@@ -4,9 +4,49 @@ import SettingCard from '@renderer/components/base/base-setting-card'
4
4
import SettingItem from '@renderer/components/base/base-setting-item'
5
5
import PacEditorViewer from '@renderer/components/sysproxy/pac-editor-modal'
6
6
import { useAppConfig } from '@renderer/hooks/use-app-config'
7
+ import { platform } from '@renderer/utils/init'
7
8
import { triggerSysProxy } from '@renderer/utils/ipc'
8
9
import { Key , useState } from 'react'
9
10
import React from 'react'
11
+ import { MdDeleteForever } from 'react-icons/md'
12
+
13
+ const defaultBypass : string [ ] =
14
+ platform === 'linux'
15
+ ? [ 'localhost' , '127.0.0.1' , '192.168.0.0/16' , '10.0.0.0/8' , '172.16.0.0/12' , '::1' ]
16
+ : platform === 'darwin'
17
+ ? [
18
+ '127.0.0.1' ,
19
+ '192.168.0.0/16' ,
20
+ '10.0.0.0/8' ,
21
+ '172.16.0.0/12' ,
22
+ 'localhost' ,
23
+ '*.local' ,
24
+ '*.crashlytics.com' ,
25
+ '<local>'
26
+ ]
27
+ : [
28
+ 'localhost' ,
29
+ '127.*' ,
30
+ '192.168.*' ,
31
+ '10.*' ,
32
+ '172.16.*' ,
33
+ '172.17.*' ,
34
+ '172.18.*' ,
35
+ '172.19.*' ,
36
+ '172.20.*' ,
37
+ '172.21.*' ,
38
+ '172.22.*' ,
39
+ '172.23.*' ,
40
+ '172.24.*' ,
41
+ '172.25.*' ,
42
+ '172.26.*' ,
43
+ '172.27.*' ,
44
+ '172.28.*' ,
45
+ '172.29.*' ,
46
+ '172.30.*' ,
47
+ '172.31.*' ,
48
+ '<local>'
49
+ ]
10
50
11
51
const defaultPacScript = `
12
52
function FindProxyForURL(url, host) {
@@ -16,10 +56,34 @@ function FindProxyForURL(url, host) {
16
56
17
57
const Sysproxy : React . FC = ( ) => {
18
58
const { appConfig, patchAppConfig } = useAppConfig ( )
19
- const { sysProxy } = appConfig || { sysProxy : { enable : false } }
59
+ const { sysProxy } = appConfig || ( { sysProxy : { enable : false } } as IAppConfig )
60
+
61
+ const [ values , setValues ] = useState ( {
62
+ enable : sysProxy . enable ,
63
+ host : sysProxy . host ?? '' ,
64
+ bypass : sysProxy . bypass ?? defaultBypass ,
65
+ mode : sysProxy . mode ?? 'manual' ,
66
+ pacScript : sysProxy . pacScript ?? defaultPacScript
67
+ } )
20
68
21
- const [ values , setValues ] = useState < ISysProxyConfig > ( sysProxy )
22
69
const [ openPacEditor , setOpenPacEditor ] = useState ( false )
70
+
71
+ const handleBypassChange = ( value : string , index : number ) : void => {
72
+ const newBypass = [ ...values . bypass ]
73
+ if ( index === newBypass . length ) {
74
+ if ( value . trim ( ) !== '' ) {
75
+ newBypass . push ( value )
76
+ }
77
+ } else {
78
+ if ( value . trim ( ) === '' ) {
79
+ newBypass . splice ( index , 1 )
80
+ } else {
81
+ newBypass [ index ] = value
82
+ }
83
+ }
84
+ setValues ( { ...values , bypass : newBypass } )
85
+ }
86
+
23
87
const onSave = async ( ) : Promise < void > => {
24
88
// check valid TODO
25
89
await patchAppConfig ( { sysProxy : values } )
@@ -74,11 +138,53 @@ const Sysproxy: React.FC = () => {
74
138
< Tab className = "select-none" key = "auto" title = "PAC" />
75
139
</ Tabs >
76
140
</ SettingItem >
77
- < SettingItem title = "代理模式" >
78
- < Button size = "sm" onPress = { ( ) => setOpenPacEditor ( true ) } variant = "bordered" >
79
- 编辑PAC脚本
80
- </ Button >
81
- </ SettingItem >
141
+
142
+ { values . mode === 'auto' && (
143
+ < SettingItem title = "代理模式" >
144
+ < Button size = "sm" onPress = { ( ) => setOpenPacEditor ( true ) } variant = "bordered" >
145
+ 编辑PAC脚本
146
+ </ Button >
147
+ </ SettingItem >
148
+ ) }
149
+ { values . mode === 'manual' && (
150
+ < >
151
+ < SettingItem title = "添加默认代理绕过" divider >
152
+ < Button
153
+ size = "sm"
154
+ onPress = { ( ) => {
155
+ setValues ( { ...values , bypass : defaultBypass . concat ( values . bypass ) } )
156
+ } }
157
+ >
158
+ 添加默认代理绕过
159
+ </ Button >
160
+ </ SettingItem >
161
+ < div className = "flex flex-col items-stretch" >
162
+ < h3 className = "select-none mb-2" > 代理绕过</ h3 >
163
+ { [ ...values . bypass , '' ] . map ( ( domain , index ) => (
164
+ < div key = { index } className = "mb-2 flex" >
165
+ < Input
166
+ fullWidth
167
+ size = "sm"
168
+ placeholder = "例: *.baidu.com"
169
+ value = { domain }
170
+ onValueChange = { ( v ) => handleBypassChange ( v , index ) }
171
+ />
172
+ { index < values . bypass . length && (
173
+ < Button
174
+ className = "ml-2"
175
+ size = "sm"
176
+ variant = "flat"
177
+ color = "warning"
178
+ onClick = { ( ) => handleBypassChange ( '' , index ) }
179
+ >
180
+ < MdDeleteForever className = "text-lg" />
181
+ </ Button >
182
+ ) }
183
+ </ div >
184
+ ) ) }
185
+ </ div >
186
+ </ >
187
+ ) }
82
188
</ SettingCard >
83
189
</ BasePage >
84
190
)
0 commit comments