【问题标题】:Electron Updater download-progress Event no getting called电子更新程序下载进度事件没有被调用
【发布时间】:2019-09-04 01:58:10
【问题描述】:

我想在下载更新时在我的 Electron 应用程序中显示一个进度条。因此,我根据需要调整了电子生成器更新程序文档中的示例代码。

以下是我的 main.ts 的节选:

function sendStatusToWindow(updateState: UpdateState) {
  log.info(updateState);
  win.webContents.send('message', updateState);
}

autoUpdater.on('checking-for-update', () => {
  sendStatusToWindow({ status: 'checking' });
});

autoUpdater.on('update-available', (info) => {
  sendStatusToWindow({ status: 'update-available' });
});

autoUpdater.on('update-not-available', (info) => {
  sendStatusToWindow({ status: 'current' });
});

autoUpdater.on('error', (err) => {
  sendStatusToWindow({ status: 'error', error: err });
});

autoUpdater.on('download-progress', (progressObj) => {
  log.info(progressObj);
  sendStatusToWindow({
    status: 'downloading',
    download: {
      bytesPerSecond: progressObj.bytesPerSecond,
      percent: progressObj.percent,
      transferred: progressObj.transferred,
      total: progressObj.total
    }
  });
});

autoUpdater.on('update-downloaded', (info) => {
  sendStatusToWindow({ status: 'completed' });
});

还有我的 electron-builder.json:

  "win": {
    "icon": "dist",
    "target": ["NSIS"],
    "publish": ["github"]
  }

除了download-progress 之外的所有事件都被调用 是不是我做错了什么?

【问题讨论】:

    标签: electron electron-builder


    【解决方案1】:

    你在打电话吗?

        if (this.isDev) {
             this._autoUpdater.checkForUpdates();
         } else {
            this._autoUpdater.checkForUpdatesAndNotify();
         }
    

    在开发模式下,checkForUpdatesAndNotify 不会触发任何事情。这仅在打包时有效。如果您在开发模式 (electron-is-dev) 下调用 checkForUpdates,那么您应该会收到下载事件。

    【讨论】:

    • 打包应用程序后也会出现此问题(通过电子生成器)。在这种情况下,开发标志应该是 0。
    猜你喜欢
    • 2023-01-20
    • 2020-06-21
    • 1970-01-01
    • 2013-09-10
    • 2023-01-05
    • 2011-01-31
    • 1970-01-01
    • 1970-01-01
    • 2013-09-21
    相关资源
    最近更新 更多