auto close connection

This commit is contained in:
pompurin404 2024-08-11 13:14:43 +08:00
parent 0d6a65b6d6
commit fbd52a40f6
No known key found for this signature in database
5 changed files with 30 additions and 4 deletions

View File

@ -5,6 +5,7 @@ export const defaultConfig: IAppConfig = {
proxyDisplayMode: 'simple',
proxyDisplayOrder: 'default',
autoCheckUpdate: true,
autoCloseConnection: true,
useNameserverPolicy: false,
nameserverPolicy: {},
sysProxy: { enable: false, mode: 'manual' }

View File

@ -1,15 +1,21 @@
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 { patchMihomoConfig } from '@renderer/utils/ipc'
import { mihomoCloseAllConnections, patchMihomoConfig } from '@renderer/utils/ipc'
import { Key } from 'react'
const OutboundModeSwitcher: React.FC = () => {
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig(true)
const { appConfig } = useAppConfig()
const { autoCloseConnection = true } = appConfig || {}
const { mode } = controledMihomoConfig || {}
const onChangeMode = async (mode: OutboundMode): Promise<void> => {
await patchControledMihomoConfig({ mode })
await patchMihomoConfig({ mode })
if (autoCloseConnection) {
await mihomoCloseAllConnections()
}
}
return (

View File

@ -4,6 +4,7 @@ import { useAppConfig } from '@renderer/hooks/use-app-config'
import {
getRuntimeConfig,
mihomoChangeProxy,
mihomoCloseAllConnections,
mihomoGroupDelay,
mihomoProxies,
mihomoProxyDelay
@ -24,7 +25,11 @@ const Proxies: React.FC = () => {
const { data: proxies, mutate } = useSWR('mihomoProxies', mihomoProxies)
const { data: runtime } = useSWR('getRuntimeConfig', getRuntimeConfig)
const { appConfig, patchAppConfig } = useAppConfig()
const { proxyDisplayMode = 'simple', proxyDisplayOrder = 'default' } = appConfig || {}
const {
proxyDisplayMode = 'simple',
proxyDisplayOrder = 'default',
autoCloseConnection = true
} = appConfig || {}
const groups = useMemo(() => {
const groups: IMihomoGroup[] = []
@ -80,6 +85,9 @@ const Proxies: React.FC = () => {
const onChangeProxy = (group: string, proxy: string): void => {
mihomoChangeProxy(group, proxy).then(() => {
if (autoCloseConnection) {
mihomoCloseAllConnections()
}
mutate()
})
}

View File

@ -30,6 +30,7 @@ const Settings: React.FC = () => {
delayTestTimeout,
autoCheckUpdate,
userAgent,
autoCloseConnection = true,
appTheme = 'system'
} = appConfig || {}
const [url, setUrl] = useState(delayTestUrl)
@ -169,7 +170,7 @@ const Settings: React.FC = () => {
}}
></Input>
</SettingItem>
<SettingItem title="延迟测试超时时间">
<SettingItem title="延迟测试超时时间" divider>
<Input
type="number"
size="sm"
@ -179,7 +180,16 @@ const Settings: React.FC = () => {
onValueChange={(v) => {
patchAppConfig({ delayTestTimeout: parseInt(v) })
}}
></Input>
/>
</SettingItem>
<SettingItem title="自动断开连接">
<Switch
size="sm"
isSelected={autoCloseConnection}
onValueChange={(v) => {
patchAppConfig({ autoCloseConnection: v })
}}
/>
</SettingItem>
</SettingCard>
<SettingCard>

View File

@ -197,6 +197,7 @@ interface IAppConfig {
appTheme: AppTheme
autoCheckUpdate: boolean
silentStart: boolean
autoCloseConnection: boolean
sysProxy: ISysProxyConfig
userAgent?: string
delayTestUrl?: string