【发布时间】:2019-09-04 01:58:10
【问题描述】:
我想在下载更新时在我的 Electron 应用程序中显示一个进度条。因此,我根据需要调整了电子生成器更新程序文档中的示例代码。
以下是我的 main.ts 的节选:
function sendStatusToWindow(updateState: UpdateState) {
log.info(updateState);
win.webContents.send('message', updateState);
}
autoUpdater.on('checking-for-update', () => {
sendStatusToWindow({ status: 'checking' });
});
autoUpdater.on('update-available', (info) => {
sendStatusToWindow({ status: 'update-available' });
});
autoUpdater.on('update-not-available', (info) => {
sendStatusToWindow({ status: 'current' });
});
autoUpdater.on('error', (err) => {
sendStatusToWindow({ status: 'error', error: err });
});
autoUpdater.on('download-progress', (progressObj) => {
log.info(progressObj);
sendStatusToWindow({
status: 'downloading',
download: {
bytesPerSecond: progressObj.bytesPerSecond,
percent: progressObj.percent,
transferred: progressObj.transferred,
total: progressObj.total
}
});
});
autoUpdater.on('update-downloaded', (info) => {
sendStatusToWindow({ status: 'completed' });
});
还有我的 electron-builder.json:
"win": {
"icon": "dist",
"target": ["NSIS"],
"publish": ["github"]
}
除了download-progress 之外的所有事件都被调用
是不是我做错了什么?
【问题讨论】: