Kaynağa Gözat

feat: disable script mode when use clash meta

GyDi 2 yıl önce
ebeveyn
işleme
8086b6d78c
1 değiştirilmiş dosya ile 18 ekleme ve 2 silme
  1. 18 2
      src/pages/proxies.tsx

+ 18 - 2
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 (
     <BasePage
       contentStyle={{ height: "100%" }}