更新代码

This commit is contained in:
刘嘉伟 2024-08-07 23:12:47 +08:00
parent 62e67f97bd
commit a98c8d343a
2 changed files with 69 additions and 8 deletions

51
electron/api/update.ts Normal file
View File

@ -0,0 +1,51 @@
import {app, dialog, autoUpdater } from "electron";
const log = require('electron-log');
export const initUpdaterApi = () => {
const server = 'https://hazel-jplav4y84-uiluck.vercel.app'
const url = `${server}/update/${process.platform}/${app.getVersion()}`
autoUpdater.setFeedURL({ url })
setInterval(() => {
}, 60000)
autoUpdater.checkForUpdates()
// autoUpdater.on('checking-for-update', () => {
// log.info("正在检查更新")
// })
//
// autoUpdater.on('update-available', () => {
// log.info("有可用更新")
// })
//
// autoUpdater.on('update-not-available', () => {
// log.info('没有可用的更新')
// })
//
// autoUpdater.on('error', (err) => {
// log.error(`更新错误:${err.message}`)
//
// })
//
// autoUpdater.on('download-progress', (progressObj) => {
// log.debug(`下载进度 ${progressObj.percent}%`)
// })
//
// autoUpdater.on('update-downloaded', () => {
// console.log('update-downloaded')
//
// dialog.showMessageBox({
// type: 'info',
// title: '应用更新',
// message: '发现新版本,是否更新?',
// buttons: ['是', '否']
// }).then((buttonIndex) => {
// if (buttonIndex.response == 0) { //选择是,则退出程序,安装新版本
// autoUpdater.quitAndInstall()
// app.quit()
// }
// })
// })
}

View File

@ -9,6 +9,7 @@ import {initLoggerApi} from "../api/logger";
import {initFileApi} from "../api/file";
import {getConfig} from "../storage/config";
import log from "electron-log";
import {initUpdaterApi} from "../api/update";
// The built directory structure
//
// ├─┬ dist-electron
@ -160,6 +161,23 @@ export const createTray = () => {
}
app.whenReady().then(() => {
initGitHubApi();
initConfigApi();
initProxyApi();
initFrpcApi();
initLoggerApi();
initFileApi();
// initUpdaterApi();
//更新测试打开
Object.defineProperty(app, 'isPackaged', {
get() {
return true;
}
});
createWindow().then(r => {
createTray()
})
@ -212,11 +230,3 @@ ipcMain.handle("open-win", (_, arg) => {
childWindow.loadFile(indexHtml, {hash: arg});
}
});
initGitHubApi();
initConfigApi();
initProxyApi();
initFrpcApi();
initLoggerApi();
initFileApi();