From 502706931e9fee8507290fc2b51a83318a84483f Mon Sep 17 00:00:00 2001 From: GyDi Date: Wed, 23 Mar 2022 12:49:34 +0800 Subject: [PATCH] fix: manage global proxy correctly --- src/components/proxy/proxy-global.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/proxy/proxy-global.tsx b/src/components/proxy/proxy-global.tsx index b2b4b1c..9ddb297 100644 --- a/src/components/proxy/proxy-global.tsx +++ b/src/components/proxy/proxy-global.tsx @@ -91,8 +91,24 @@ const ProxyGlobal = (props: Props) => { useEffect(() => { if (groupName === "DIRECT") setNow("DIRECT"); - if (groupName === "GLOBAL") setNow(curProxy || "DIRECT"); - }, [groupName, curProxy]); + else if (groupName === "GLOBAL") { + if (profiles) { + const current = profiles.current; + const profile = profiles.items?.find((p) => p.uid === current); + + profile?.selected?.forEach((item) => { + if (item.name === "GLOBAL") { + if (item.now && item.now !== curProxy) { + updateProxy("GLOBAL", item.now).then(() => setNow(item!.now!)); + mutate("getProxies"); + } + } + }); + } + + setNow(curProxy || "DIRECT"); + } + }, [groupName, curProxy, profiles]); return ( <>