自动更新
应用客户端自动更新
# 自动更新
// frontend/src/views/framework/updater/Index.vue
<script>
checkForUpdater () {
this.$ipc.invoke(ipcApiRoute.checkForUpdater).then(r => {
console.log(r);
})
},
</script>
// electron/controller/framework.js
/**
* 检查是否有新版本
*/
checkForUpdater() {
const autoUpdaterAddon = this.app.addon.autoUpdater;
autoUpdaterAddon.checkUpdate();
return;
}
// Make sure to add code blocks to your code group
# 下载 & 进度
// frontend/src/views/framework/updater/Index.vue
<script>
init () {
this.$ipc.removeAllListeners(specialIpcRoute.appUpdater);
this.$ipc.on(specialIpcRoute.appUpdater, (event, result) => {
result = JSON.parse(result);
this.status = result.status;
if (result.status == 3) {
this.progress = result.desc;
this.percentNumber = result.percentNumber;
} else {
this.$message.info(result.desc);
}
})
},
download () {
if (this.status !== 1) {
this.$message.info('没有可用版本');
return
}
this.$ipc.invoke(ipcApiRoute.downloadApp).then(r => {
console.log(r);
})
},
</script>
// electron/controller/framework.js
/**
* 下载新版本
*/
downloadApp() {
const autoUpdaterAddon = this.app.addon.autoUpdater;
autoUpdaterAddon.download();
return;
}
// Make sure to add code blocks to your code group
# 完整代码
上次更新: 2025/04/10, 03:07:49