electron updater 4.2.0 包不下载新版本但可以检测到
这是github上的一个私有仓库
新版本成功发送到 github
在package.json中:
"build": {
"appId": "com.myApp.ID",
"npmRebuild": false,
"win": {
"icon": "./resources/electron/icons/256x256.png",
"publish": [
{
"provider": "github",
"owner": "me",
"repo": "POS",
"private": true,
"releaseType": "release",
"token": "<private token>"
}
],
"target": [
{
"target": "nsis",
"arch": [
"x64"
]
}
]
}
},
我的 electron.js 文件或 main.js 我有:
win.webContents.on('did-finish-load', () => {
if(!serve) {
appUpdater(win);
}
});
appUpdater函数是:
function appUpdater(win) {
autoUpdater.autoInstallOnAppQuit = true;
autoUpdater.autoDownload = true;
autoUpdater.logger = logger;
/* Log whats happening
TODO send autoUpdater events to renderer so that we could console log it in developer tools
You could alsoe use nslog or other logging to see what's happening */
let foundUpdate = false;
autoUpdater.on('checking-for-update', () => {
dialog.showMessageBox(win, {
message: 'CHECKING FOR UPDATES !!'
});
});
autoUpdater.on('update-available', () => {
foundUpdate = true;
dialog.showMessageBox(win, {
message: ' update-available !!'
});
});
autoUpdater.on('error', error => {
autoUpdater.logger.debug(error);
});
// Ask the user if update is available
autoUpdater.on('update-downloaded', (_event, releaseNotes, _releaseName) => {
let message = 'A new version is now available. It will be installed the next time you restart the application.';
dialog.showMessageBox(win, {
type: 'question',
buttons: ['Install', 'Later'],
defaultId: 0,
message: 'A new version has been downloaded',
detail: message
}, response => {
if(response === 0) {
setTimeout(() => autoUpdater.quitAndInstall(), 1);
}
});
});
// init for updates
setInterval(() => {
if(!foundUpdate) {
autoUpdater.checkForUpdates();
}
}, 60000);
}
exports.appUpdater = appUpdater;
可自动更新的目标是windows nsis
检查更新和更新可用事件正确触发,但更新下载或错误根本不会触发
如果您已经有这方面的经验,请告诉我
注意:我也在用户机器中设置了环境变量 GH_TOKEN