diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 2fedd83c..7037b7bd 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -6696,12 +6696,13 @@ dependencies = [ [[package]] name = "sysproxy" version = "0.3.0" -source = "git+https://github.com/clash-verge-rev/sysproxy-rs?rev=3d748b5#3d748b5743fcd954ced7a7fb45707bb1114494f2" +source = "git+https://github.com/clash-verge-rev/sysproxy-rs#28c3df9005694354cbaf725c23fe243854aac8a0" dependencies = [ "interfaces", "iptools", "log", "thiserror 1.0.69", + "url", "windows 0.58.0", "winreg 0.52.0", "xdg", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 4497e0d6..e32f70c6 100755 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -43,7 +43,7 @@ tokio = { version = "1.44", features = [ serde = { version = "1.0", features = ["derive"] } reqwest = { version = "0.12", features = ["json", "rustls-tls", "cookies"] } regex = "1.11.1" -sysproxy = { git = "https://github.com/clash-verge-rev/sysproxy-rs", rev = "3d748b5" } +sysproxy = { git = "https://github.com/clash-verge-rev/sysproxy-rs" } image = "0.25.6" imageproc = "0.25.0" tauri = { version = "2.4.0", features = [ diff --git a/src/components/setting/mods/sysproxy-viewer.tsx b/src/components/setting/mods/sysproxy-viewer.tsx index 9dcf8a85..aeaabdd1 100644 --- a/src/components/setting/mods/sysproxy-viewer.tsx +++ b/src/components/setting/mods/sysproxy-viewer.tsx @@ -9,6 +9,8 @@ import { getNetworkInterfacesInfo, getSystemHostname, getSystemProxy, + patchVergeConfig, + restartCore, } from "@/services/cmds"; import getSystem from "@/utils/get-system"; import { EditRounded } from "@mui/icons-material"; @@ -32,6 +34,7 @@ import { useState, } from "react"; import { useTranslation } from "react-i18next"; +import { mutate } from "swr"; const DEFAULT_PAC = `function FindProxyForURL(url, host) { return "PROXY %proxy_host%:%mixed-port%; SOCKS5 %proxy_host%:%mixed-port%; DIRECT;"; }`; @@ -264,6 +267,34 @@ export const SysproxyViewer = forwardRef((props, ref) => { try { await patchVerge(patch); + + // 更新系统代理状态,以便UI立即反映变化 + await new Promise((resolve) => setTimeout(resolve, 100)); + await mutate("getSystemProxy"); + await mutate("getAutotemProxy"); + + // 如果系统代理当前已开启,则重新应用系统代理设置以便立即生效 + const currentSysProxy = await getSystemProxy(); + const currentAutoProxy = await getAutotemProxy(); + + if (value.pac ? currentAutoProxy?.enable : currentSysProxy?.enable) { + // 如果系统代理已开启,则通过临时切换代理状态来触发系统代理重新应用 + const currentState = enabled ?? false; + + // 临时关闭系统代理 + await patchVergeConfig({ enable_system_proxy: false }); + + // 等待一小段时间 + await new Promise((resolve) => setTimeout(resolve, 300)); + + // 重新开启系统代理 + await patchVergeConfig({ enable_system_proxy: currentState }); + + // 更新UI状态 + await mutate("getSystemProxy"); + await mutate("getAutotemProxy"); + } + setOpen(false); } catch (err: any) { Notice.error(err.message || err.toString());