其中使用了electron-vue
github地址: https://github.com/lihaotian0...
手動更新代碼:
import {BrowserWindow, ipcMain, webContents} from 'electron'
import {autoUpdater} from "electron-updater"
const window = BrowserWindow.fromWebContents(webContents.getFocusedWebContents());
//和之前package.json配置的一樣
//處理更新操作
function handleUpdate() {
const returnData = {
error: {status: -1, msg: '檢測更新查詢異常'},
checking: {status: 0, msg: '正在檢查應用程序更新'},
updateAva: {status: 1, msg: '檢測到新版本,正在下載,請稍後'},
updateNotAva: {status: -1, msg: '您現在使用的版本爲最新版本,無需更新!'},
};
//和之前package.json配置的一樣
autoUpdater.setFeedURL('http://lee.com/app/update1');
//更新錯誤
autoUpdater.on('error', function (error) {
sendUpdateMessage(returnData.error)
});
//檢查中
autoUpdater.on('checking-for-update', function () {
sendUpdateMessage(returnData.checking)
});
//發現新版本
autoUpdater.on('update-available', function (info) {
sendUpdateMessage(returnData.updateAva)
});
//當前版本爲最新版本
autoUpdater.on('update-not-available', function (info) {
setTimeout(function () {
sendUpdateMessage(returnData.updateNotAva)
}, 1000);
});
// 更新下載進度事件
autoUpdater.on('download-progress', function (progressObj) {
window.webContents.send('downloadProgress', progressObj)
});
autoUpdater.on('update-downloaded', () => {
ipcMain.on('isUpdateNow', (e, data) => {
autoUpdater.quitAndInstall();
});
setTimeout(()=>{
autoUpdater.quitAndInstall();
},3000)
});
//執行自動更新檢查
autoUpdater.checkForUpdates();
}
// 通過main進程發送事件給renderer進程,提示更新信息
function sendUpdateMessage(text) {
window.webContents.send('message', text)
}
ipcMain.on("checkForUpdate", (event, data) => {
// event.sender.send('reply', 'hi lee my name is yuan, age is 17');
handleUpdate();
});