mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-16 11:42:21 +08:00
feat: add unified delay
This commit is contained in:
parent
ab7775e1ef
commit
2833718c90
|
@ -55,6 +55,7 @@ impl IClashTemp {
|
||||||
map.insert("secret".into(), "".into());
|
map.insert("secret".into(), "".into());
|
||||||
map.insert("tun".into(), tun.into());
|
map.insert("tun".into(), tun.into());
|
||||||
map.insert("external-controller-cors".into(), cors_map.into());
|
map.insert("external-controller-cors".into(), cors_map.into());
|
||||||
|
map.insert("unified-delay".into(), true.into());
|
||||||
Self(map)
|
Self(map)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ impl IRuntime {
|
||||||
// 这里只更改 allow-lan | ipv6 | log-level | tun
|
// 这里只更改 allow-lan | ipv6 | log-level | tun
|
||||||
pub fn patch_config(&mut self, patch: Mapping) {
|
pub fn patch_config(&mut self, patch: Mapping) {
|
||||||
if let Some(config) = self.config.as_mut() {
|
if let Some(config) = self.config.as_mut() {
|
||||||
["allow-lan", "ipv6", "log-level"]
|
["allow-lan", "ipv6", "log-level", "unified-delay"]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|key| {
|
.for_each(|key| {
|
||||||
if let Some(value) = patch.get(key).to_owned() {
|
if let Some(value) = patch.get(key).to_owned() {
|
||||||
|
|
|
@ -9,7 +9,7 @@ use std::collections::HashMap;
|
||||||
/// path 是绝对路径
|
/// path 是绝对路径
|
||||||
pub async fn put_configs(path: &str) -> Result<()> {
|
pub async fn put_configs(path: &str) -> Result<()> {
|
||||||
let (url, headers) = clash_client_info()?;
|
let (url, headers) = clash_client_info()?;
|
||||||
let url = format!("{url}/configs");
|
let url = format!("{url}/configs?force=true");
|
||||||
|
|
||||||
let mut data = HashMap::new();
|
let mut data = HashMap::new();
|
||||||
data.insert("path", path);
|
data.insert("path", path);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use serde_yaml::{Mapping, Value};
|
use serde_yaml::{Mapping, Value};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
pub const HANDLE_FIELDS: [&str; 11] = [
|
pub const HANDLE_FIELDS: [&str; 12] = [
|
||||||
"mode",
|
"mode",
|
||||||
"redir-port",
|
"redir-port",
|
||||||
"tproxy-port",
|
"tproxy-port",
|
||||||
|
@ -13,6 +13,7 @@ pub const HANDLE_FIELDS: [&str; 11] = [
|
||||||
"ipv6",
|
"ipv6",
|
||||||
"external-controller",
|
"external-controller",
|
||||||
"secret",
|
"secret",
|
||||||
|
"unified-delay",
|
||||||
];
|
];
|
||||||
|
|
||||||
pub const DEFAULT_FIELDS: [&str; 5] = [
|
pub const DEFAULT_FIELDS: [&str; 5] = [
|
||||||
|
|
|
@ -119,14 +119,15 @@ pub async fn patch_clash(patch: Mapping) -> Result<()> {
|
||||||
Config::generate().await?;
|
Config::generate().await?;
|
||||||
CoreManager::global().restart_core().await?;
|
CoreManager::global().restart_core().await?;
|
||||||
handle::Handle::refresh_clash();
|
handle::Handle::refresh_clash();
|
||||||
}
|
} else {
|
||||||
|
if patch.get("mode").is_some() {
|
||||||
|
log_err!(handle::Handle::update_systray_part());
|
||||||
|
}
|
||||||
|
|
||||||
if patch.get("mode").is_some() {
|
Config::runtime().latest().patch_config(patch);
|
||||||
log_err!(handle::Handle::update_systray_part());
|
update_core_config(false).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::runtime().latest().patch_config(patch);
|
|
||||||
|
|
||||||
<Result<()>>::Ok(())
|
<Result<()>>::Ok(())
|
||||||
};
|
};
|
||||||
match res {
|
match res {
|
||||||
|
|
|
@ -41,7 +41,6 @@ export function GuardState<T>(props: Props<T>) {
|
||||||
childProps[onChangeProps] = async (...args: any[]) => {
|
childProps[onChangeProps] = async (...args: any[]) => {
|
||||||
// 多次操作无效
|
// 多次操作无效
|
||||||
if (lockRef.current) return;
|
if (lockRef.current) return;
|
||||||
|
|
||||||
lockRef.current = true;
|
lockRef.current = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -34,7 +34,12 @@ const SettingClash = ({ onError }: Props) => {
|
||||||
const { clash, version, mutateClash, patchClash } = useClash();
|
const { clash, version, mutateClash, patchClash } = useClash();
|
||||||
const { verge, mutateVerge, patchVerge } = useVerge();
|
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 ?? {};
|
const { enable_random_port = false, verge_mixed_port } = verge ?? {};
|
||||||
|
|
||||||
|
@ -106,6 +111,19 @@ const SettingClash = ({ onError }: Props) => {
|
||||||
</GuardState>
|
</GuardState>
|
||||||
</SettingItem>
|
</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")}>
|
<SettingItem label={t("Log Level")}>
|
||||||
<GuardState
|
<GuardState
|
||||||
// clash premium 2022.08.26 值为warn
|
// clash premium 2022.08.26 值为warn
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import useSWR, { mutate } from "swr";
|
import useSWR, { mutate } from "swr";
|
||||||
import { useLockFn } from "ahooks";
|
import { useLockFn } from "ahooks";
|
||||||
import { getAxios, getVersion, updateConfigs } from "@/services/api";
|
import { getAxios, getVersion } from "@/services/api";
|
||||||
import {
|
import {
|
||||||
getClashInfo,
|
getClashInfo,
|
||||||
patchClashConfig,
|
patchClashConfig,
|
||||||
|
@ -19,7 +19,6 @@ export const useClash = () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
const patchClash = useLockFn(async (patch: Partial<IConfigData>) => {
|
const patchClash = useLockFn(async (patch: Partial<IConfigData>) => {
|
||||||
await updateConfigs(patch);
|
|
||||||
await patchClashConfig(patch);
|
await patchClashConfig(patch);
|
||||||
mutateClash();
|
mutateClash();
|
||||||
});
|
});
|
||||||
|
|
|
@ -246,6 +246,7 @@
|
||||||
"Ip Address": "IP Address",
|
"Ip Address": "IP Address",
|
||||||
"Mac Address": "MAC Address",
|
"Mac Address": "MAC Address",
|
||||||
"IPv6": "IPv6",
|
"IPv6": "IPv6",
|
||||||
|
"Unified Delay": "Unified Delay",
|
||||||
"Log Level": "Log Level",
|
"Log Level": "Log Level",
|
||||||
"Port Config": "Port Config",
|
"Port Config": "Port Config",
|
||||||
"Random Port": "Random Port",
|
"Random Port": "Random Port",
|
||||||
|
|
|
@ -241,6 +241,7 @@
|
||||||
"Ip Address": "آدرس IP",
|
"Ip Address": "آدرس IP",
|
||||||
"Mac Address": "آدرس MAC",
|
"Mac Address": "آدرس MAC",
|
||||||
"IPv6": "IPv6",
|
"IPv6": "IPv6",
|
||||||
|
"Unified Delay": "معادلDELAY",
|
||||||
"Log Level": "سطح لاگ",
|
"Log Level": "سطح لاگ",
|
||||||
"Port Config": "پیکربندی پورت",
|
"Port Config": "پیکربندی پورت",
|
||||||
"Random Port": "پورت تصادفی",
|
"Random Port": "پورت تصادفی",
|
||||||
|
|
|
@ -244,6 +244,7 @@
|
||||||
"Ip Address": "IP адрес",
|
"Ip Address": "IP адрес",
|
||||||
"Mac Address": "MAC адрес",
|
"Mac Address": "MAC адрес",
|
||||||
"IPv6": "IPv6",
|
"IPv6": "IPv6",
|
||||||
|
"Unified Delay": "Общий задержка",
|
||||||
"Log Level": "Уровень логов",
|
"Log Level": "Уровень логов",
|
||||||
"Port Config": "Настройка порта",
|
"Port Config": "Настройка порта",
|
||||||
"Random Port": "Случайный порт",
|
"Random Port": "Случайный порт",
|
||||||
|
|
|
@ -246,6 +246,7 @@
|
||||||
"Ip Address": "IP 地址",
|
"Ip Address": "IP 地址",
|
||||||
"Mac Address": "MAC 地址",
|
"Mac Address": "MAC 地址",
|
||||||
"IPv6": "IPv6",
|
"IPv6": "IPv6",
|
||||||
|
"Unified Delay": "统一延时",
|
||||||
"Log Level": "日志等级",
|
"Log Level": "日志等级",
|
||||||
"Port Config": "端口设置",
|
"Port Config": "端口设置",
|
||||||
"Random Port": "随机端口",
|
"Random Port": "随机端口",
|
||||||
|
|
|
@ -3,11 +3,7 @@ import { useEffect } from "react";
|
||||||
import { useLockFn } from "ahooks";
|
import { useLockFn } from "ahooks";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Box, Button, ButtonGroup } from "@mui/material";
|
import { Box, Button, ButtonGroup } from "@mui/material";
|
||||||
import {
|
import { closeAllConnections, getClashConfig } from "@/services/api";
|
||||||
closeAllConnections,
|
|
||||||
getClashConfig,
|
|
||||||
updateConfigs,
|
|
||||||
} from "@/services/api";
|
|
||||||
import { patchClashConfig } from "@/services/cmds";
|
import { patchClashConfig } from "@/services/cmds";
|
||||||
import { useVerge } from "@/hooks/use-verge";
|
import { useVerge } from "@/hooks/use-verge";
|
||||||
import { BasePage } from "@/components/base";
|
import { BasePage } from "@/components/base";
|
||||||
|
@ -33,7 +29,6 @@ const ProxyPage = () => {
|
||||||
if (mode !== curMode && verge?.auto_close_connection) {
|
if (mode !== curMode && verge?.auto_close_connection) {
|
||||||
closeAllConnections();
|
closeAllConnections();
|
||||||
}
|
}
|
||||||
await updateConfigs({ mode });
|
|
||||||
await patchClashConfig({ mode });
|
await patchClashConfig({ mode });
|
||||||
mutateClash();
|
mutateClash();
|
||||||
});
|
});
|
||||||
|
|
|
@ -49,12 +49,6 @@ export const getClashConfig = async () => {
|
||||||
return instance.get("/configs") as Promise<IConfigData>;
|
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
|
/// Update geo data
|
||||||
export const updateGeoData = async () => {
|
export const updateGeoData = async () => {
|
||||||
const instance = await getAxios();
|
const instance = await getAxios();
|
||||||
|
|
1
src/services/types.d.ts
vendored
1
src/services/types.d.ts
vendored
|
@ -32,6 +32,7 @@ interface IConfigData {
|
||||||
"tproxy-port": number;
|
"tproxy-port": number;
|
||||||
"external-controller": string;
|
"external-controller": string;
|
||||||
secret: string;
|
secret: string;
|
||||||
|
"unified-delay": boolean;
|
||||||
tun: {
|
tun: {
|
||||||
stack: string;
|
stack: string;
|
||||||
device: string;
|
device: string;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user