mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-17 07:50:33 +08:00
parent
09a4e7e083
commit
86dcf0bdcf
@ -285,23 +285,37 @@ export const ProxyChain = ({
|
|||||||
|
|
||||||
const handleConnect = useCallback(async () => {
|
const handleConnect = useCallback(async () => {
|
||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
// 如果已连接,则断开连接
|
|
||||||
setIsConnecting(true);
|
setIsConnecting(true);
|
||||||
try {
|
try {
|
||||||
// 清空链式代理配置
|
|
||||||
await updateProxyChainConfigInRuntime(null);
|
await updateProxyChainConfigInRuntime(null);
|
||||||
|
|
||||||
// 切换到 DIRECT 模式断开代理连接
|
const targetGroup =
|
||||||
// await updateProxyAndSync("GLOBAL", "DIRECT");
|
mode === "global"
|
||||||
|
? "GLOBAL"
|
||||||
|
: selectedGroup || localStorage.getItem("proxy-chain-group");
|
||||||
|
|
||||||
|
if (targetGroup) {
|
||||||
|
try {
|
||||||
|
await selectNodeForGroup(targetGroup, "DIRECT");
|
||||||
|
} catch {
|
||||||
|
if (proxyChain.length >= 1) {
|
||||||
|
try {
|
||||||
|
await selectNodeForGroup(targetGroup, proxyChain[0].name);
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage.removeItem("proxy-chain-group");
|
||||||
|
localStorage.removeItem("proxy-chain-exit-node");
|
||||||
|
localStorage.removeItem("proxy-chain-items");
|
||||||
|
|
||||||
// 关闭所有连接
|
|
||||||
await closeAllConnections();
|
await closeAllConnections();
|
||||||
|
await mutateProxies();
|
||||||
|
|
||||||
// 刷新代理信息以更新连接状态
|
onUpdateChain([]);
|
||||||
mutateProxies();
|
|
||||||
|
|
||||||
// 清空链式代理配置UI
|
|
||||||
// onUpdateChain([]);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to disconnect from proxy chain:", error);
|
console.error("Failed to disconnect from proxy chain:", error);
|
||||||
alert(t("proxies.page.chain.disconnectFailed") || "断开链式代理失败");
|
alert(t("proxies.page.chain.disconnectFailed") || "断开链式代理失败");
|
||||||
@ -348,7 +362,15 @@ export const ProxyChain = ({
|
|||||||
} finally {
|
} finally {
|
||||||
setIsConnecting(false);
|
setIsConnecting(false);
|
||||||
}
|
}
|
||||||
}, [proxyChain, isConnected, t, mutateProxies, mode, selectedGroup]);
|
}, [
|
||||||
|
proxyChain,
|
||||||
|
isConnected,
|
||||||
|
t,
|
||||||
|
mutateProxies,
|
||||||
|
mode,
|
||||||
|
selectedGroup,
|
||||||
|
onUpdateChain,
|
||||||
|
]);
|
||||||
|
|
||||||
const proxyChainRef = useRef(proxyChain);
|
const proxyChainRef = useRef(proxyChain);
|
||||||
const onUpdateChainRef = useRef(onUpdateChain);
|
const onUpdateChainRef = useRef(onUpdateChain);
|
||||||
@ -376,10 +398,11 @@ export const ProxyChain = ({
|
|||||||
type: proxy.type,
|
type: proxy.type,
|
||||||
delay: undefined,
|
delay: undefined,
|
||||||
})) || [];
|
})) || [];
|
||||||
onUpdateChain(chainItems);
|
if (chainItems.length > 0) {
|
||||||
|
onUpdateChain(chainItems);
|
||||||
|
}
|
||||||
} catch (parseError) {
|
} catch (parseError) {
|
||||||
console.error("Failed to parse YAML:", parseError);
|
console.error("Failed to parse YAML:", parseError);
|
||||||
onUpdateChain([]);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((importError) => {
|
.catch((importError) => {
|
||||||
@ -399,19 +422,16 @@ export const ProxyChain = ({
|
|||||||
type: proxy.type,
|
type: proxy.type,
|
||||||
delay: undefined,
|
delay: undefined,
|
||||||
})) || [];
|
})) || [];
|
||||||
onUpdateChain(chainItems);
|
if (chainItems.length > 0) {
|
||||||
|
onUpdateChain(chainItems);
|
||||||
|
}
|
||||||
} catch (jsonError) {
|
} catch (jsonError) {
|
||||||
console.error("Failed to parse as JSON either:", jsonError);
|
console.error("Failed to parse as JSON either:", jsonError);
|
||||||
onUpdateChain([]);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to process chain config data:", error);
|
console.error("Failed to process chain config data:", error);
|
||||||
onUpdateChain([]);
|
|
||||||
}
|
}
|
||||||
} else if (chainConfigData === "") {
|
|
||||||
// Empty string means no proxies available, show empty state
|
|
||||||
onUpdateChain([]);
|
|
||||||
}
|
}
|
||||||
}, [chainConfigData, onUpdateChain]);
|
}, [chainConfigData, onUpdateChain]);
|
||||||
|
|
||||||
@ -481,6 +501,9 @@ export const ProxyChain = ({
|
|||||||
size="small"
|
size="small"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
updateProxyChainConfigInRuntime(null);
|
updateProxyChainConfigInRuntime(null);
|
||||||
|
localStorage.removeItem("proxy-chain-group");
|
||||||
|
localStorage.removeItem("proxy-chain-exit-node");
|
||||||
|
localStorage.removeItem("proxy-chain-items");
|
||||||
onUpdateChain([]);
|
onUpdateChain([]);
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
|
|||||||
@ -51,8 +51,26 @@ const VirtuosoFooter = () => <div style={{ height: "8px" }} />;
|
|||||||
export const ProxyGroups = (props: Props) => {
|
export const ProxyGroups = (props: Props) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { mode, isChainMode = false, chainConfigData } = props;
|
const { mode, isChainMode = false, chainConfigData } = props;
|
||||||
const [proxyChain, setProxyChain] = useState<ProxyChainItem[]>([]);
|
const [proxyChain, setProxyChain] = useState<ProxyChainItem[]>(() => {
|
||||||
|
try {
|
||||||
|
const saved = localStorage.getItem("proxy-chain-items");
|
||||||
|
if (saved) {
|
||||||
|
return JSON.parse(saved);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
});
|
||||||
const [selectedGroup, setSelectedGroup] = useState<string | null>(null);
|
const [selectedGroup, setSelectedGroup] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (proxyChain.length > 0) {
|
||||||
|
localStorage.setItem("proxy-chain-items", JSON.stringify(proxyChain));
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem("proxy-chain-items");
|
||||||
|
}
|
||||||
|
}, [proxyChain]);
|
||||||
const [ruleMenuAnchor, setRuleMenuAnchor] = useState<null | HTMLElement>(
|
const [ruleMenuAnchor, setRuleMenuAnchor] = useState<null | HTMLElement>(
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
@ -231,10 +249,11 @@ export const ProxyGroups = (props: Props) => {
|
|||||||
setSelectedGroup(groupName);
|
setSelectedGroup(groupName);
|
||||||
handleGroupMenuClose();
|
handleGroupMenuClose();
|
||||||
|
|
||||||
// 在链式代理模式的规则模式下,切换代理组时清空链式代理配置
|
|
||||||
if (isChainMode && mode === "rule") {
|
if (isChainMode && mode === "rule") {
|
||||||
updateProxyChainConfigInRuntime(null);
|
updateProxyChainConfigInRuntime(null);
|
||||||
// 同时清空右侧链式代理配置
|
localStorage.removeItem("proxy-chain-group");
|
||||||
|
localStorage.removeItem("proxy-chain-exit-node");
|
||||||
|
localStorage.removeItem("proxy-chain-items");
|
||||||
setProxyChain([]);
|
setProxyChain([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user