support oneclick update for windows

This commit is contained in:
pompurin404 2024-09-18 22:35:16 +08:00
parent 76bc24a6cd
commit e79e3dcd1b
No known key found for this signature in database
4 changed files with 33 additions and 4 deletions

View File

@ -5,6 +5,7 @@
### Features ### Features
- 支持托盘菜单切换订阅 - 支持托盘菜单切换订阅
- Windows 支持一键更新
### Bug Fixes ### Bug Fixes

View File

@ -33,7 +33,6 @@ nsis:
artifactName: ${name}-windows-${version}-${arch}-setup.${ext} artifactName: ${name}-windows-${version}-${arch}-setup.${ext}
shortcutName: Mihomo Party shortcutName: Mihomo Party
uninstallDisplayName: ${productName} uninstallDisplayName: ${productName}
deleteAppDataOnUninstall: true
allowToChangeInstallationDirectory: true allowToChangeInstallationDirectory: true
oneClick: false oneClick: false
perMachine: true perMachine: true

View File

@ -271,6 +271,11 @@ const resolveRunner = () =>
file: 'mihomo-party-run.exe', file: 'mihomo-party-run.exe',
downloadURL: `https://github.com/mihomo-party-org/mihomo-party-run/releases/download/${arch}/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 = () => const resolveSubstore = () =>
resolveResource({ resolveResource({
file: 'sub-store.bundle.js', file: 'sub-store.bundle.js',
@ -359,6 +364,12 @@ const tasks = [
name: 'substorefrontend', name: 'substorefrontend',
func: resolveSubstoreFrontend, func: resolveSubstoreFrontend,
retry: 5 retry: 5
},
{
name: '7zip',
func: resolve7zip,
retry: 5,
winOnly: true
} }
] ]

View File

@ -2,11 +2,12 @@ import axios from 'axios'
import yaml from 'yaml' import yaml from 'yaml'
import { app, shell } from 'electron' import { app, shell } from 'electron'
import { getControledMihomoConfig } from '../config' 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 { rm, writeFile } from 'fs/promises'
import path from 'path' import path from 'path'
import { existsSync } from 'fs' import { existsSync } from 'fs'
import os from 'os' import os from 'os'
import { spawn } from 'child_process'
export async function checkUpdate(): Promise<IAppVersion | undefined> { export async function checkUpdate(): Promise<IAppVersion | undefined> {
const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig() const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig()
@ -65,8 +66,25 @@ export async function downloadAndInstallUpdate(version: string): Promise<void> {
}) })
await writeFile(path.join(dataDir(), file), res.data) await writeFile(path.join(dataDir(), file), res.data)
} }
await shell.openPath(path.join(dataDir(), file)) if (file.endsWith('.exe')) {
app.quit() 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) { } catch (e) {
rm(path.join(dataDir(), file)) rm(path.join(dataDir(), file))
throw e throw e