diff --git a/changelog.md b/changelog.md index a316455..e0caf6e 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ ### Features - 支持托盘菜单切换订阅 +- Windows 支持一键更新 ### Bug Fixes diff --git a/electron-builder.yml b/electron-builder.yml index 47b5d97..d8a83fb 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -33,7 +33,6 @@ nsis: artifactName: ${name}-windows-${version}-${arch}-setup.${ext} shortcutName: Mihomo Party uninstallDisplayName: ${productName} - deleteAppDataOnUninstall: true allowToChangeInstallationDirectory: true oneClick: false perMachine: true diff --git a/scripts/prepare.mjs b/scripts/prepare.mjs index 6f30cc9..f778a8e 100644 --- a/scripts/prepare.mjs +++ b/scripts/prepare.mjs @@ -271,6 +271,11 @@ const resolveRunner = () => file: 'mihomo-party-run.exe', downloadURL: `https://github.com/mihomo-party-org/mihomo-party-run/releases/download/${arch}/mihomo-party-run.exe` }) +const resolve7zip = () => + resolveResource({ + file: '7za.exe', + downloadURL: `https://github.com/develar/7zip-bin/raw/master/win/${arch}/7za.exe` + }) const resolveSubstore = () => resolveResource({ file: 'sub-store.bundle.js', @@ -359,6 +364,12 @@ const tasks = [ name: 'substorefrontend', func: resolveSubstoreFrontend, retry: 5 + }, + { + name: '7zip', + func: resolve7zip, + retry: 5, + winOnly: true } ] diff --git a/src/main/resolve/autoUpdater.ts b/src/main/resolve/autoUpdater.ts index dfcbb14..f904329 100644 --- a/src/main/resolve/autoUpdater.ts +++ b/src/main/resolve/autoUpdater.ts @@ -2,11 +2,12 @@ import axios from 'axios' import yaml from 'yaml' import { app, shell } from 'electron' import { getControledMihomoConfig } from '../config' -import { dataDir, isPortable } from '../utils/dirs' +import { dataDir, exeDir, isPortable, resourcesFilesDir } from '../utils/dirs' import { rm, writeFile } from 'fs/promises' import path from 'path' import { existsSync } from 'fs' import os from 'os' +import { spawn } from 'child_process' export async function checkUpdate(): Promise { const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig() @@ -65,8 +66,25 @@ export async function downloadAndInstallUpdate(version: string): Promise { }) await writeFile(path.join(dataDir(), file), res.data) } - await shell.openPath(path.join(dataDir(), file)) - app.quit() + if (file.endsWith('.exe')) { + spawn(path.join(dataDir(), file), ['/S', '--force-run'], { + detached: true, + stdio: 'ignore' + }).unref() + } else if (file.endsWith('.7z')) { + spawn( + path.join(resourcesFilesDir(), '7za.exe'), + ['x', `-o"${exeDir()}"`, '-y', path.join(dataDir(), file)], + { + shell: true, + detached: true + } + ).unref() + app.quit() + } else { + await shell.openPath(path.join(dataDir(), file)) + app.quit() + } } catch (e) { rm(path.join(dataDir(), file)) throw e