1
1
import { ignoredError , APP_TITLE } from '@/utils'
2
2
import { deleteConnection , getConnections , useProxy } from '@/api/kernel'
3
- import { useAppSettingsStore , useEnvStore , useKernelApiStore , usePluginsStore } from '@/stores'
3
+ import {
4
+ type ProxyType ,
5
+ useAppSettingsStore ,
6
+ useEnvStore ,
7
+ useKernelApiStore ,
8
+ usePluginsStore
9
+ } from '@/stores'
4
10
import { AbsolutePath , Exec , ExitApp , Readfile , Writefile } from '@/bridge'
5
11
import { useConfirm , useMessage } from '@/hooks'
6
12
@@ -67,7 +73,11 @@ export const GrantTUNPermission = async (path: string) => {
67
73
}
68
74
69
75
// SystemProxy Helper
70
- export const SetSystemProxy = async ( enable : boolean , server : string , proxyType = 0 ) => {
76
+ export const SetSystemProxy = async (
77
+ enable : boolean ,
78
+ server : string ,
79
+ proxyType : ProxyType = 'mixed'
80
+ ) => {
71
81
const { os } = useEnvStore ( ) . env
72
82
73
83
if ( os === 'windows' ) {
@@ -85,8 +95,8 @@ export const SetSystemProxy = async (enable: boolean, server: string, proxyType
85
95
}
86
96
}
87
97
88
- function setWindowsSystemProxy ( server : string , enabled : boolean , proxyType : number ) {
89
- if ( proxyType === 2 ) throw 'home.overview.notSupportSocks'
98
+ function setWindowsSystemProxy ( server : string , enabled : boolean , proxyType : ProxyType ) {
99
+ if ( proxyType === 'socks' ) throw 'home.overview.notSupportSocks'
90
100
91
101
ignoredError (
92
102
Exec ,
@@ -121,12 +131,12 @@ function setWindowsSystemProxy(server: string, enabled: boolean, proxyType: numb
121
131
)
122
132
}
123
133
124
- function setDarwinSystemProxy ( server : string , enabled : boolean , proxyType : number ) {
134
+ function setDarwinSystemProxy ( server : string , enabled : boolean , proxyType : ProxyType ) {
125
135
function _set ( device : string ) {
126
136
const state = enabled ? 'on' : 'off'
127
137
128
- const httpState = [ 0 , 1 ] . includes ( proxyType ) ? state : 'off'
129
- const socksState = [ 0 , 2 ] . includes ( proxyType ) ? state : 'off'
138
+ const httpState = [ 'mixed' , 'http' ] . includes ( proxyType ) ? state : 'off'
139
+ const socksState = [ 'mixed' , 'socks' ] . includes ( proxyType ) ? state : 'off'
130
140
131
141
ignoredError ( Exec , 'networksetup' , [ '-setwebproxystate' , device , httpState ] )
132
142
ignoredError ( Exec , 'networksetup' , [ '-setsecurewebproxystate' , device , httpState ] )
@@ -146,10 +156,10 @@ function setDarwinSystemProxy(server: string, enabled: boolean, proxyType: numbe
146
156
_set ( 'Wi-Fi' )
147
157
}
148
158
149
- function setLinuxSystemProxy ( server : string , enabled : boolean , proxyType : number ) {
159
+ function setLinuxSystemProxy ( server : string , enabled : boolean , proxyType : ProxyType ) {
150
160
const [ serverName , serverPort ] = server . split ( ':' )
151
- const httpEnabled = enabled && [ 0 , 1 ] . includes ( proxyType )
152
- const socksEnabled = enabled && [ 0 , 2 ] . includes ( proxyType )
161
+ const httpEnabled = enabled && [ 'mixed' , 'http' ] . includes ( proxyType )
162
+ const socksEnabled = enabled && [ 'mixed' , 'socks' ] . includes ( proxyType )
153
163
154
164
ignoredError ( Exec , 'gsettings' , [
155
165
'set' ,
0 commit comments