feat: add unified delay

This commit is contained in:
huzibaca 2024-11-05 16:24:58 +08:00
parent ab7775e1ef
commit 2833718c90
No known key found for this signature in database
GPG Key ID: D4364EE4851DC302
15 changed files with 37 additions and 24 deletions

View File

@ -55,6 +55,7 @@ impl IClashTemp {
map.insert("secret".into(), "".into());
map.insert("tun".into(), tun.into());
map.insert("external-controller-cors".into(), cors_map.into());
map.insert("unified-delay".into(), true.into());
Self(map)
}

View File

@ -19,7 +19,7 @@ impl IRuntime {
// 这里只更改 allow-lan | ipv6 | log-level | tun
pub fn patch_config(&mut self, patch: Mapping) {
if let Some(config) = self.config.as_mut() {
["allow-lan", "ipv6", "log-level"]
["allow-lan", "ipv6", "log-level", "unified-delay"]
.into_iter()
.for_each(|key| {
if let Some(value) = patch.get(key).to_owned() {

View File

@ -9,7 +9,7 @@ use std::collections::HashMap;
/// path 是绝对路径
pub async fn put_configs(path: &str) -> Result<()> {
let (url, headers) = clash_client_info()?;
let url = format!("{url}/configs");
let url = format!("{url}/configs?force=true");
let mut data = HashMap::new();
data.insert("path", path);

View File

@ -1,7 +1,7 @@
use serde_yaml::{Mapping, Value};
use std::collections::HashSet;
pub const HANDLE_FIELDS: [&str; 11] = [
pub const HANDLE_FIELDS: [&str; 12] = [
"mode",
"redir-port",
"tproxy-port",
@ -13,6 +13,7 @@ pub const HANDLE_FIELDS: [&str; 11] = [
"ipv6",
"external-controller",
"secret",
"unified-delay",
];
pub const DEFAULT_FIELDS: [&str; 5] = [

View File

@ -119,14 +119,15 @@ pub async fn patch_clash(patch: Mapping) -> Result<()> {
Config::generate().await?;
CoreManager::global().restart_core().await?;
handle::Handle::refresh_clash();
}
} else {
if patch.get("mode").is_some() {
log_err!(handle::Handle::update_systray_part());
}
if patch.get("mode").is_some() {
log_err!(handle::Handle::update_systray_part());
Config::runtime().latest().patch_config(patch);
update_core_config(false).await?;
}
Config::runtime().latest().patch_config(patch);
<Result<()>>::Ok(())
};
match res {

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;