feat: disable script mode when use clash meta

This commit is contained in:
GyDi 2022-11-21 22:28:57 +08:00
parent 48e14b36b8
commit 8086b6d78c
No known key found for this signature in database
GPG Key ID: 9C3AD40F1F99880A

View File

@ -1,11 +1,13 @@
import useSWR from "swr"; import useSWR from "swr";
import { useEffect, useMemo } from "react";
import { useLockFn } from "ahooks"; import { useLockFn } from "ahooks";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Button, ButtonGroup, Paper } from "@mui/material"; import { Button, ButtonGroup, Paper } from "@mui/material";
import { getClashConfig, updateConfigs } from "@/services/api"; import { getClashConfig, updateConfigs } from "@/services/api";
import { patchClashConfig } from "@/services/cmds"; import { patchClashConfig } from "@/services/cmds";
import { ProxyGroups } from "@/components/proxy/proxy-groups"; import { useVerge } from "@/hooks/use-verge";
import { BasePage } from "@/components/base"; import { BasePage } from "@/components/base";
import { ProxyGroups } from "@/components/proxy/proxy-groups";
const ProxyPage = () => { const ProxyPage = () => {
const { t } = useTranslation(); const { t } = useTranslation();
@ -15,7 +17,15 @@ const ProxyPage = () => {
getClashConfig 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 curMode = clashConfig?.mode.toLowerCase();
const onChangeMode = useLockFn(async (mode: string) => { const onChangeMode = useLockFn(async (mode: string) => {
@ -24,6 +34,12 @@ const ProxyPage = () => {
mutateClash(); mutateClash();
}); });
useEffect(() => {
if (curMode && !modeList.includes(curMode)) {
onChangeMode("rule");
}
}, [curMode]);
return ( return (
<BasePage <BasePage
contentStyle={{ height: "100%" }} contentStyle={{ height: "100%" }}