Skip to content

Commit ddcb730

Browse files
author
pompurin404
committed
set sysproxy bypass
1 parent 95ae550 commit ddcb730

File tree

2 files changed

+114
-7
lines changed

2 files changed

+114
-7
lines changed

src/main/resolve/sysproxy.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getAppConfig, getControledMihomoConfig } from '../config'
33
import { pacPort } from './server'
44

55
let defaultBypass: string[]
6+
67
if (process.platform === 'linux')
78
defaultBypass = ['localhost', '127.0.0.1', '192.168.0.0/16', '10.0.0.0/8', '172.16.0.0/12', '::1']
89
if (process.platform === 'darwin')

src/renderer/src/pages/syspeoxy.tsx

+113-7
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,49 @@ import SettingCard from '@renderer/components/base/base-setting-card'
44
import SettingItem from '@renderer/components/base/base-setting-item'
55
import PacEditorViewer from '@renderer/components/sysproxy/pac-editor-modal'
66
import { useAppConfig } from '@renderer/hooks/use-app-config'
7+
import { platform } from '@renderer/utils/init'
78
import { triggerSysProxy } from '@renderer/utils/ipc'
89
import { Key, useState } from 'react'
910
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+
]
1050

1151
const defaultPacScript = `
1252
function FindProxyForURL(url, host) {
@@ -16,10 +56,34 @@ function FindProxyForURL(url, host) {
1656

1757
const Sysproxy: React.FC = () => {
1858
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+
})
2068

21-
const [values, setValues] = useState<ISysProxyConfig>(sysProxy)
2269
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+
2387
const onSave = async (): Promise<void> => {
2488
// check valid TODO
2589
await patchAppConfig({ sysProxy: values })
@@ -74,11 +138,53 @@ const Sysproxy: React.FC = () => {
74138
<Tab className="select-none" key="auto" title="PAC" />
75139
</Tabs>
76140
</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+
)}
82188
</SettingCard>
83189
</BasePage>
84190
)

0 commit comments

Comments
 (0)