From 78a0cfd052d6ecf428786a67a4de8ccf17d312cc Mon Sep 17 00:00:00 2001 From: GyDi Date: Mon, 14 Feb 2022 01:26:24 +0800 Subject: [PATCH] feat: edit system proxy bypass --- src-tauri/src/cmds.rs | 10 +++++++--- src/components/setting/setting-system.tsx | 23 +++++++++++++++++++++-- src/services/types.ts | 1 + 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/cmds.rs b/src-tauri/src/cmds.rs index 8cf1b54..617ac42 100644 --- a/src-tauri/src/cmds.rs +++ b/src-tauri/src/cmds.rs @@ -281,10 +281,14 @@ pub fn get_cur_proxy(verge_state: State<'_, VergeState>) -> Result) -> Result { - match verge_state.0.lock() { - Ok(arc) => Ok(arc.config.clone()), - Err(_) => Err("failed to get verge lock".into()), + let verge = verge_state.0.lock().unwrap(); + let mut config = verge.config.clone(); + + if config.system_proxy_bypass.is_none() && verge.cur_sysproxy.is_some() { + config.system_proxy_bypass = Some(verge.cur_sysproxy.clone().unwrap().bypass) } + + Ok(config) } /// patch the verge config diff --git a/src/components/setting/setting-system.tsx b/src/components/setting/setting-system.tsx index 5ccad99..b19e986 100644 --- a/src/components/setting/setting-system.tsx +++ b/src/components/setting/setting-system.tsx @@ -1,5 +1,5 @@ import useSWR, { useSWRConfig } from "swr"; -import { Box, ListItemText, Switch } from "@mui/material"; +import { Box, ListItemText, Switch, TextField } from "@mui/material"; import { getVergeConfig, patchVergeConfig } from "../../services/cmds"; import { SettingList, SettingItem } from "./setting"; import { CmdType } from "../../services/types"; @@ -17,6 +17,7 @@ const SettingSystem = ({ onError }: Props) => { const { enable_auto_launch: startup = false, enable_system_proxy: proxy = false, + system_proxy_bypass: bypass = "", } = vergeConfig ?? {}; const onSwitchFormat = (_e: any, value: boolean) => value; @@ -55,11 +56,29 @@ const SettingSystem = ({ onError }: Props) => { onCatch={onError} onFormat={onSwitchFormat} onChange={(e) => onChangeData({ enable_system_proxy: e })} - onGuard={(e) => patchVergeConfig({ enable_system_proxy: e })} + onGuard={async (e) => { + await patchVergeConfig({ enable_system_proxy: e }); + mutate("getVergeConfig"); // update bypass value + }} > + + {proxy && ( + + + e.target.value} + onChange={(e) => onChangeData({ system_proxy_bypass: e })} + onGuard={(e) => patchVergeConfig({ system_proxy_bypass: e })} + > + + + + )} ); }; diff --git a/src/services/types.ts b/src/services/types.ts index 1f42c82..2216cd7 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -114,5 +114,6 @@ export namespace CmdType { theme_blur?: boolean; enable_auto_launch?: boolean; enable_system_proxy?: boolean; + system_proxy_bypass?: string; } }