From 71ebb00309c5aaa021185458458bc563827be42c Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Wed, 7 Aug 2024 17:36:47 +0800 Subject: [PATCH] set sysproxy bypass --- src/main/resolve/sysproxy.ts | 3 +- src/renderer/src/pages/syspeoxy.tsx | 83 ++++++++++++++++++++++++++--- src/shared/types.d.ts | 1 + 3 files changed, 78 insertions(+), 9 deletions(-) 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 }