Commit fbd52a4 pompurin404
committed
1 parent 0d6a65b commit fbd52a4 Copy full SHA for fbd52a4
File tree 5 files changed +30
-4
lines changed
5 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ export const defaultConfig: IAppConfig = {
5
5
proxyDisplayMode : 'simple' ,
6
6
proxyDisplayOrder : 'default' ,
7
7
autoCheckUpdate : true ,
8
+ autoCloseConnection : true ,
8
9
useNameserverPolicy : false ,
9
10
nameserverPolicy : { } ,
10
11
sysProxy : { enable : false , mode : 'manual' }
Original file line number Diff line number Diff line change 1
1
import { Tabs , Tab } from '@nextui-org/react'
2
+ import { useAppConfig } from '@renderer/hooks/use-app-config'
2
3
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
3
- import { patchMihomoConfig } from '@renderer/utils/ipc'
4
+ import { mihomoCloseAllConnections , patchMihomoConfig } from '@renderer/utils/ipc'
4
5
import { Key } from 'react'
5
6
6
7
const OutboundModeSwitcher : React . FC = ( ) => {
7
8
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig ( true )
9
+ const { appConfig } = useAppConfig ( )
10
+ const { autoCloseConnection = true } = appConfig || { }
8
11
const { mode } = controledMihomoConfig || { }
9
12
10
13
const onChangeMode = async ( mode : OutboundMode ) : Promise < void > => {
11
14
await patchControledMihomoConfig ( { mode } )
12
15
await patchMihomoConfig ( { mode } )
16
+ if ( autoCloseConnection ) {
17
+ await mihomoCloseAllConnections ( )
18
+ }
13
19
}
14
20
15
21
return (
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { useAppConfig } from '@renderer/hooks/use-app-config'
4
4
import {
5
5
getRuntimeConfig ,
6
6
mihomoChangeProxy ,
7
+ mihomoCloseAllConnections ,
7
8
mihomoGroupDelay ,
8
9
mihomoProxies ,
9
10
mihomoProxyDelay
@@ -24,7 +25,11 @@ const Proxies: React.FC = () => {
24
25
const { data : proxies , mutate } = useSWR ( 'mihomoProxies' , mihomoProxies )
25
26
const { data : runtime } = useSWR ( 'getRuntimeConfig' , getRuntimeConfig )
26
27
const { appConfig, patchAppConfig } = useAppConfig ( )
27
- const { proxyDisplayMode = 'simple' , proxyDisplayOrder = 'default' } = appConfig || { }
28
+ const {
29
+ proxyDisplayMode = 'simple' ,
30
+ proxyDisplayOrder = 'default' ,
31
+ autoCloseConnection = true
32
+ } = appConfig || { }
28
33
29
34
const groups = useMemo ( ( ) => {
30
35
const groups : IMihomoGroup [ ] = [ ]
@@ -80,6 +85,9 @@ const Proxies: React.FC = () => {
80
85
81
86
const onChangeProxy = ( group : string , proxy : string ) : void => {
82
87
mihomoChangeProxy ( group , proxy ) . then ( ( ) => {
88
+ if ( autoCloseConnection ) {
89
+ mihomoCloseAllConnections ( )
90
+ }
83
91
mutate ( )
84
92
} )
85
93
}
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ const Settings: React.FC = () => {
30
30
delayTestTimeout,
31
31
autoCheckUpdate,
32
32
userAgent,
33
+ autoCloseConnection = true ,
33
34
appTheme = 'system'
34
35
} = appConfig || { }
35
36
const [ url , setUrl ] = useState ( delayTestUrl )
@@ -169,7 +170,7 @@ const Settings: React.FC = () => {
169
170
} }
170
171
> </ Input >
171
172
</ SettingItem >
172
- < SettingItem title = "延迟测试超时时间" >
173
+ < SettingItem title = "延迟测试超时时间" divider >
173
174
< Input
174
175
type = "number"
175
176
size = "sm"
@@ -179,7 +180,16 @@ const Settings: React.FC = () => {
179
180
onValueChange = { ( v ) => {
180
181
patchAppConfig ( { delayTestTimeout : parseInt ( v ) } )
181
182
} }
182
- > </ Input >
183
+ />
184
+ </ SettingItem >
185
+ < SettingItem title = "自动断开连接" >
186
+ < Switch
187
+ size = "sm"
188
+ isSelected = { autoCloseConnection }
189
+ onValueChange = { ( v ) => {
190
+ patchAppConfig ( { autoCloseConnection : v } )
191
+ } }
192
+ />
183
193
</ SettingItem >
184
194
</ SettingCard >
185
195
< SettingCard >
Original file line number Diff line number Diff line change @@ -197,6 +197,7 @@ interface IAppConfig {
197
197
appTheme : AppTheme
198
198
autoCheckUpdate : boolean
199
199
silentStart : boolean
200
+ autoCloseConnection : boolean
200
201
sysProxy : ISysProxyConfig
201
202
userAgent ?: string
202
203
delayTestUrl ?: string
You can’t perform that action at this time.
0 commit comments