electron-builder.yml配置更新地址
# 配置自動更新的信息
publish:provider: generic # 更新服務提供者url: http://xxx.xxxx.com/pc/xxx-xx# 更新的地址
服務器地址
?會自動讀取latest.yml 下的版本號比較
檢測更新方法autoUpdater.js
// src/main/autoUpdater.jsimport { 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);