mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 10:53:44 +08:00
90 lines
2.3 KiB
TypeScript
90 lines
2.3 KiB
TypeScript
import useSWR from "swr";
|
|
import { useEffect, useMemo } from "react";
|
|
import { useLockFn } from "ahooks";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Box, Button, ButtonGroup, Paper } from "@mui/material";
|
|
import {
|
|
closeAllConnections,
|
|
getClashConfig,
|
|
updateConfigs,
|
|
} from "@/services/api";
|
|
import { patchClashConfig } from "@/services/cmds";
|
|
import { useVerge } from "@/hooks/use-verge";
|
|
import { BasePage } from "@/components/base";
|
|
import { ProxyGroups } from "@/components/proxy/proxy-groups";
|
|
import { ProviderButton } from "@/components/proxy/provider-button";
|
|
|
|
const ProxyPage = () => {
|
|
const { t } = useTranslation();
|
|
|
|
const { data: clashConfig, mutate: mutateClash } = useSWR(
|
|
"getClashConfig",
|
|
getClashConfig
|
|
);
|
|
|
|
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) => {
|
|
// 断开连接
|
|
if (mode !== curMode && verge?.auto_close_connection) {
|
|
closeAllConnections();
|
|
}
|
|
await updateConfigs({ mode });
|
|
await patchClashConfig({ mode });
|
|
mutateClash();
|
|
});
|
|
|
|
useEffect(() => {
|
|
if (curMode && !modeList.includes(curMode)) {
|
|
onChangeMode("rule");
|
|
}
|
|
}, [curMode]);
|
|
|
|
return (
|
|
<BasePage
|
|
contentStyle={{ height: "100%" }}
|
|
title={t("Proxy Groups")}
|
|
header={
|
|
<Box display="flex" alignItems="center" gap={1}>
|
|
<ProviderButton />
|
|
|
|
<ButtonGroup size="small">
|
|
{modeList.map((mode) => (
|
|
<Button
|
|
key={mode}
|
|
variant={mode === curMode ? "contained" : "outlined"}
|
|
onClick={() => onChangeMode(mode)}
|
|
sx={{ textTransform: "capitalize" }}
|
|
>
|
|
{t(mode)}
|
|
</Button>
|
|
))}
|
|
</ButtonGroup>
|
|
</Box>
|
|
}
|
|
>
|
|
<Box
|
|
sx={{
|
|
borderRadius: 1,
|
|
boxShadow: 0,
|
|
height: "100%",
|
|
boxSizing: "border-box",
|
|
}}
|
|
>
|
|
<ProxyGroups mode={curMode!} />
|
|
</Box>
|
|
</BasePage>
|
|
);
|
|
};
|
|
|
|
export default ProxyPage;
|