From 6ffe0e86f448450104121bf91c7183813f2a7984 Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Mon, 5 Aug 2024 22:36:52 +0800 Subject: [PATCH] check update --- pnpm-lock.yaml | 45 ------------------- src/main/resolve/autoUpdater.ts | 29 ++++++++++++ src/main/utils/ipc.ts | 2 + src/main/utils/template.ts | 1 + src/renderer/src/App.tsx | 2 + .../src/components/updater/updater-button.tsx | 33 ++++++++++++++ src/renderer/src/pages/settings.tsx | 33 +++++++++++++- src/renderer/src/utils/ipc.ts | 4 ++ src/shared/types.d.ts | 1 + 9 files changed, 103 insertions(+), 47 deletions(-) create mode 100644 src/main/resolve/autoUpdater.ts create mode 100644 src/renderer/src/components/updater/updater-button.tsx diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 63e6215..67f09ce 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,9 +26,6 @@ importers: dayjs: specifier: ^1.11.12 version: 1.11.12 - electron-updater: - specifier: ^6.2.1 - version: 6.2.1 framer-motion: specifier: ^11.3.19 version: 11.3.19(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -2110,10 +2107,6 @@ packages: buffer@5.7.1: resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==} - builder-util-runtime@9.2.4: - resolution: {integrity: sha512-upp+biKpN/XZMLim7aguUyW8s0FUpDvOtK6sbanMFDAMBzpHDqdhgVYm6zc9HJ6nWo7u2Lxk60i2M6Jd3aiNrA==} - engines: {node: '>=12.0.0'} - builder-util-runtime@9.2.5: resolution: {integrity: sha512-HjIDfhvqx/8B3TDN4GbABQcgpewTU4LMRTQPkVpKYV3lsuxEJoIfvg09GyWTNmfVNSUAYf+fbTN//JX4TH20pg==} engines: {node: '>=12.0.0'} @@ -2436,9 +2429,6 @@ packages: electron-to-chromium@1.5.3: resolution: {integrity: sha512-QNdYSS5i8D9axWp/6XIezRObRHqaav/ur9z1VzCDUCH1XIFOr9WQk5xmgunhsTpjjgDy3oLxO/WMOVZlpUQrlA==} - electron-updater@6.2.1: - resolution: {integrity: sha512-83eKIPW14qwZqUUM6wdsIRwVKZyjmHxQ4/8G+1C6iS5PdDt7b1umYQyj1/qPpH510GmHEQe4q0kCPe3qmb3a0Q==} - electron-vite@2.3.0: resolution: {integrity: sha512-lsN2FymgJlp4k6MrcsphGqZQ9fKRdJKasoaiwIrAewN1tapYI/KINLdfEL7n10LuF0pPSNf/IqjzZbB5VINctg==} engines: {node: ^18.0.0 || >=20.0.0} @@ -3154,9 +3144,6 @@ packages: lodash.difference@4.5.0: resolution: {integrity: sha512-dS2j+W26TQ7taQBGN8Lbbq04ssV3emRw4NY58WErlTO29pIqS0HmoT5aJ9+TUQ1N3G+JOZSji4eugsWwGp9yPA==} - lodash.escaperegexp@4.1.2: - resolution: {integrity: sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw==} - lodash.flatten@4.4.0: resolution: {integrity: sha512-C5N2Z3DgnnKr0LOpv/hKCgKdb7ZZwafIrsesve6lmzvZIRZRGaZ/l6Q8+2W7NaT+ZwO3fFlSCzCzrDCFdJfZ4g==} @@ -3166,9 +3153,6 @@ packages: lodash.get@4.4.2: resolution: {integrity: sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==} - lodash.isequal@4.5.0: - resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==} - lodash.isplainobject@4.0.6: resolution: {integrity: sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==} @@ -4037,9 +4021,6 @@ packages: thenify@3.3.1: resolution: {integrity: sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==} - tiny-typed-emitter@2.1.0: - resolution: {integrity: sha512-qVtvMxeXbVej0cQWKqVSSAHmKZEHAvxdF8HEUBFWts8h+xEo5m/lEiPakuyZ3BnCBjOD8i24kzNOiOLLgsSxhA==} - tmp-promise@3.0.3: resolution: {integrity: sha512-RwM7MoPojPxsOBYnyd2hy0bxtIlVrihNs9pj5SUvY8Zz1sQcQG2tG1hSr8PDxfgEB8RNKDhqbIlroIarSNDNsQ==} @@ -7276,13 +7257,6 @@ snapshots: base64-js: 1.5.1 ieee754: 1.2.1 - builder-util-runtime@9.2.4: - dependencies: - debug: 4.3.6 - sax: 1.4.1 - transitivePeerDependencies: - - supports-color - builder-util-runtime@9.2.5: dependencies: debug: 4.3.6 @@ -7672,19 +7646,6 @@ snapshots: electron-to-chromium@1.5.3: {} - electron-updater@6.2.1: - dependencies: - builder-util-runtime: 9.2.4 - fs-extra: 10.1.0 - js-yaml: 4.1.0 - lazy-val: 1.0.5 - lodash.escaperegexp: 4.1.2 - lodash.isequal: 4.5.0 - semver: 7.6.3 - tiny-typed-emitter: 2.1.0 - transitivePeerDependencies: - - supports-color - electron-vite@2.3.0(vite@5.3.5(@types/node@22.0.0)): dependencies: '@babel/core': 7.25.2 @@ -8536,16 +8497,12 @@ snapshots: lodash.difference@4.5.0: {} - lodash.escaperegexp@4.1.2: {} - lodash.flatten@4.4.0: {} lodash.foreach@4.5.0: {} lodash.get@4.4.2: {} - lodash.isequal@4.5.0: {} - lodash.isplainobject@4.0.6: {} lodash.kebabcase@4.1.1: {} @@ -9496,8 +9453,6 @@ snapshots: dependencies: any-promise: 1.3.0 - tiny-typed-emitter@2.1.0: {} - tmp-promise@3.0.3: dependencies: tmp: 0.2.3 diff --git a/src/main/resolve/autoUpdater.ts b/src/main/resolve/autoUpdater.ts new file mode 100644 index 0000000..8c8225b --- /dev/null +++ b/src/main/resolve/autoUpdater.ts @@ -0,0 +1,29 @@ +import axios from 'axios' +import yaml from 'yaml' +import { app } from 'electron' +import { getControledMihomoConfig } from '../config' + +export async function checkUpdate(): Promise { + try { + const res = await axios.get( + 'https://github.com/pompurin404/mihomo-party/releases/latest/download/latest.yml', + { + headers: { 'Content-Type': 'application/octet-stream' }, + proxy: { + protocol: 'http', + host: '127.0.0.1', + port: getControledMihomoConfig()['mixed-port'] || 7890 + } + } + ) + const latest = yaml.parse(res.data) + const remoteVersion = latest.version + const currentVersion = app.getVersion() + if (remoteVersion !== currentVersion) { + return remoteVersion + } + } catch (e) { + console.error(e) + } + return undefined +} diff --git a/src/main/utils/ipc.ts b/src/main/utils/ipc.ts index 6311823..7c7f88d 100644 --- a/src/main/utils/ipc.ts +++ b/src/main/utils/ipc.ts @@ -31,6 +31,7 @@ import { } from '../config' import { isEncryptionAvailable, restartCore } from '../core/manager' import { triggerSysProxy } from '../resolve/sysproxy' +import { checkUpdate } from '../resolve/autoUpdater' export function registerIpcMainHandlers(): void { ipcMain.handle('mihomoVersion', mihomoVersion) @@ -65,6 +66,7 @@ export function registerIpcMainHandlers(): void { ipcMain.handle('triggerSysProxy', (_e, enable) => triggerSysProxy(enable)) ipcMain.handle('isEncryptionAvailable', isEncryptionAvailable) ipcMain.handle('encryptString', (_e, str) => safeStorage.encryptString(str)) + ipcMain.handle('checkUpdate', () => checkUpdate()) ipcMain.handle('platform', () => process.platform) ipcMain.handle('quitApp', () => app.quit()) } diff --git a/src/main/utils/template.ts b/src/main/utils/template.ts index 3ff283a..600bd99 100644 --- a/src/main/utils/template.ts +++ b/src/main/utils/template.ts @@ -3,6 +3,7 @@ export const defaultConfig: IAppConfig = { silentStart: false, proxyDisplayMode: 'simple', proxyDisplayOrder: 'default', + autoCheckUpdate: true, sysProxy: { enable: false, mode: 'manual' } } diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 126fa2d..cf3c54c 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -15,6 +15,7 @@ import ConnCard from '@renderer/components/sider/conn-card' import LogCard from '@renderer/components/sider/log-card' import MihomoCoreCard from './components/sider/mihomo-core-card.tsx' import TestCard from './components/sider/test-card.js' +import UpdaterButton from './components/updater/updater-button.js' const App: React.FC = () => { const { setTheme } = useTheme() @@ -47,6 +48,7 @@ const App: React.FC = () => {

Mihomo Party

+ + ) +} + +export default UpdaterButton diff --git a/src/renderer/src/pages/settings.tsx b/src/renderer/src/pages/settings.tsx index 33cc10c..201c20b 100644 --- a/src/renderer/src/pages/settings.tsx +++ b/src/renderer/src/pages/settings.tsx @@ -3,7 +3,13 @@ import BasePage from '@renderer/components/base/base-page' import SettingCard from '@renderer/components/base/base-setting-card' import SettingItem from '@renderer/components/base/base-setting-item' import { useAppConfig } from '@renderer/hooks/use-app-config' -import { checkAutoRun, enableAutoRun, disableAutoRun, quitApp } from '@renderer/utils/ipc' +import { + checkAutoRun, + enableAutoRun, + disableAutoRun, + quitApp, + checkUpdate +} from '@renderer/utils/ipc' import { IoLogoGithub } from 'react-icons/io5' import useSWR from 'swr' @@ -15,7 +21,7 @@ const Settings: React.FC = () => { }) const { appConfig, patchAppConfig } = useAppConfig() - const { silentStart = false, delayTestUrl, delayTestTimeout } = appConfig || {} + const { silentStart = false, delayTestUrl, delayTestTimeout, autoCheckUpdate } = appConfig || {} return ( { }} /> + + { + patchAppConfig({ autoCheckUpdate: v }) + }} + /> + { + { + checkUpdate().then((v) => { + if (v) { + new window.Notification(`v${v}版本已发布`, { body: '点击前往下载' }).onclick = + (): void => { + open(`https://github.com/pompurin404/mihomo-party/releases/tag/v${v}`) + } + } + }) + }} + /> diff --git a/src/renderer/src/utils/ipc.ts b/src/renderer/src/utils/ipc.ts index d4a065c..f0c67de 100644 --- a/src/renderer/src/utils/ipc.ts +++ b/src/renderer/src/utils/ipc.ts @@ -127,6 +127,10 @@ export async function encryptString(str: string): Promise { return await window.electron.ipcRenderer.invoke('encryptString', str) } +export async function checkUpdate(): Promise { + return await window.electron.ipcRenderer.invoke('checkUpdate') +} + export async function getPlatform(): Promise { return await window.electron.ipcRenderer.invoke('platform') } diff --git a/src/shared/types.d.ts b/src/shared/types.d.ts index ae92804..97ad049 100644 --- a/src/shared/types.d.ts +++ b/src/shared/types.d.ts @@ -133,6 +133,7 @@ interface IAppConfig { core: 'mihomo' | 'mihomo-alpha' proxyDisplayMode: 'simple' | 'full' proxyDisplayOrder: 'default' | 'delay' | 'name' + autoCheckUpdate: boolean silentStart: boolean sysProxy: ISysProxyConfig userAgent?: string