mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 11:42:19 +08:00
auto close connection
This commit is contained in:
parent
0d6a65b6d6
commit
fbd52a40f6
|
@ -5,6 +5,7 @@ export const defaultConfig: IAppConfig = {
|
|||
proxyDisplayMode: 'simple',
|
||||
proxyDisplayOrder: 'default',
|
||||
autoCheckUpdate: true,
|
||||
autoCloseConnection: true,
|
||||
useNameserverPolicy: false,
|
||||
nameserverPolicy: {},
|
||||
sysProxy: { enable: false, mode: 'manual' }
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
1
src/shared/types.d.ts
vendored
1
src/shared/types.d.ts
vendored
|
@ -197,6 +197,7 @@ interface IAppConfig {
|
|||
appTheme: AppTheme
|
||||
autoCheckUpdate: boolean
|
||||
silentStart: boolean
|
||||
autoCloseConnection: boolean
|
||||
sysProxy: ISysProxyConfig
|
||||
userAgent?: string
|
||||
delayTestUrl?: string
|
||||
|
|
Loading…
Reference in New Issue
Block a user