mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 07:03:45 +08:00
[修复]修改代理设置后,如果修改之前代理是开启状态,自动重新应用代理设置。 (#3391)
* [修复]修改代理设置后,如果修改之前代理是开启状态,自动重新应用代理设置。 * chore: update sysproxy version --------- Co-authored-by: Tunglies <tunglies.dev@outlook.com>
This commit is contained in:
parent
2622cc06eb
commit
ffc0693afc
3
src-tauri/Cargo.lock
generated
3
src-tauri/Cargo.lock
generated
@ -6696,12 +6696,13 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "sysproxy"
|
name = "sysproxy"
|
||||||
version = "0.3.0"
|
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 = [
|
dependencies = [
|
||||||
"interfaces",
|
"interfaces",
|
||||||
"iptools",
|
"iptools",
|
||||||
"log",
|
"log",
|
||||||
"thiserror 1.0.69",
|
"thiserror 1.0.69",
|
||||||
|
"url",
|
||||||
"windows 0.58.0",
|
"windows 0.58.0",
|
||||||
"winreg 0.52.0",
|
"winreg 0.52.0",
|
||||||
"xdg",
|
"xdg",
|
||||||
|
@ -43,7 +43,7 @@ tokio = { version = "1.44", features = [
|
|||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
reqwest = { version = "0.12", features = ["json", "rustls-tls", "cookies"] }
|
reqwest = { version = "0.12", features = ["json", "rustls-tls", "cookies"] }
|
||||||
regex = "1.11.1"
|
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"
|
image = "0.25.6"
|
||||||
imageproc = "0.25.0"
|
imageproc = "0.25.0"
|
||||||
tauri = { version = "2.4.0", features = [
|
tauri = { version = "2.4.0", features = [
|
||||||
|
@ -9,6 +9,8 @@ import {
|
|||||||
getNetworkInterfacesInfo,
|
getNetworkInterfacesInfo,
|
||||||
getSystemHostname,
|
getSystemHostname,
|
||||||
getSystemProxy,
|
getSystemProxy,
|
||||||
|
patchVergeConfig,
|
||||||
|
restartCore,
|
||||||
} from "@/services/cmds";
|
} from "@/services/cmds";
|
||||||
import getSystem from "@/utils/get-system";
|
import getSystem from "@/utils/get-system";
|
||||||
import { EditRounded } from "@mui/icons-material";
|
import { EditRounded } from "@mui/icons-material";
|
||||||
@ -32,6 +34,7 @@ import {
|
|||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { mutate } from "swr";
|
||||||
const DEFAULT_PAC = `function FindProxyForURL(url, host) {
|
const DEFAULT_PAC = `function FindProxyForURL(url, host) {
|
||||||
return "PROXY %proxy_host%:%mixed-port%; SOCKS5 %proxy_host%:%mixed-port%; DIRECT;";
|
return "PROXY %proxy_host%:%mixed-port%; SOCKS5 %proxy_host%:%mixed-port%; DIRECT;";
|
||||||
}`;
|
}`;
|
||||||
@ -264,6 +267,34 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await patchVerge(patch);
|
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);
|
setOpen(false);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
Notice.error(err.message || err.toString());
|
Notice.error(err.message || err.toString());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user