From a98c8d343acae0315f859276537a8bca3b5b01e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=98=89=E4=BC=9F?= <8473136@qq.com> Date: Wed, 7 Aug 2024 23:12:47 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=9B=B4=E6=96=B0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/api/update.ts | 51 ++++++++++++++++++++++++++++++++++++++++++ electron/main/index.ts | 26 ++++++++++++++------- 2 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 electron/api/update.ts diff --git a/electron/api/update.ts b/electron/api/update.ts new file mode 100644 index 0000000..c2231ca --- /dev/null +++ b/electron/api/update.ts @@ -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() + // } + // }) + // }) + +} diff --git a/electron/main/index.ts b/electron/main/index.ts index 8a196a0..a71df8f 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -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();