diff --git a/src/main/resolve/sysproxy.ts b/src/main/resolve/sysproxy.ts index 50f1f0b5..7ab55740 100644 --- a/src/main/resolve/sysproxy.ts +++ b/src/main/resolve/sysproxy.ts @@ -52,7 +52,8 @@ export function triggerSysProxy(enable: boolean): void { export function enableSysProxy(): void { const { sysProxy } = getAppConfig() - const { mode, host, bypass = defaultBypass } = sysProxy + const { mode, host, bypass = [], useDefaultBypass } = sysProxy + if (useDefaultBypass) bypass.unshift(...defaultBypass) const { 'mixed-port': port = 7890 } = getControledMihomoConfig() switch (mode || 'manual') { diff --git a/src/renderer/src/pages/syspeoxy.tsx b/src/renderer/src/pages/syspeoxy.tsx index 6a5ac723..6ea8f4dc 100644 --- a/src/renderer/src/pages/syspeoxy.tsx +++ b/src/renderer/src/pages/syspeoxy.tsx @@ -1,4 +1,4 @@ -import { Button, Input, Tab, Tabs } from '@nextui-org/react' +import { Button, Input, Switch, Tab, Tabs } from '@nextui-org/react' import BasePage from '@renderer/components/base/base-page' import SettingCard from '@renderer/components/base/base-setting-card' import SettingItem from '@renderer/components/base/base-setting-item' @@ -7,6 +7,7 @@ import { useAppConfig } from '@renderer/hooks/use-app-config' import { triggerSysProxy } from '@renderer/utils/ipc' import { Key, useState } from 'react' import React from 'react' +import { MdDeleteForever } from 'react-icons/md' const defaultPacScript = ` function FindProxyForURL(url, host) { @@ -16,10 +17,35 @@ 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 ?? '', + useDefaultBypass: sysProxy.useDefaultBypass ?? true, + bypass: sysProxy.bypass ?? [], + 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 +100,52 @@ const Sysproxy: React.FC = () => { - - - + + {values.mode === 'auto' && ( + + + + )} + {values.mode === 'manual' && ( + <> + + { + setValues({ ...values, useDefaultBypass: v }) + }} + /> + +
+

代理绕过

+ {[...values.bypass, ''].map((domain, index) => ( +
+ handleBypassChange(v, index)} + /> + {index < values.bypass.length && ( + + )} +
+ ))} +
+ + )} ) diff --git a/src/shared/types.d.ts b/src/shared/types.d.ts index e0e7b0af..a5000493 100644 --- a/src/shared/types.d.ts +++ b/src/shared/types.d.ts @@ -147,6 +147,7 @@ interface ISysProxyConfig { enable: boolean host?: string mode?: SysProxyMode + useDefaultBypass?: boolean bypass?: string[] pacScript?: string }