refactor: frontend (#5068)

* refactor: setting components

* refactor: frontend

* fix: settings router
This commit is contained in:
Sline
2025-10-15 18:57:44 +08:00
committed by GitHub
parent a591ee1efc
commit 0b4403b67b
34 changed files with 1072 additions and 861 deletions
+30 -27
View File
@@ -16,6 +16,7 @@ import {
useEffect,
useImperativeHandle,
useMemo,
useRef,
useState,
} from "react";
import { useTranslation } from "react-i18next";
@@ -38,6 +39,11 @@ import {
import { showNotice } from "@/services/noticeService";
import getSystem from "@/utils/get-system";
const sleep = (ms: number) =>
new Promise<void>((resolve) => {
setTimeout(resolve, ms);
});
const DEFAULT_PAC = `function FindProxyForURL(url, host) {
return "PROXY %proxy_host%:%mixed-port%; SOCKS5 %proxy_host%:%mixed-port%; DIRECT;";
}`;
@@ -130,40 +136,37 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
errorRetryInterval: 5000,
});
const [prevMixedPort, setPrevMixedPort] = useState(clashConfig?.mixedPort);
const prevMixedPortRef = useRef(clashConfig?.mixedPort);
useEffect(() => {
if (clashConfig?.mixedPort && clashConfig.mixedPort !== prevMixedPort) {
setPrevMixedPort(clashConfig.mixedPort);
resetSystemProxy();
const mixedPort = clashConfig?.mixedPort;
if (!mixedPort || mixedPort === prevMixedPortRef.current) {
return;
}
}, [clashConfig?.mixedPort]);
const resetSystemProxy = async () => {
try {
const currentSysProxy = await getSystemProxy();
const currentAutoProxy = await getAutotemProxy();
prevMixedPortRef.current = mixedPort;
if (value.pac ? currentAutoProxy?.enable : currentSysProxy?.enable) {
// 临时关闭系统代理
await patchVergeConfig({ enable_system_proxy: false });
const updateProxy = async () => {
try {
const currentSysProxy = await getSystemProxy();
const currentAutoProxy = await getAutotemProxy();
// 减少等待时间
await new Promise((resolve) => setTimeout(resolve, 200));
// 重新开启系统代理
await patchVergeConfig({ enable_system_proxy: true });
// 更新UI状态
await Promise.all([
mutate("getSystemProxy"),
mutate("getAutotemProxy"),
]);
if (value.pac ? currentAutoProxy?.enable : currentSysProxy?.enable) {
await patchVergeConfig({ enable_system_proxy: false });
await sleep(200);
await patchVergeConfig({ enable_system_proxy: true });
await Promise.all([
mutate("getSystemProxy"),
mutate("getAutotemProxy"),
]);
}
} catch (err: any) {
showNotice("error", err.toString());
}
} catch (err: any) {
showNotice("error", err.toString());
}
};
};
updateProxy();
}, [clashConfig?.mixedPort, value.pac]);
const { systemProxyAddress } = useAppData();