diff --git a/src/main/resolve/sysproxy.ts b/src/main/resolve/sysproxy.ts index 50f1f0b..05e3fbd 100644 --- a/src/main/resolve/sysproxy.ts +++ b/src/main/resolve/sysproxy.ts @@ -3,6 +3,7 @@ import { getAppConfig, getControledMihomoConfig } from '../config' import { pacPort } from './server' let defaultBypass: string[] + if (process.platform === 'linux') defaultBypass = ['localhost', '127.0.0.1', '192.168.0.0/16', '10.0.0.0/8', '172.16.0.0/12', '::1'] if (process.platform === 'darwin') diff --git a/src/renderer/src/pages/syspeoxy.tsx b/src/renderer/src/pages/syspeoxy.tsx index 6a5ac72..c3ee2b3 100644 --- a/src/renderer/src/pages/syspeoxy.tsx +++ b/src/renderer/src/pages/syspeoxy.tsx @@ -4,9 +4,49 @@ import SettingCard from '@renderer/components/base/base-setting-card' import SettingItem from '@renderer/components/base/base-setting-item' import PacEditorViewer from '@renderer/components/sysproxy/pac-editor-modal' import { useAppConfig } from '@renderer/hooks/use-app-config' +import { platform } from '@renderer/utils/init' import { triggerSysProxy } from '@renderer/utils/ipc' import { Key, useState } from 'react' import React from 'react' +import { MdDeleteForever } from 'react-icons/md' + +const defaultBypass: string[] = + platform === 'linux' + ? ['localhost', '127.0.0.1', '192.168.0.0/16', '10.0.0.0/8', '172.16.0.0/12', '::1'] + : platform === 'darwin' + ? [ + '127.0.0.1', + '192.168.0.0/16', + '10.0.0.0/8', + '172.16.0.0/12', + 'localhost', + '*.local', + '*.crashlytics.com', + '' + ] + : [ + 'localhost', + '127.*', + '192.168.*', + '10.*', + '172.16.*', + '172.17.*', + '172.18.*', + '172.19.*', + '172.20.*', + '172.21.*', + '172.22.*', + '172.23.*', + '172.24.*', + '172.25.*', + '172.26.*', + '172.27.*', + '172.28.*', + '172.29.*', + '172.30.*', + '172.31.*', + '' + ] const defaultPacScript = ` function FindProxyForURL(url, host) { @@ -16,10 +56,34 @@ function FindProxyForURL(url, host) { const Sysproxy: React.FC = () => { const { appConfig, patchAppConfig } = useAppConfig() - const { sysProxy } = appConfig || { sysProxy: { enable: false } } + const { sysProxy } = appConfig || ({ sysProxy: { enable: false } } as IAppConfig) + + const [values, setValues] = useState({ + enable: sysProxy.enable, + host: sysProxy.host ?? '', + bypass: sysProxy.bypass ?? defaultBypass, + mode: sysProxy.mode ?? 'manual', + pacScript: sysProxy.pacScript ?? defaultPacScript + }) - const [values, setValues] = useState(sysProxy) const [openPacEditor, setOpenPacEditor] = useState(false) + + const handleBypassChange = (value: string, index: number): void => { + const newBypass = [...values.bypass] + if (index === newBypass.length) { + if (value.trim() !== '') { + newBypass.push(value) + } + } else { + if (value.trim() === '') { + newBypass.splice(index, 1) + } else { + newBypass[index] = value + } + } + setValues({ ...values, bypass: newBypass }) + } + const onSave = async (): Promise => { // check valid TODO await patchAppConfig({ sysProxy: values }) @@ -74,11 +138,53 @@ const Sysproxy: React.FC = () => { - - - + + {values.mode === 'auto' && ( + + + + )} + {values.mode === 'manual' && ( + <> + + + +
+

代理绕过

+ {[...values.bypass, ''].map((domain, index) => ( +
+ handleBypassChange(v, index)} + /> + {index < values.bypass.length && ( + + )} +
+ ))} +
+ + )} )