mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
auto close connection
This commit is contained in:
parent
0d6a65b6d6
commit
fbd52a40f6
@ -5,6 +5,7 @@ export const defaultConfig: IAppConfig = {
|
|||||||
proxyDisplayMode: 'simple',
|
proxyDisplayMode: 'simple',
|
||||||
proxyDisplayOrder: 'default',
|
proxyDisplayOrder: 'default',
|
||||||
autoCheckUpdate: true,
|
autoCheckUpdate: true,
|
||||||
|
autoCloseConnection: true,
|
||||||
useNameserverPolicy: false,
|
useNameserverPolicy: false,
|
||||||
nameserverPolicy: {},
|
nameserverPolicy: {},
|
||||||
sysProxy: { enable: false, mode: 'manual' }
|
sysProxy: { enable: false, mode: 'manual' }
|
||||||
|
|||||||
@ -1,15 +1,21 @@
|
|||||||
import { Tabs, Tab } from '@nextui-org/react'
|
import { Tabs, Tab } from '@nextui-org/react'
|
||||||
|
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 } from '@renderer/utils/ipc'
|
import { mihomoCloseAllConnections, patchMihomoConfig } from '@renderer/utils/ipc'
|
||||||
import { Key } from 'react'
|
import { Key } from 'react'
|
||||||
|
|
||||||
const OutboundModeSwitcher: React.FC = () => {
|
const OutboundModeSwitcher: React.FC = () => {
|
||||||
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig(true)
|
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig(true)
|
||||||
|
const { appConfig } = useAppConfig()
|
||||||
|
const { autoCloseConnection = true } = appConfig || {}
|
||||||
const { mode } = controledMihomoConfig || {}
|
const { mode } = controledMihomoConfig || {}
|
||||||
|
|
||||||
const onChangeMode = async (mode: OutboundMode): Promise<void> => {
|
const onChangeMode = async (mode: OutboundMode): Promise<void> => {
|
||||||
await patchControledMihomoConfig({ mode })
|
await patchControledMihomoConfig({ mode })
|
||||||
await patchMihomoConfig({ mode })
|
await patchMihomoConfig({ mode })
|
||||||
|
if (autoCloseConnection) {
|
||||||
|
await mihomoCloseAllConnections()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { useAppConfig } from '@renderer/hooks/use-app-config'
|
|||||||
import {
|
import {
|
||||||
getRuntimeConfig,
|
getRuntimeConfig,
|
||||||
mihomoChangeProxy,
|
mihomoChangeProxy,
|
||||||
|
mihomoCloseAllConnections,
|
||||||
mihomoGroupDelay,
|
mihomoGroupDelay,
|
||||||
mihomoProxies,
|
mihomoProxies,
|
||||||
mihomoProxyDelay
|
mihomoProxyDelay
|
||||||
@ -24,7 +25,11 @@ const Proxies: React.FC = () => {
|
|||||||
const { data: proxies, mutate } = useSWR('mihomoProxies', mihomoProxies)
|
const { data: proxies, mutate } = useSWR('mihomoProxies', mihomoProxies)
|
||||||
const { data: runtime } = useSWR('getRuntimeConfig', getRuntimeConfig)
|
const { data: runtime } = useSWR('getRuntimeConfig', getRuntimeConfig)
|
||||||
const { appConfig, patchAppConfig } = useAppConfig()
|
const { appConfig, patchAppConfig } = useAppConfig()
|
||||||
const { proxyDisplayMode = 'simple', proxyDisplayOrder = 'default' } = appConfig || {}
|
const {
|
||||||
|
proxyDisplayMode = 'simple',
|
||||||
|
proxyDisplayOrder = 'default',
|
||||||
|
autoCloseConnection = true
|
||||||
|
} = appConfig || {}
|
||||||
|
|
||||||
const groups = useMemo(() => {
|
const groups = useMemo(() => {
|
||||||
const groups: IMihomoGroup[] = []
|
const groups: IMihomoGroup[] = []
|
||||||
@ -80,6 +85,9 @@ const Proxies: React.FC = () => {
|
|||||||
|
|
||||||
const onChangeProxy = (group: string, proxy: string): void => {
|
const onChangeProxy = (group: string, proxy: string): void => {
|
||||||
mihomoChangeProxy(group, proxy).then(() => {
|
mihomoChangeProxy(group, proxy).then(() => {
|
||||||
|
if (autoCloseConnection) {
|
||||||
|
mihomoCloseAllConnections()
|
||||||
|
}
|
||||||
mutate()
|
mutate()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@ const Settings: React.FC = () => {
|
|||||||
delayTestTimeout,
|
delayTestTimeout,
|
||||||
autoCheckUpdate,
|
autoCheckUpdate,
|
||||||
userAgent,
|
userAgent,
|
||||||
|
autoCloseConnection = true,
|
||||||
appTheme = 'system'
|
appTheme = 'system'
|
||||||
} = appConfig || {}
|
} = appConfig || {}
|
||||||
const [url, setUrl] = useState(delayTestUrl)
|
const [url, setUrl] = useState(delayTestUrl)
|
||||||
@ -169,7 +170,7 @@ const Settings: React.FC = () => {
|
|||||||
}}
|
}}
|
||||||
></Input>
|
></Input>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
<SettingItem title="延迟测试超时时间">
|
<SettingItem title="延迟测试超时时间" divider>
|
||||||
<Input
|
<Input
|
||||||
type="number"
|
type="number"
|
||||||
size="sm"
|
size="sm"
|
||||||
@ -179,7 +180,16 @@ const Settings: React.FC = () => {
|
|||||||
onValueChange={(v) => {
|
onValueChange={(v) => {
|
||||||
patchAppConfig({ delayTestTimeout: parseInt(v) })
|
patchAppConfig({ delayTestTimeout: parseInt(v) })
|
||||||
}}
|
}}
|
||||||
></Input>
|
/>
|
||||||
|
</SettingItem>
|
||||||
|
<SettingItem title="自动断开连接">
|
||||||
|
<Switch
|
||||||
|
size="sm"
|
||||||
|
isSelected={autoCloseConnection}
|
||||||
|
onValueChange={(v) => {
|
||||||
|
patchAppConfig({ autoCloseConnection: v })
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
</SettingCard>
|
</SettingCard>
|
||||||
<SettingCard>
|
<SettingCard>
|
||||||
|
|||||||
1
src/shared/types.d.ts
vendored
1
src/shared/types.d.ts
vendored
@ -197,6 +197,7 @@ interface IAppConfig {
|
|||||||
appTheme: AppTheme
|
appTheme: AppTheme
|
||||||
autoCheckUpdate: boolean
|
autoCheckUpdate: boolean
|
||||||
silentStart: boolean
|
silentStart: boolean
|
||||||
|
autoCloseConnection: boolean
|
||||||
sysProxy: ISysProxyConfig
|
sysProxy: ISysProxyConfig
|
||||||
userAgent?: string
|
userAgent?: string
|
||||||
delayTestUrl?: string
|
delayTestUrl?: string
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user