electronnsiselectron-builderelectron-updater

Electron auto update fails silently when installing update on Windows


I have an electron app which uses electron-builder for building, packing & publishing the app.

I have the following auto-update code:

autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
autoUpdater.autoDownload = true;

const updateCheck = () => {
  autoUpdater.checkForUpdates().then(resp => {
    log.info("autoUpdate response:");
    log.info(resp);
  });
};

app.on("ready", async () => {
  log.info(`Version: ${app.getVersion()}`);

  autoUpdater.on("update-downloaded", () => {
    log.info("update downloaded");
    setImmediate(() => {
      try {
        log.info("installing update");
        // app.relaunch();
        autoUpdater.quitAndInstall();
      } catch (err) {
        log.error("Error installing update");
        log.error(err);
      }
    });
  });

  autoUpdater.on("error", err => {
    log.error("AutoUpdater error");
    log.error(err);
  });

  updateCheck();

  schedule.scheduleJob("*/10 * * * *", updateCheck);
});

When I publish a new version, the auto-updater detects it, downloads it successfully, and then tries to install it.

During installation of the update, the progress bar fills up halfway, then disappears.

The app remains closed and does not automatically relaunch after the progress bar disappears.

When I re-launch it manually, it is still the old version. It detects that there is an update which has already downloaded, and tries to install it, with the same result (progress bar fills halfway then disappears, app remains closed after).

My log file shows no errors, either from the catch block or the autoUpdater.on("error") callback.

The location C:\Users\<User>\AppData\Local\<app-name>-updater has an installer.exe file which installs the previous version, and a pending folder which contains an installer for the new version. Manually executing this installer causes the app to be updated with no errors.

I tried testing using checkForUpdatesAndNotify instead of checkForUpdates (and commenting out the call to quitAndInstall), and it worked as advertised, however I would like to ensure the update is installed immediately rather than wait for the user to quit on their own.

How can I debug this further? Why am I not seeing any errors? Where should I be looking for them? What am I doing wrong?


Solution

  • The problem turned out to be the fact that I created the window with the option closable: false, preventing the auto updater from closing it. The auto updater works perfectly after removing this setting