diff --git a/scripts/check.mjs b/scripts/check.mjs index 49ff423912..91938e6b58 100644 --- a/scripts/check.mjs +++ b/scripts/check.mjs @@ -337,6 +337,11 @@ const resolveGeoIP = () => file: "geoip.dat", downloadURL: `https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.dat`, }); +const resolveEnableLoopback = () => + resolveResource({ + file: "enableLoopback.exe", + downloadURL: `https://github.com/Kuingsmile/uwp-tool/releases/download/latest/enableLoopback.exe`, + }); const tasks = [ { name: "clash", func: () => resolveSidecar(clashBackup()), retry: 5 }, @@ -348,6 +353,12 @@ const tasks = [ { name: "mmdb", func: resolveMmdb, retry: 5 }, { name: "geosite", func: resolveGeosite, retry: 5 }, { name: "geoip", func: resolveGeoIP, retry: 5 }, + { + name: "enableLoopback", + func: resolveEnableLoopback, + retry: 5, + winOnly: true, + }, ]; async function runTask() { diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 9b1c0ec5ff..43db11dcb1 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3397,14 +3397,12 @@ checksum = "e60ef3b82994702bbe4e134d98aadca4b49ed04440148985678d415c68127666" [[package]] name = "runas" -version = "1.1.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49535b7c73aec5596ae2c44a6d8a7a8f8592e5744564c327fd4846750413d921" +checksum = "ed87390fefd18965ff20baae5aeb9913bcf82d2b59dc04c0f6d8f17f7be56ff2" dependencies = [ - "libc", - "security-framework-sys", + "cc", "which", - "windows-sys 0.48.0", ] [[package]] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 06c955d675..85bbf489d5 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -44,7 +44,7 @@ wry = { version = "0.24.3" } [target.'cfg(windows)'.dependencies] -runas = "1.1.0" +runas = "=1.0.0" deelevate = "0.2.0" winreg = { version = "0.50", features = ["transactions"] } windows-sys = { version = "0.48", features = ["Win32_System_LibraryLoader", "Win32_System_SystemInformation"] } diff --git a/src-tauri/src/cmds.rs b/src-tauri/src/cmds.rs index 4492d4143d..c60c888d6e 100644 --- a/src-tauri/src/cmds.rs +++ b/src-tauri/src/cmds.rs @@ -229,6 +229,17 @@ pub fn open_web_url(url: String) -> CmdResult<()> { wrap_err!(open::that(url)) } +#[cfg(windows)] +pub mod uwp { + use super::*; + use crate::core::win_uwp; + + #[tauri::command] + pub async fn invoke_uwp_tool() -> CmdResult { + wrap_err!(win_uwp::invoke_uwptools().await) + } +} + #[cfg(windows)] pub mod service { use super::*; @@ -267,3 +278,13 @@ pub mod service { Ok(()) } } + +#[cfg(not(windows))] +pub mod uwp { + use super::*; + + #[tauri::command] + pub async fn invoke_uwp_tool() -> CmdResult { + Ok(()) + } +} \ No newline at end of file diff --git a/src-tauri/src/core/mod.rs b/src-tauri/src/core/mod.rs index 4221721f1e..80378f53e2 100644 --- a/src-tauri/src/core/mod.rs +++ b/src-tauri/src/core/mod.rs @@ -8,5 +8,6 @@ pub mod sysopt; pub mod timer; pub mod tray; pub mod win_service; +pub mod win_uwp; pub use self::core::*; diff --git a/src-tauri/src/core/win_uwp.rs b/src-tauri/src/core/win_uwp.rs new file mode 100644 index 0000000000..353005b7f4 --- /dev/null +++ b/src-tauri/src/core/win_uwp.rs @@ -0,0 +1,27 @@ +#![cfg(target_os = "windows")] + +use crate::utils::dirs; +use anyhow::{bail, Result}; +use deelevate::{PrivilegeLevel, Token}; +use runas::Command as RunasCommand; +use std::process::Command as StdCommand; + +pub async fn invoke_uwptools() -> Result<()> { + let binary_path = dirs::service_path()?; + let tool_path = binary_path.with_file_name("enableLoopback.exe"); + + if !tool_path.exists() { + bail!("enableLoopback exe not found"); + } + + let token = Token::with_current_process()?; + let level = token.privilege_level()?; + + match level { + PrivilegeLevel::NotPrivileged => RunasCommand::new(tool_path).status()?, + _ => StdCommand::new(tool_path) + .status()?, + }; + + Ok(()) +} \ No newline at end of file diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 59903db9ce..e78a8ae9b7 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -46,6 +46,7 @@ fn main() -> std::io::Result<()> { cmds::get_runtime_yaml, cmds::get_runtime_exists, cmds::get_runtime_logs, + cmds::uwp::invoke_uwp_tool, // verge cmds::get_verge_config, cmds::patch_verge_config, diff --git a/src/components/setting/setting-clash.tsx b/src/components/setting/setting-clash.tsx index 19f77ca612..9ab6746dcd 100644 --- a/src/components/setting/setting-clash.tsx +++ b/src/components/setting/setting-clash.tsx @@ -18,6 +18,10 @@ import { ClashPortViewer } from "./mods/clash-port-viewer"; import { ControllerViewer } from "./mods/controller-viewer"; import { SettingList, SettingItem } from "./mods/setting-comp"; import { ClashCoreViewer } from "./mods/clash-core-viewer"; +import { invoke_uwp_tool } from "@/services/cmds"; +import getSystem from "@/utils/get-system"; + +const isWIN = getSystem() === "windows"; interface Props { onError: (err: Error) => void; @@ -162,6 +166,18 @@ const SettingClash = ({ onError }: Props) => { > {version} + {isWIN && ( + + + + + + )} ); }; diff --git a/src/locales/en.json b/src/locales/en.json index 542367ba27..3b56dd8fc9 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -76,6 +76,7 @@ "Auto Launch": "Auto Launch", "Silent Start": "Silent Start", "System Proxy": "System Proxy", + "Open UWP tool": "UWP工具", "System Proxy Setting": "System Proxy Setting", "Proxy Guard": "Proxy Guard", "Guard Duration": "Guard Duration", diff --git a/src/locales/ru.json b/src/locales/ru.json index dc908c5f3d..44738048d2 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -76,6 +76,7 @@ "Proxy Bypass": "Игнорирование прокси", "Current System Proxy": "Текущий системный прокси", "Theme Mode": "Режим темы", + "Open UWP tool": "Открыть UWP инструмент", "Theme Blur": "Размытие темы", "Theme Setting": "Настройка темы", "Hotkey Setting": "Настройка клавиатурных сокращений", diff --git a/src/locales/zh.json b/src/locales/zh.json index 870f22ead7..c034537029 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -76,6 +76,7 @@ "Auto Launch": "开机自启", "Silent Start": "静默启动", "System Proxy": "系统代理", + "Open UWP tool": "Open UWP tool", "System Proxy Setting": "系统代理设置", "Proxy Guard": "系统代理守卫", "Guard Duration": "代理守卫间隔", diff --git a/src/services/cmds.ts b/src/services/cmds.ts index 2bd857e164..547baa1e9d 100644 --- a/src/services/cmds.ts +++ b/src/services/cmds.ts @@ -173,3 +173,9 @@ export async function installService() { export async function uninstallService() { return invoke("uninstall_service"); } + +export async function invoke_uwp_tool() { + return invoke("invoke_uwp_tool").catch((err) => + Notice.error(err?.message || err.toString(), 1500) + ); +}