mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
support upgrade core
This commit is contained in:
parent
48028a43c1
commit
93155cedfb
@ -1,6 +1,7 @@
|
||||
### New Features
|
||||
|
||||
- 自动删除过期日志与更新缓存
|
||||
- 添加更新内核功能
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
|
||||
@ -38,6 +38,10 @@ export async function startCore(): Promise<void> {
|
||||
})
|
||||
return new Promise((resolve, reject) => {
|
||||
child.stdout?.on('data', async (data) => {
|
||||
if (data.toString().includes('updater: finished')) {
|
||||
stopCore()
|
||||
await startCore()
|
||||
}
|
||||
if (data.toString().includes('External controller listen error')) {
|
||||
if (retry) {
|
||||
retry--
|
||||
|
||||
@ -152,6 +152,11 @@ export const mihomoGroupDelay = async (group: string, url?: string): Promise<IMi
|
||||
})
|
||||
}
|
||||
|
||||
export const mihomoUpgrade = async (): Promise<void> => {
|
||||
const instance = await getAxios()
|
||||
return await instance.post('/upgrade')
|
||||
}
|
||||
|
||||
export const startMihomoTraffic = async (): Promise<void> => {
|
||||
await mihomoTraffic()
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import {
|
||||
mihomoRules,
|
||||
mihomoUpdateProxyProviders,
|
||||
mihomoUpdateRuleProviders,
|
||||
mihomoUpgrade,
|
||||
mihomoUpgradeGeo,
|
||||
mihomoVersion,
|
||||
patchMihomoConfig,
|
||||
@ -64,7 +65,17 @@ function ipcErrorWrapper<T>( // eslint-disable-next-line @typescript-eslint/no-e
|
||||
try {
|
||||
return await fn(...args)
|
||||
} catch (e) {
|
||||
return { invokeError: `${e}` }
|
||||
if (e && typeof e === 'object') {
|
||||
if ('message' in e) {
|
||||
return { invokeError: e.message }
|
||||
} else {
|
||||
return { invokeError: JSON.stringify(e) }
|
||||
}
|
||||
}
|
||||
if (e instanceof Error || typeof e === 'string') {
|
||||
return { invokeError: e }
|
||||
}
|
||||
return { invokeError: 'Unknown Error' }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -87,6 +98,7 @@ export function registerIpcMainHandlers(): void {
|
||||
ipcErrorWrapper(mihomoChangeProxy)(group, proxy)
|
||||
)
|
||||
ipcMain.handle('mihomoUpgradeGeo', ipcErrorWrapper(mihomoUpgradeGeo))
|
||||
ipcMain.handle('mihomoUpgrade', ipcErrorWrapper(mihomoUpgrade))
|
||||
ipcMain.handle('mihomoProxyDelay', (_e, proxy, url) =>
|
||||
ipcErrorWrapper(mihomoProxyDelay)(proxy, url)
|
||||
)
|
||||
|
||||
@ -6,7 +6,8 @@ import { useAppConfig } from '@renderer/hooks/use-app-config'
|
||||
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
|
||||
import { platform } from '@renderer/utils/init'
|
||||
import { FaNetworkWired } from 'react-icons/fa'
|
||||
import { restartCore } from '@renderer/utils/ipc'
|
||||
import { IoMdCloudDownload } from 'react-icons/io'
|
||||
import { mihomoUpgrade, restartCore } from '@renderer/utils/ipc'
|
||||
import React, { useState } from 'react'
|
||||
import InterfaceModal from '@renderer/components/mihomo/interface-modal'
|
||||
|
||||
@ -45,6 +46,7 @@ const Mihomo: React.FC = () => {
|
||||
const [externalControllerInput, setExternalControllerInput] = useState(externalController)
|
||||
const [secretInput, setSecretInput] = useState(secret)
|
||||
|
||||
const [upgrading, setUpgrading] = useState(false)
|
||||
const [lanOpen, setLanOpen] = useState(false)
|
||||
|
||||
const onChangeNeedRestart = async (patch: Partial<IMihomoConfig>): Promise<void> => {
|
||||
@ -57,7 +59,33 @@ const Mihomo: React.FC = () => {
|
||||
{lanOpen && <InterfaceModal onClose={() => setLanOpen(false)} />}
|
||||
<BasePage title="内核设置">
|
||||
<SettingCard>
|
||||
<SettingItem title="内核版本" divider>
|
||||
<SettingItem
|
||||
title="内核版本"
|
||||
actions={
|
||||
<Button
|
||||
size="sm"
|
||||
isIconOnly
|
||||
title="升级内核"
|
||||
variant="light"
|
||||
className="ml-2"
|
||||
isLoading={upgrading}
|
||||
onPress={async () => {
|
||||
try {
|
||||
setUpgrading(true)
|
||||
await mihomoUpgrade()
|
||||
PubSub.publish('mihomo-core-changed')
|
||||
} catch (e) {
|
||||
alert(e)
|
||||
} finally {
|
||||
setUpgrading(false)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<IoMdCloudDownload className="text-lg" />
|
||||
</Button>
|
||||
}
|
||||
divider
|
||||
>
|
||||
<Select
|
||||
className="w-[100px]"
|
||||
size="sm"
|
||||
|
||||
@ -61,6 +61,10 @@ export async function mihomoUpgradeGeo(): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoUpgradeGeo'))
|
||||
}
|
||||
|
||||
export async function mihomoUpgrade(): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoUpgrade'))
|
||||
}
|
||||
|
||||
export async function mihomoProxyDelay(proxy: string, url?: string): Promise<IMihomoDelay> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoProxyDelay', proxy, url))
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user