Electron auto update fails silently when installing update on Windows

故事扮演 提交于 2020-01-15 09:52:12

问题


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?


回答1:


Quick question: have you used this answer to make your App closed and minimizable to tray?

if you did you should application.isQuiting = true before calling autoUpdater.quitAndInstall(); otherwise the application.close() function is pretty much blocked form anywhere other then the contextMenu.



来源:https://stackoverflow.com/questions/58126745/electron-auto-update-fails-silently-when-installing-update-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!