electron 全量更新
需要安装第三方库 electron-builder,electron-updater
electron-builder.yml配置更新地址
# 配置自动更新的信息 publish: provider: generic # 更新服务提供者 url: http://xxx.xxxx.com/pc/xxx-xx# 更新的地址
服务器地址

会自动读取latest.yml 下的版本号比较
检测更新方法autoUpdater.js
// src/main/autoUpdater.js import { app, dialog } from 'electron'; import { autoUpdater } from 'electron-updater'; export const checkUpdate = () => { autoUpdater.autoDownload = false; // 手动触发下载 autoUpdater.on('update-available', () => { dialog .showMessageBox({ type: 'info', title: '更新提示', message: `有最新版本,您现在的版本是 ${app.getVersion()},现在要下载更新吗?`, buttons: ['下载', '取消'] }) .then(({ response }) => { if (response === 0) autoUpdater.downloadUpdate(); }); }); autoUpdater.on('update-downloaded', () => { dialog .showMessageBox({ message: '更新已下载,退出应用后安装', buttons: ['立即重启', '稍后'] }) .then(({ response }) => { if (response === 0) autoUpdater.quitAndInstall(); }); }); autoUpdater.checkForUpdates(); // 触发检查 };
main.js添加检测
import {checkUpdate} from "./autoUpdater"
checkUpdate(mainWindow);

浙公网安备 33010602011771号