diff --git a/electron-builder.json5 b/electron-builder.json5 index a2a742d..a7bf322 100644 --- a/electron-builder.json5 +++ b/electron-builder.json5 @@ -52,7 +52,7 @@ ], } ], - "artifactName": "${productName}-Mac-${arch}-${version}.${ext}", +// "artifactName": "${productName}-mac-${arch}-${version}.${ext}", category: "public.app-category.utilities" }, "win": { @@ -86,17 +86,17 @@ ] } ], - "artifactName": "${productName}-Windows-${arch}-${version}.${ext}" +// "artifactName": "${productName}-win-${arch}-${version}.${ext}" }, "nsis": { - "artifactName": "${productName}-Windows-${arch}-${version}-Setup.${ext}", +// "artifactName": "${productName}-win-${arch}-${version}-Setup.${ext}", "oneClick": false, "perMachine": false, "allowToChangeInstallationDirectory": true, "deleteAppDataOnUninstall": false }, "portable": { - "artifactName": "${productName}-Windows-${arch}-${version}.${ext}" +// "artifactName": "${productName}-win-${arch}-${version}.${ext}" }, "linux": { "target": [ @@ -131,7 +131,7 @@ ], "category": "Network", - "artifactName": "${productName}-Linux-${arch}-${version}.${ext}" +// "artifactName": "${productName}-Linux-${arch}-${version}.${ext}" }, "publish": [ { diff --git a/electron/api/update.ts b/electron/api/update.ts index 3064fcd..2526713 100644 --- a/electron/api/update.ts +++ b/electron/api/update.ts @@ -4,49 +4,78 @@ const log = require('electron-log'); export const initUpdaterApi = () => { - log.info("自动更新") - 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}`) - // - // }) - // + const server = 'https://hazel-git-master-uiluck.vercel.app' + let packageName = null + const platform = process.platform; + const arch = process.arch; + switch (platform) { + case "darwin": + if (arch == "arm64") { + packageName = "dmg_arm64"; + } else { + packageName = "dmg"; + } + break; + case "win32": + packageName = "exe"; + break; + case "linux": + packageName = "AppImage"; + if (arch == "arm64") { + packageName = "AppImage_arm64"; + } else { + packageName = "AppImage"; + } + break; + } + const url = `${server}/update/${packageName}/${app.getVersion()}` + log.info(`开启自动更新 ${url}`); + autoUpdater.setFeedURL({url}) + + 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() - // } - // }) - // }) + + 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() + } + }) + }) + + // setInterval(() => { + // log.initialize("定时检查更新") + // // autoUpdater.checkForUpdates(); + // }, 60000) + autoUpdater.checkForUpdates(); + log.info("手动检查更新一次") + } diff --git a/electron/main/index.ts b/electron/main/index.ts index e33c4ae..dba6981 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -7,6 +7,7 @@ import {initProxyApi} from "../api/proxy"; import {initFrpcApi, startFrpWorkerProcess, stopFrpcProcess} from "../api/frpc"; import {initLoggerApi} from "../api/logger"; import {initFileApi} from "../api/file"; +import {initUpdaterApi} from "../api/update"; import {getConfig} from "../storage/config"; import log from "electron-log"; // The built directory structure diff --git a/package.json b/package.json index 5b4b2c1..bc9f584 100644 --- a/package.json +++ b/package.json @@ -41,17 +41,18 @@ "@vitejs/plugin-vue": "^4.3.3", "@vue/eslint-config-prettier": "^7.1.0", "@vueuse/core": "^9.13.0", - "eslint": "^7.28.0", "autoprefixer": "^10.4.15", "cssnano": "^6.0.1", "electron": "^26.6.10", "electron-builder": "^24.13.3", "electron-builder-squirrel-windows": "^24.13.3", "element-plus": "^2.4.2", + "eslint": "^7.28.0", "eslint-plugin-prettier": "^4.2.1", "moment": "^2.29.4", "nedb": "^1.8.0", "node-cmd": "^5.0.0", + "postcss": "^8.4.31", "prettier": "^2.8.8", "sass": "^1.66.1", "tailwindcss": "^3.3.3", @@ -63,16 +64,15 @@ "vue": "^3.3.4", "vue-router": "^4.2.4", "vue-tsc": "^2.0.22", - "vue-types": "^5.1.1", - "postcss": "^8.4.31" + "vue-types": "^5.1.1" }, "dependencies": { "adm-zip": "^0.5.14", "animate.css": "^4.1.1", "electron-dl": "^3.5.1", "electron-log": "^5.1.7", + "isbinaryfile": "4.0.10", "tar": "^6.2.0", - "unused-filename": "^4.0.1", - "isbinaryfile": "4.0.10" + "unused-filename": "^4.0.1" } }