我正在尝试使用电子制作工具的自动更新功能,我添加了update-not-available
和update-available
的听众。如果没有新的更新,update-not-available
事件会成功触发,但出于某种原因,当我的应用程序的新版本可用时,update-available
事件未被触发,有没有办法检查事件的原因没有被触发或添加日志以查看是否发生任何错误?
下面是我的main.js代码
const { autoUpdater } = require("electron-updater");
...other imports
app.on('ready', () => {
//do this
//Check for updates.
autoUpdater.checkForUpdates();
}
autoUpdater.on("update-not-available", (info) => {
const dialogOpts = {
type: 'info',
buttons: ['Ok'],
title: 'Application Update',
message: "Yay",
detail: 'No new updates.'
}
dialog.showMessageBox(dialogOpts, (response) => {
});
});
autoUpdater.on("update-available", (info) => {
const dialogOpts = {
type: 'info',
buttons: ['Ok'],
title: 'Application Update',
message: process.platform === 'win32' ? releaseNotes : releaseName,
detail: 'A new version is being downloaded.'
}
dialog.showMessageBox(dialogOpts, (response) => {
});
})
autoUpdater.on("update-downloaded", (info) => {
const dialogOpts = {
type: 'info',
buttons: ['Restart', 'Later'],
title: 'Application Update',
message: process.platform === 'win32' ? releaseNotes : releaseName,
detail: 'A new version has been downloaded. Restart the application to apply the updates.'
}
dialog.showMessageBox(dialogOpts, (response) => {
if (response === 0) autoUpdater.quitAndInstall()
});
});
答案 0 :(得分:0)
通过从命令行运行可执行文件,我能够找到失败的原因。由于下面的行
,它失败了message: process.platform === 'win32' ? releaseNotes : releaseName,
因为变量未定义。通过更改回调函数参数来修复它以包含releaseName
和releaseNotes
,如此
autoUpdater.on("update-available", (event, releaseNotes, releaseName) => {
正如文档here中所提供的那样。