feat: edit system proxy bypass

This commit is contained in:
GyDi 2022-02-14 01:26:24 +08:00
parent 8548373742
commit 78a0cfd052
No known key found for this signature in database
GPG Key ID: 1C95E0D3467B3084
3 changed files with 29 additions and 5 deletions

View File

@ -281,10 +281,14 @@ pub fn get_cur_proxy(verge_state: State<'_, VergeState>) -> Result<Option<SysPro
/// get the verge config /// get the verge config
#[tauri::command] #[tauri::command]
pub fn get_verge_config(verge_state: State<'_, VergeState>) -> Result<VergeConfig, String> { pub fn get_verge_config(verge_state: State<'_, VergeState>) -> Result<VergeConfig, String> {
match verge_state.0.lock() { let verge = verge_state.0.lock().unwrap();
Ok(arc) => Ok(arc.config.clone()), let mut config = verge.config.clone();
Err(_) => Err("failed to get verge lock".into()),
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 /// patch the verge config

View File

@ -1,5 +1,5 @@
import useSWR, { useSWRConfig } from "swr"; 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 { getVergeConfig, patchVergeConfig } from "../../services/cmds";
import { SettingList, SettingItem } from "./setting"; import { SettingList, SettingItem } from "./setting";
import { CmdType } from "../../services/types"; import { CmdType } from "../../services/types";
@ -17,6 +17,7 @@ const SettingSystem = ({ onError }: Props) => {
const { const {
enable_auto_launch: startup = false, enable_auto_launch: startup = false,
enable_system_proxy: proxy = false, enable_system_proxy: proxy = false,
system_proxy_bypass: bypass = "",
} = vergeConfig ?? {}; } = vergeConfig ?? {};
const onSwitchFormat = (_e: any, value: boolean) => value; const onSwitchFormat = (_e: any, value: boolean) => value;
@ -55,11 +56,29 @@ const SettingSystem = ({ onError }: Props) => {
onCatch={onError} onCatch={onError}
onFormat={onSwitchFormat} onFormat={onSwitchFormat}
onChange={(e) => onChangeData({ enable_system_proxy: e })} 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
}}
> >
<Switch edge="end" /> <Switch edge="end" />
</GuardState> </GuardState>
</SettingItem> </SettingItem>
{proxy && (
<SettingItem>
<ListItemText primary="Proxy Bypass" />
<GuardState
value={bypass ?? ""}
onCatch={onError}
onFormat={(e: any) => e.target.value}
onChange={(e) => onChangeData({ system_proxy_bypass: e })}
onGuard={(e) => patchVergeConfig({ system_proxy_bypass: e })}
>
<TextField autoComplete="off" size="small" sx={{ width: 120 }} />
</GuardState>
</SettingItem>
)}
</SettingList> </SettingList>
); );
}; };

View File

@ -114,5 +114,6 @@ export namespace CmdType {
theme_blur?: boolean; theme_blur?: boolean;
enable_auto_launch?: boolean; enable_auto_launch?: boolean;
enable_system_proxy?: boolean; enable_system_proxy?: boolean;
system_proxy_bypass?: string;
} }
} }