【问题标题】:eletron 'download-progress' does not anything电子“下载进度”没有任何作用
【发布时间】:2020-06-21 06:25:31
【问题描述】:

我的构建配置

"build": {
    "mac": {
        "target": [
            "dmg",
            "zip"
        ],
        "publish": {
            "provider": "generic",
            "url": "http://ip/update/darwin/0.0.1",
            "channel": "stable"
        }
    },
    "win": {
        "target": [
            "squirrel",
            "nsis"
        ]
    },
    "nsis": {
        "oneClick": false,
        "allowToChangeInstallationDirectory": false
    }
},

命令

"build_mac": "electron-builder --mac"

和 main.js

const { app, BrowserWindow, dialog } = require('electron');
const { autoUpdater } = require('electron-updater');
const log = require('electron-log');

autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'info';
log.info('App starting...');

app.whenReady().then(function() {
let win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
        nodeIntegration: true,
    },
});

win.loadFile('buildprodp/index.html');
win.webContents.openDevTools();

setInterval(() => {
    win.webContents.send('submitted-form', `currentVersion - ${app.getVersion()}`);
}, 5000);

init(win);
});

app.on('ready', function() {
setTimeout(() => {
    autoUpdater.checkForUpdates();
}, 6000);
});

// autoUpdate codes
const init = win => {

autoUpdater.on('checking-for-update', (ev, err) => {
    win.webContents.send('submitted-form', '???? Checking for updates');
    win.webContents.send('submitted-form', ev);
    win.webContents.send('submitted-form', err);
});

autoUpdater.on('update-available', (ev, err) => {
    win.webContents.send('submitted-form', '???? Update available. Downloading ⌛️');
});

autoUpdater.on('update-not-available', (ev, err) => {
    win.webContents.send('submitted-form', '???? Update not available');
});

autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
    const dialogOpts = {
        type: 'info',
        buttons: ['Restart', 'Later'],
        title: 'Application Update',
        message: process.platform === 'win32' ? releaseNotes : releaseName,
        detail: 'plz restart',
    };

    dialog.showMessageBox(dialogOpts).then(returnValue => {
        if (returnValue.response === 0) autoUpdater.quitAndInstall();
    });
});

autoUpdater.on('error', message => {
    win.webContents.send('submitted-form', message);
});

autoUpdater.on('download-progress', progressObj => {
    win.webContents.send('submitted-form', 'down start');
});
};

确实有效 6秒后

  1. autoUpdater.checkForUpdates();
  2. 列表项
  3. autoUpdater.on('检查更新'
  4. autoUpdater.on('update-available',
  5. !!跳过 autoUpdater.on('download-progress'!!
  6. autoUpdater.on('更新下载'

https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/AppUpdater.ts#L555

只有“下载进度”不起作用

【问题讨论】:

    标签: electron electron-builder


    【解决方案1】:

    这是一个缓存问题 删除文件夹效果很好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-10
      相关资源
      最近更新 更多