Skip to content

Commit

Permalink
change mihomo core
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Aug 3, 2024
1 parent b65e678 commit b3dacd2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/renderer/src/components/sider/mihomo-core-card.tsx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ import { useLocation, useNavigate } from 'react-router-dom'
import useSWR from 'swr'

const MihomoCoreCard: React.FC = () => {
const { data: version } = useSWR('mihomoVersion', mihomoVersion)
const { data: version, mutate } = useSWR('mihomoVersion', mihomoVersion)
const navigate = useNavigate()
const location = useLocation()
const match = location.pathname.includes('/mihomo')

const [mem, setMem] = useState(0)

useEffect(() => {
const token = PubSub.subscribe('mihomo-core-changed', () => {
mutate()
setTimeout(() => {
mutate()
}, 1000)
})
window.electron.ipcRenderer.on('mihomoMemory', (_e, info: IMihomoMemoryInfo) => {
setMem(info.inuse)
})
return (): void => {
PubSub.unsubscribe(token)
window.electron.ipcRenderer.removeAllListeners('mihomoMemory')
}
}, [])
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/sider/rule-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const RuleCard: React.FC = () => {
const navigate = useNavigate()
const location = useLocation()
const match = location.pathname.includes('/rules')
const { data: rules } = useSWR<IMihomoRulesInfo>('/rules', mihomoRules, {
const { data: rules } = useSWR<IMihomoRulesInfo>('mihomoRules', mihomoRules, {
refreshInterval: 5000
})

Expand Down
22 changes: 22 additions & 0 deletions src/renderer/src/pages/mihomo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ import { Button, Input, Select, SelectItem, Switch } from '@nextui-org/react'
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 { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
import { patchMihomoConfig, restartCore } from '@renderer/utils/ipc'
import React, { useState } from 'react'

const CoreMap = {
mihomo: '稳定版',
'mihomo-alpha': '预览版'
}

const Mihomo: React.FC = () => {
const { appConfig, patchAppConfig } = useAppConfig()
const { core = 'mihomo' } = appConfig || {}
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
const {
ipv6,
Expand Down Expand Up @@ -34,6 +42,20 @@ const Mihomo: React.FC = () => {
return (
<BasePage title="内核设置">
<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>
<div className="flex">
{mixedPortInput !== mixedPort && (
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/pages/rules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useSWR from 'swr'
import { mihomoRules } from '@renderer/utils/ipc'

const Rules: React.FC = () => {
const { data: rules = { rules: [] } } = useSWR<IMihomoRulesInfo>('/rules', mihomoRules, {
const { data: rules = { rules: [] } } = useSWR<IMihomoRulesInfo>('mihomoRules', mihomoRules, {
refreshInterval: 5000
})
const [filter, setFilter] = useState('')
Expand Down

0 comments on commit b3dacd2

Please sign in to comment.