diff --git a/src-tauri/src/config/verge.rs b/src-tauri/src/config/verge.rs index cba0d3e..9bf6919 100644 --- a/src-tauri/src/config/verge.rs +++ b/src-tauri/src/config/verge.rs @@ -130,14 +130,24 @@ pub struct IVerge { #[cfg(not(target_os = "windows"))] pub verge_redir_port: Option, + #[cfg(not(target_os = "windows"))] + pub verge_redir_enabled: Option, + #[cfg(target_os = "linux")] pub verge_tproxy_port: Option, + #[cfg(target_os = "linux")] + pub verge_tproxy_enabled: Option, + pub verge_mixed_port: Option, pub verge_socks_port: Option, + pub verge_socks_enabled: Option, + pub verge_port: Option, + + pub verge_http_enabled: Option, } #[derive(Default, Debug, Clone, Deserialize, Serialize)] @@ -198,11 +208,17 @@ impl IVerge { enable_random_port: Some(false), #[cfg(not(target_os = "windows"))] verge_redir_port: Some(7895), + #[cfg(not(target_os = "windows"))] + verge_redir_enabled: Some(true), #[cfg(target_os = "linux")] verge_tproxy_port: Some(7896), + #[cfg(target_os = "linux")] + verge_tproxy_enabled: Some(true), verge_mixed_port: Some(7897), verge_socks_port: Some(7898), + verge_socks_enabled: Some(true), verge_port: Some(7899), + verge_http_enabled: Some(true), enable_proxy_guard: Some(false), proxy_guard_duration: Some(30), auto_close_connection: Some(true), @@ -251,11 +267,17 @@ impl IVerge { patch!(enable_random_port); #[cfg(not(target_os = "windows"))] patch!(verge_redir_port); + #[cfg(not(target_os = "windows"))] + patch!(verge_redir_enabled); #[cfg(target_os = "linux")] patch!(verge_tproxy_port); + #[cfg(target_os = "linux")] + patch!(verge_tproxy_enabled); patch!(verge_mixed_port); patch!(verge_socks_port); + patch!(verge_socks_enabled); patch!(verge_port); + patch!(verge_http_enabled); patch!(enable_system_proxy); patch!(enable_proxy_guard); patch!(system_proxy_bypass); diff --git a/src-tauri/src/enhance/mod.rs b/src-tauri/src/enhance/mod.rs index c2c90d6..bf5fd01 100644 --- a/src-tauri/src/enhance/mod.rs +++ b/src-tauri/src/enhance/mod.rs @@ -22,15 +22,29 @@ pub fn enhance() -> (Mapping, Vec, HashMap) { // config.yaml 的订阅 let clash_config = { Config::clash().latest().0.clone() }; - let (clash_core, enable_tun, enable_builtin) = { + let (clash_core, enable_tun, enable_builtin, socks_enabled, http_enabled) = { let verge = Config::verge(); let verge = verge.latest(); ( verge.clash_core.clone(), verge.enable_tun_mode.unwrap_or(false), verge.enable_builtin_enhanced.unwrap_or(true), + verge.verge_socks_enabled.unwrap_or(true), + verge.verge_http_enabled.unwrap_or(true), ) }; + #[cfg(not(target_os = "windows"))] + let redir_enabled = { + let verge = Config::verge(); + let verge = verge.latest(); + verge.verge_redir_enabled.unwrap_or(true) + }; + #[cfg(target_os = "linux")] + let tproxy_enabled = { + let verge = Config::verge(); + let verge = verge.latest(); + verge.verge_tproxy_enabled.unwrap_or(true) + }; // 从profiles里拿东西 let (mut config, chain) = { @@ -88,6 +102,28 @@ pub fn enhance() -> (Mapping, Vec, HashMap) { } config.insert("tun".into(), tun.into()); } else { + if key.as_str() == Some("socks-port") && !socks_enabled { + config.remove("socks-port"); + continue; + } + if key.as_str() == Some("port") && !http_enabled { + config.remove("port"); + continue; + } + #[cfg(not(target_os = "windows"))] + { + if key.as_str() == Some("redir-port") && !redir_enabled { + config.remove("redir-port"); + continue; + } + } + #[cfg(target_os = "linux")] + { + if key.as_str() == Some("tproxy-port") && !tproxy_enabled { + config.remove("tproxy-port"); + continue; + } + } config.insert(key, value); } } diff --git a/src-tauri/src/feat.rs b/src-tauri/src/feat.rs index 25aa5ed..23c3189 100644 --- a/src-tauri/src/feat.rs +++ b/src-tauri/src/feat.rs @@ -183,7 +183,12 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> { let common_tray_icon = patch.common_tray_icon; let sysproxy_tray_icon = patch.sysproxy_tray_icon; let tun_tray_icon = patch.tun_tray_icon; - + #[cfg(not(target_os = "windows"))] + let redir_enabled = patch.verge_redir_enabled; + #[cfg(target_os = "linux")] + let tproxy_enabled = patch.verge_tproxy_enabled; + let socks_enabled = patch.verge_socks_enabled; + let http_enabled = patch.verge_http_enabled; match { let service_mode = patch.enable_service_mode; @@ -195,7 +200,20 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> { } else if tun_mode.is_some() { update_core_config().await?; } - + #[cfg(not(target_os = "windows"))] + if redir_enabled.is_some() { + Config::generate()?; + CoreManager::global().run_core().await?; + } + #[cfg(target_os = "linux")] + if tproxy_enabled.is_some() { + Config::generate()?; + CoreManager::global().run_core().await?; + } + if socks_enabled.is_some() || http_enabled.is_some() { + Config::generate()?; + CoreManager::global().run_core().await?; + } if auto_launch.is_some() { sysopt::Sysopt::global().update_launch()?; } diff --git a/src/components/setting/mods/clash-port-viewer.tsx b/src/components/setting/mods/clash-port-viewer.tsx index 70b1f4b..d2cc6a4 100644 --- a/src/components/setting/mods/clash-port-viewer.tsx +++ b/src/components/setting/mods/clash-port-viewer.tsx @@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next"; import { useLockFn } from "ahooks"; import { List, ListItem, ListItemText, TextField } from "@mui/material"; import { useClashInfo } from "@/hooks/use-clash"; -import { BaseDialog, DialogRef, Notice } from "@/components/base"; +import { BaseDialog, DialogRef, Notice, Switch } from "@/components/base"; import { useVerge } from "@/hooks/use-verge"; import getSystem from "@/utils/get-system"; const OS = getSystem(); @@ -18,26 +18,42 @@ export const ClashPortViewer = forwardRef((props, ref) => { const [redirPort, setRedirPort] = useState( verge?.verge_redir_port ?? clashInfo?.redir_port ?? 7895 ); + const [redirEnabled, setRedirEnabled] = useState( + verge?.verge_redir_enabled ?? true + ); const [tproxyPort, setTproxyPort] = useState( verge?.verge_tproxy_port ?? clashInfo?.tproxy_port ?? 7896 ); + const [tproxyEnabled, setTproxyEnabled] = useState( + verge?.verge_tproxy_enabled ?? true + ); const [mixedPort, setMixedPort] = useState( verge?.verge_mixed_port ?? clashInfo?.mixed_port ?? 7897 ); const [socksPort, setSocksPort] = useState( verge?.verge_socks_port ?? clashInfo?.socks_port ?? 7898 ); + const [socksEnabled, setSocksEnabled] = useState( + verge?.verge_socks_enabled ?? true + ); const [port, setPort] = useState( verge?.verge_port ?? clashInfo?.port ?? 7899 ); + const [httpEnabled, setHttpEnabled] = useState( + verge?.verge_http_enabled ?? true + ); useImperativeHandle(ref, () => ({ open: () => { if (verge?.verge_redir_port) setRedirPort(verge?.verge_redir_port); + setRedirEnabled(verge?.verge_redir_enabled ?? true); if (verge?.verge_tproxy_port) setTproxyPort(verge?.verge_tproxy_port); + setTproxyEnabled(verge?.verge_tproxy_enabled ?? true); if (verge?.verge_mixed_port) setMixedPort(verge?.verge_mixed_port); if (verge?.verge_socks_port) setSocksPort(verge?.verge_socks_port); + setSocksEnabled(verge?.verge_socks_enabled ?? true); if (verge?.verge_port) setPort(verge?.verge_port); + setHttpEnabled(verge?.verge_http_enabled ?? true); setOpen(true); }, close: () => setOpen(false), @@ -49,7 +65,11 @@ export const ClashPortViewer = forwardRef((props, ref) => { tproxyPort === verge?.verge_tproxy_port && mixedPort === verge?.verge_mixed_port && socksPort === verge?.verge_socks_port && - port === verge?.verge_port + port === verge?.verge_port && + redirEnabled === verge?.verge_redir_enabled && + tproxyEnabled === verge?.verge_tproxy_enabled && + socksEnabled === verge?.verge_socks_enabled && + httpEnabled === verge?.verge_http_enabled ) { setOpen(false); return; @@ -77,10 +97,12 @@ export const ClashPortViewer = forwardRef((props, ref) => { if (OS !== "windows") { await patchInfo({ "redir-port": redirPort }); await patchVerge({ verge_redir_port: redirPort }); + await patchVerge({ verge_redir_enabled: redirEnabled }); } if (OS === "linux") { await patchInfo({ "tproxy-port": tproxyPort }); await patchVerge({ verge_tproxy_port: tproxyPort }); + await patchVerge({ verge_tproxy_enabled: tproxyEnabled }); } await patchInfo({ "mixed-port": mixedPort }); await patchInfo({ "socks-port": socksPort }); @@ -88,6 +110,8 @@ export const ClashPortViewer = forwardRef((props, ref) => { await patchVerge({ verge_mixed_port: mixedPort }); await patchVerge({ verge_socks_port: socksPort }); await patchVerge({ verge_port: port }); + await patchVerge({ verge_socks_enabled: socksEnabled }); + await patchVerge({ verge_http_enabled: httpEnabled }); setOpen(false); Notice.success("Change Clash port successfully!", 1000); } catch (err: any) { @@ -107,35 +131,6 @@ export const ClashPortViewer = forwardRef((props, ref) => { onOk={onSave} > - {OS !== "windows" && ( - - - - setRedirPort(+e.target.value?.replace(/\D+/, "").slice(0, 5)) - } - /> - - )} - {OS === "linux" && ( - - - - setTproxyPort(+e.target.value?.replace(/\D+/, "").slice(0, 5)) - } - /> - - )} - ((props, ref) => { onChange={(e) => setSocksPort(+e.target.value?.replace(/\D+/, "").slice(0, 5)) } + InputProps={{ + sx: { pr: 1 }, + endAdornment: ( + { + setSocksEnabled(c); + }} + /> + ), + }} /> @@ -170,8 +176,69 @@ export const ClashPortViewer = forwardRef((props, ref) => { onChange={(e) => setPort(+e.target.value?.replace(/\D+/, "").slice(0, 5)) } + InputProps={{ + sx: { pr: 1 }, + endAdornment: ( + { + setHttpEnabled(c); + }} + /> + ), + }} /> + {OS !== "windows" && ( + + + + setRedirPort(+e.target.value?.replace(/\D+/, "").slice(0, 5)) + } + InputProps={{ + sx: { pr: 1 }, + endAdornment: ( + { + setRedirEnabled(c); + }} + /> + ), + }} + /> + + )} + {OS === "linux" && ( + + + + setTproxyPort(+e.target.value?.replace(/\D+/, "").slice(0, 5)) + } + InputProps={{ + sx: { pr: 1 }, + endAdornment: ( + { + setTproxyEnabled(c); + }} + /> + ), + }} + /> + + )} ); diff --git a/src/services/types.d.ts b/src/services/types.d.ts index 0d9537e..ea91f82 100644 --- a/src/services/types.d.ts +++ b/src/services/types.d.ts @@ -221,6 +221,10 @@ interface IVergeConfig { verge_redir_port?: number; verge_tproxy_port?: number; verge_port?: number; + verge_redir_enabled?: boolean; + verge_tproxy_enabled?: boolean; + verge_socks_enabled?: boolean; + verge_http_enabled?: boolean; enable_proxy_guard?: boolean; proxy_guard_duration?: number; system_proxy_bypass?: string;