feat: add unified delay

This commit is contained in:
huzibaca
2024-11-05 16:24:58 +08:00
parent ab7775e1ef
commit 2833718c90
15 changed files with 37 additions and 24 deletions

View File

@@ -41,7 +41,6 @@ export function GuardState<T>(props: Props<T>) {
childProps[onChangeProps] = async (...args: any[]) => {
// 多次操作无效
if (lockRef.current) return;
lockRef.current = true;
try {

View File

@@ -34,7 +34,12 @@ const SettingClash = ({ onError }: Props) => {
const { clash, version, mutateClash, patchClash } = useClash();
const { verge, mutateVerge, patchVerge } = useVerge();
const { ipv6, "allow-lan": allowLan, "log-level": logLevel } = clash ?? {};
const {
ipv6,
"allow-lan": allowLan,
"log-level": logLevel,
"unified-delay": unifiedDelay,
} = clash ?? {};
const { enable_random_port = false, verge_mixed_port } = verge ?? {};
@@ -106,6 +111,19 @@ const SettingClash = ({ onError }: Props) => {
</GuardState>
</SettingItem>
<SettingItem label={t("Unified Delay")}>
<GuardState
value={unifiedDelay ?? false}
valueProps="checked"
onCatch={onError}
onFormat={onSwitchFormat}
onChange={(e) => onChangeData({ "unified-delay": e })}
onGuard={(e) => patchClash({ "unified-delay": e })}
>
<Switch edge="end" />
</GuardState>
</SettingItem>
<SettingItem label={t("Log Level")}>
<GuardState
// clash premium 2022.08.26 值为warn

View File

@@ -1,6 +1,6 @@
import useSWR, { mutate } from "swr";
import { useLockFn } from "ahooks";
import { getAxios, getVersion, updateConfigs } from "@/services/api";
import { getAxios, getVersion } from "@/services/api";
import {
getClashInfo,
patchClashConfig,
@@ -19,7 +19,6 @@ export const useClash = () => {
);
const patchClash = useLockFn(async (patch: Partial<IConfigData>) => {
await updateConfigs(patch);
await patchClashConfig(patch);
mutateClash();
});

View File

@@ -246,6 +246,7 @@
"Ip Address": "IP Address",
"Mac Address": "MAC Address",
"IPv6": "IPv6",
"Unified Delay": "Unified Delay",
"Log Level": "Log Level",
"Port Config": "Port Config",
"Random Port": "Random Port",

View File

@@ -241,6 +241,7 @@
"Ip Address": "آدرس IP",
"Mac Address": "آدرس MAC",
"IPv6": "IPv6",
"Unified Delay": "معادلDELAY",
"Log Level": "سطح لاگ",
"Port Config": "پیکربندی پورت",
"Random Port": "پورت تصادفی",

View File

@@ -244,6 +244,7 @@
"Ip Address": "IP адрес",
"Mac Address": "MAC адрес",
"IPv6": "IPv6",
"Unified Delay": "Общий задержка",
"Log Level": "Уровень логов",
"Port Config": "Настройка порта",
"Random Port": "Случайный порт",

View File

@@ -246,6 +246,7 @@
"Ip Address": "IP 地址",
"Mac Address": "MAC 地址",
"IPv6": "IPv6",
"Unified Delay": "统一延时",
"Log Level": "日志等级",
"Port Config": "端口设置",
"Random Port": "随机端口",

View File

@@ -3,11 +3,7 @@ import { useEffect } from "react";
import { useLockFn } from "ahooks";
import { useTranslation } from "react-i18next";
import { Box, Button, ButtonGroup } from "@mui/material";
import {
closeAllConnections,
getClashConfig,
updateConfigs,
} from "@/services/api";
import { closeAllConnections, getClashConfig } from "@/services/api";
import { patchClashConfig } from "@/services/cmds";
import { useVerge } from "@/hooks/use-verge";
import { BasePage } from "@/components/base";
@@ -33,7 +29,6 @@ const ProxyPage = () => {
if (mode !== curMode && verge?.auto_close_connection) {
closeAllConnections();
}
await updateConfigs({ mode });
await patchClashConfig({ mode });
mutateClash();
});

View File

@@ -49,12 +49,6 @@ export const getClashConfig = async () => {
return instance.get("/configs") as Promise<IConfigData>;
};
/// Update current configs
export const updateConfigs = async (config: Partial<IConfigData>) => {
const instance = await getAxios();
return instance.patch("/configs", config);
};
/// Update geo data
export const updateGeoData = async () => {
const instance = await getAxios();

View File

@@ -32,6 +32,7 @@ interface IConfigData {
"tproxy-port": number;
"external-controller": string;
secret: string;
"unified-delay": boolean;
tun: {
stack: string;
device: string;