mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 11:42:19 +08:00
check update
This commit is contained in:
parent
40f6c478b5
commit
6ffe0e86f4
|
@ -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
|
||||
|
|
29
src/main/resolve/autoUpdater.ts
Normal file
29
src/main/resolve/autoUpdater.ts
Normal file
|
@ -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<string | undefined> {
|
||||
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
|
||||
}
|
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ export const defaultConfig: IAppConfig = {
|
|||
silentStart: false,
|
||||
proxyDisplayMode: 'simple',
|
||||
proxyDisplayOrder: 'default',
|
||||
autoCheckUpdate: true,
|
||||
sysProxy: { enable: false, mode: 'manual' }
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = () => {
|
|||
<div className="sticky top-0 z-40 backdrop-blur bg-background/40 h-[48px]">
|
||||
<div className="flex justify-between p-2">
|
||||
<h3 className="select-none text-lg font-bold leading-[32px]">Mihomo Party</h3>
|
||||
<UpdaterButton />
|
||||
<Button
|
||||
size="sm"
|
||||
isIconOnly
|
||||
|
|
33
src/renderer/src/components/updater/updater-button.tsx
Normal file
33
src/renderer/src/components/updater/updater-button.tsx
Normal file
|
@ -0,0 +1,33 @@
|
|||
import { Button } from '@nextui-org/react'
|
||||
import { useAppConfig } from '@renderer/hooks/use-app-config'
|
||||
import { checkUpdate } from '@renderer/utils/ipc'
|
||||
import React from 'react'
|
||||
import useSWR from 'swr'
|
||||
|
||||
const UpdaterButton: React.FC = () => {
|
||||
const { appConfig } = useAppConfig()
|
||||
const { autoCheckUpdate } = appConfig || {}
|
||||
|
||||
const { data: version } = useSWR(
|
||||
autoCheckUpdate ? 'checkUpdate' : undefined,
|
||||
autoCheckUpdate ? checkUpdate : (): void => {},
|
||||
{
|
||||
refreshInterval: 1000 * 60 * 10
|
||||
}
|
||||
)
|
||||
if (!version) return null
|
||||
|
||||
return (
|
||||
<Button
|
||||
color="danger"
|
||||
size="sm"
|
||||
onPress={() => {
|
||||
open(`https://github.com/pompurin404/mihomo-party/releases/tag/v${version}`)
|
||||
}}
|
||||
>
|
||||
v{version}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
export default UpdaterButton
|
|
@ -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 (
|
||||
<BasePage
|
||||
|
@ -47,6 +53,15 @@ const Settings: React.FC = () => {
|
|||
}}
|
||||
/>
|
||||
</SettingItem>
|
||||
<SettingItem title="自动检查更新" divider>
|
||||
<Switch
|
||||
size="sm"
|
||||
isSelected={autoCheckUpdate}
|
||||
onValueChange={(v) => {
|
||||
patchAppConfig({ autoCheckUpdate: v })
|
||||
}}
|
||||
/>
|
||||
</SettingItem>
|
||||
<SettingItem title="静默启动">
|
||||
<Switch
|
||||
size="sm"
|
||||
|
@ -83,6 +98,20 @@ const Settings: React.FC = () => {
|
|||
</SettingItem>
|
||||
</SettingCard>
|
||||
<SettingCard>
|
||||
<SettingItem
|
||||
title="检查更新"
|
||||
divider
|
||||
onPress={() => {
|
||||
checkUpdate().then((v) => {
|
||||
if (v) {
|
||||
new window.Notification(`v${v}版本已发布`, { body: '点击前往下载' }).onclick =
|
||||
(): void => {
|
||||
open(`https://github.com/pompurin404/mihomo-party/releases/tag/v${v}`)
|
||||
}
|
||||
}
|
||||
})
|
||||
}}
|
||||
/>
|
||||
<SettingItem title="退出应用" onPress={quitApp} />
|
||||
</SettingCard>
|
||||
</BasePage>
|
||||
|
|
|
@ -127,6 +127,10 @@ export async function encryptString(str: string): Promise<Buffer> {
|
|||
return await window.electron.ipcRenderer.invoke('encryptString', str)
|
||||
}
|
||||
|
||||
export async function checkUpdate(): Promise<string | undefined> {
|
||||
return await window.electron.ipcRenderer.invoke('checkUpdate')
|
||||
}
|
||||
|
||||
export async function getPlatform(): Promise<NodeJS.Platform> {
|
||||
return await window.electron.ipcRenderer.invoke('platform')
|
||||
}
|
||||
|
|
1
src/shared/types.d.ts
vendored
1
src/shared/types.d.ts
vendored
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user