[修复]修改代理设置后,如果修改之前代理是开启状态,自动重新应用代理设置。 (#3391)

* [修复]修改代理设置后,如果修改之前代理是开启状态,自动重新应用代理设置。

* chore: update sysproxy version

---------

Co-authored-by: Tunglies <tunglies.dev@outlook.com>
This commit is contained in:
逐雁南飛 2025-04-24 01:10:01 +08:00 committed by GitHub
parent 2622cc06eb
commit ffc0693afc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 2 deletions

3
src-tauri/Cargo.lock generated
View File

@ -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",

View File

@ -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 = [

View File

@ -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<DialogRef>((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());