【问题标题】:How to fix "Skip checkForUpdatesAndNotify because application is not packed" in electron.js如何在 electron.js 中修复“跳过 checkForUpdatesAndNotify,因为应用程序未打包”
【发布时间】:2019-06-06 09:52:20
【问题描述】:

我正在使用“electron-updater”来检查自动更新 Electron 应用程序。

调用“checkForUpdatesAndNotify()”函数。

在控制台中,我收到“跳过 checkForUpdatesAndNotify,因为应用程序未打包”。

  • mac0S 莫哈韦,
  • “电子更新器”:“^4.0.6”,
  • “电子”:“^3.0.13”,
  • “电子制造商”:“20.28.1”

        const {autoUpdater} = require("electron-updater");
        autoUpdater.checkForUpdatesAndNotify();
    
        autoUpdater.on('checking-for-update', () => {
          console.log('Checking for update...');
        });
    
        autoUpdater.on('update-available', (info) => {
          console.log('Update available.');
        });
    
        autoUpdater.on('update-not-available', (info) => {
          console.log('Update not available.');
        });
    
        autoUpdater.on('error', (err) => {
          console.log('Error in auto-updater. ' + err);
        });
    
        autoUpdater.on('download-progress', (progressObj) => {
          let log_message = "Download speed: " + progressObj.bytesPerSecond;
          log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
          log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
          console.log(log_message);
        });
    
        autoUpdater.on('update-downloaded', (info) => {
          console.log('Update downloaded');
        });
    

【问题讨论】:

  • 您在哪个环境中面临这个问题,开发还是生产?

标签: electron auto-update electron-builder


【解决方案1】:

checkForUpdatesAndNotify() 无法在开发模式下工作。

如果你坚持在开发模式下测试它,你可以用isPackaged做一些hack:

const app = require('electron').app;

Object.defineProperty(app, 'isPackaged', {
  get() {
    return true;
  }
});

小心,不要将这个hack用于生产,它可能

【讨论】:

  • 好招!非常感谢,它完美地完成了这项工作!
【解决方案2】:

改用autoUpdater.checkForUpdates

【讨论】:

    猜你喜欢
    • 2021-01-31
    • 2018-02-20
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    • 2016-01-02
    • 1970-01-01
    相关资源
    最近更新 更多