本文介绍了在Windows上安装更新时,电子自动更新会以静默方式失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个电子应用程序,该应用程序使用 electron-builder 进行建筑,包装和安装。

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).

我的日志文件没有显示任何错误,无论是catch块还是 autoUpdater.on( error)回调。

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

位置 C:\Users\< User> \AppData\Local\< app-name> -updater 具有 installer.exe 文件,用于安装先前版本,以及 pending 文件夹,其中包含新版本的安装程序。

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.

我尝试使用 checkForUpdatesAndNotify 而不是 checkForUpdates (并注释掉对 quitAndInstall 的调用),它的工作与广告一样,但是我想确保更新立即安装,而不是等待用户自己退出。

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?

推荐答案

事实证明,问题出在我用选项<$ c创建的窗口中$ c> closesable:false ,阻止自动更新程序关闭它。删除此设置后,自动更新程序可以完美运行

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

这篇关于在Windows上安装更新时,电子自动更新会以静默方式失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 07:06