From 8086b6d78c8d8591a13f312e1584a75531ebe96c Mon Sep 17 00:00:00 2001 From: GyDi Date: Mon, 21 Nov 2022 22:28:57 +0800 Subject: [PATCH] feat: disable script mode when use clash meta --- src/pages/proxies.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pages/proxies.tsx b/src/pages/proxies.tsx index 67452cc..901b4c1 100644 --- a/src/pages/proxies.tsx +++ b/src/pages/proxies.tsx @@ -1,11 +1,13 @@ import useSWR from "swr"; +import { useEffect, useMemo } from "react"; import { useLockFn } from "ahooks"; import { useTranslation } from "react-i18next"; import { Button, ButtonGroup, Paper } from "@mui/material"; import { getClashConfig, updateConfigs } from "@/services/api"; import { patchClashConfig } from "@/services/cmds"; -import { ProxyGroups } from "@/components/proxy/proxy-groups"; +import { useVerge } from "@/hooks/use-verge"; import { BasePage } from "@/components/base"; +import { ProxyGroups } from "@/components/proxy/proxy-groups"; const ProxyPage = () => { const { t } = useTranslation(); @@ -15,7 +17,15 @@ const ProxyPage = () => { getClashConfig ); - const modeList = ["rule", "global", "direct", "script"]; + const { verge } = useVerge(); + + const modeList = useMemo(() => { + if (verge?.clash_core === "clash-meta") { + return ["rule", "global", "direct"]; + } + return ["rule", "global", "direct", "script"]; + }, [verge?.clash_core]); + const curMode = clashConfig?.mode.toLowerCase(); const onChangeMode = useLockFn(async (mode: string) => { @@ -24,6 +34,12 @@ const ProxyPage = () => { mutateClash(); }); + useEffect(() => { + if (curMode && !modeList.includes(curMode)) { + onChangeMode("rule"); + } + }, [curMode]); + return (