eletron 'download-progress' 什么都不做

eletron 'download-progress' does not anything

我的构建配置

"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('checking-for-update'
  4. autoUpdater.on('update-available',
  5. !!跳过 autoUpdater.on('download-progress'!!
  6. autoUpdater.on('update-downloaded'

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

只有'download-progress'不行

缓存问题 删除文件夹正常