mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-11 04:00:32 +08:00
change mihomo core
This commit is contained in:
parent
f583bef224
commit
12504704a3
@ -7,7 +7,7 @@ import { useLocation, useNavigate } from 'react-router-dom'
|
|||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
|
|
||||||
const MihomoCoreCard: React.FC = () => {
|
const MihomoCoreCard: React.FC = () => {
|
||||||
const { data: version } = useSWR('mihomoVersion', mihomoVersion)
|
const { data: version, mutate } = useSWR('mihomoVersion', mihomoVersion)
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const match = location.pathname.includes('/mihomo')
|
const match = location.pathname.includes('/mihomo')
|
||||||
@ -15,10 +15,17 @@ const MihomoCoreCard: React.FC = () => {
|
|||||||
const [mem, setMem] = useState(0)
|
const [mem, setMem] = useState(0)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const token = PubSub.subscribe('mihomo-core-changed', () => {
|
||||||
|
mutate()
|
||||||
|
setTimeout(() => {
|
||||||
|
mutate()
|
||||||
|
}, 1000)
|
||||||
|
})
|
||||||
window.electron.ipcRenderer.on('mihomoMemory', (_e, info: IMihomoMemoryInfo) => {
|
window.electron.ipcRenderer.on('mihomoMemory', (_e, info: IMihomoMemoryInfo) => {
|
||||||
setMem(info.inuse)
|
setMem(info.inuse)
|
||||||
})
|
})
|
||||||
return (): void => {
|
return (): void => {
|
||||||
|
PubSub.unsubscribe(token)
|
||||||
window.electron.ipcRenderer.removeAllListeners('mihomoMemory')
|
window.electron.ipcRenderer.removeAllListeners('mihomoMemory')
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|||||||
@ -8,7 +8,7 @@ const RuleCard: React.FC = () => {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const match = location.pathname.includes('/rules')
|
const match = location.pathname.includes('/rules')
|
||||||
const { data: rules } = useSWR<IMihomoRulesInfo>('/rules', mihomoRules, {
|
const { data: rules } = useSWR<IMihomoRulesInfo>('mihomoRules', mihomoRules, {
|
||||||
refreshInterval: 5000
|
refreshInterval: 5000
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -2,11 +2,19 @@ import { Button, Input, Select, SelectItem, Switch } from '@nextui-org/react'
|
|||||||
import BasePage from '@renderer/components/base/base-page'
|
import BasePage from '@renderer/components/base/base-page'
|
||||||
import SettingCard from '@renderer/components/base/base-setting-card'
|
import SettingCard from '@renderer/components/base/base-setting-card'
|
||||||
import SettingItem from '@renderer/components/base/base-setting-item'
|
import SettingItem from '@renderer/components/base/base-setting-item'
|
||||||
|
import { useAppConfig } from '@renderer/hooks/use-app-config'
|
||||||
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
|
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
|
||||||
import { patchMihomoConfig, restartCore } from '@renderer/utils/ipc'
|
import { patchMihomoConfig, restartCore } from '@renderer/utils/ipc'
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
|
|
||||||
|
const CoreMap = {
|
||||||
|
mihomo: '稳定版',
|
||||||
|
'mihomo-alpha': '预览版'
|
||||||
|
}
|
||||||
|
|
||||||
const Mihomo: React.FC = () => {
|
const Mihomo: React.FC = () => {
|
||||||
|
const { appConfig, patchAppConfig } = useAppConfig()
|
||||||
|
const { core = 'mihomo' } = appConfig || {}
|
||||||
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
|
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
|
||||||
const {
|
const {
|
||||||
ipv6,
|
ipv6,
|
||||||
@ -34,6 +42,20 @@ const Mihomo: React.FC = () => {
|
|||||||
return (
|
return (
|
||||||
<BasePage title="内核设置">
|
<BasePage title="内核设置">
|
||||||
<SettingCard>
|
<SettingCard>
|
||||||
|
<SettingItem title="内核版本" divider>
|
||||||
|
<Select
|
||||||
|
className="w-[100px]"
|
||||||
|
size="sm"
|
||||||
|
selectedKeys={new Set([core])}
|
||||||
|
onSelectionChange={async (v) => {
|
||||||
|
await patchAppConfig({ core: v.currentKey as 'mihomo' | 'mihomo-alpha' })
|
||||||
|
restartCore().then(() => PubSub.publish('mihomo-core-changed'))
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectItem key="mihomo">{CoreMap['mihomo']}</SelectItem>
|
||||||
|
<SelectItem key="mihomo-alpha">{CoreMap['mihomo-alpha']}</SelectItem>
|
||||||
|
</Select>
|
||||||
|
</SettingItem>
|
||||||
<SettingItem title="混合端口" divider>
|
<SettingItem title="混合端口" divider>
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
{mixedPortInput !== mixedPort && (
|
{mixedPortInput !== mixedPort && (
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import useSWR from 'swr'
|
|||||||
import { mihomoRules } from '@renderer/utils/ipc'
|
import { mihomoRules } from '@renderer/utils/ipc'
|
||||||
|
|
||||||
const Rules: React.FC = () => {
|
const Rules: React.FC = () => {
|
||||||
const { data: rules = { rules: [] } } = useSWR<IMihomoRulesInfo>('/rules', mihomoRules, {
|
const { data: rules = { rules: [] } } = useSWR<IMihomoRulesInfo>('mihomoRules', mihomoRules, {
|
||||||
refreshInterval: 5000
|
refreshInterval: 5000
|
||||||
})
|
})
|
||||||
const [filter, setFilter] = useState('')
|
const [filter, setFilter] = useState('')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user