From ef9bbaca1973f3da0b14268f4334efb135e863df Mon Sep 17 00:00:00 2001 From: MystiPanda Date: Sat, 20 Jan 2024 12:16:46 +0800 Subject: [PATCH] revert: Support both registry and api for windows sysproxy --- src-tauri/Cargo.lock | 18 ++--- src-tauri/Cargo.toml | 2 +- src-tauri/src/config/verge.rs | 5 -- src-tauri/src/core/sysopt.rs | 72 +++---------------- .../setting/mods/sysproxy-viewer.tsx | 33 +-------- src/locales/en.json | 5 +- src/locales/ru.json | 5 +- src/locales/zh.json | 5 +- src/services/types.d.ts | 1 - 9 files changed, 22 insertions(+), 124 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 8bc3fb51..d9643afa 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2962,9 +2962,9 @@ dependencies = [ [[package]] name = "openssl" -version = "0.10.62" +version = "0.10.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cde4d2d9200ad5909f8dac647e29482e07c3a35de8a13fce7c9c7747ad9f671" +checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8" dependencies = [ "bitflags 2.4.2", "cfg-if", @@ -2994,9 +2994,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.98" +version = "0.9.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1665caf8ab2dc9aef43d1c0023bd904633a6a05cb30b0ad59bec2ae986e57a7" +checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae" dependencies = [ "cc", "libc", @@ -4303,9 +4303,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.12.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "smol" @@ -4477,7 +4477,7 @@ dependencies = [ [[package]] name = "sysproxy" version = "0.3.0" -source = "git+https://github.com/clash-verge-rev/sysproxy-rs?branch=main#79390614ede8252158bf775ffaabbec04d8a4359" +source = "git+https://github.com/zzzgydi/sysproxy-rs?branch=main#95a2ba9b609e99dcba21276b2db96c499c06836b" dependencies = [ "interfaces", "iptools", @@ -5392,9 +5392,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "uuid" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" +checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" dependencies = [ "getrandom 0.2.12", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 720c5bbb..94f4c400 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -38,7 +38,7 @@ window-shadows = { version = "0.2" } tokio = { version = "1", features = ["full"] } serde = { version = "1.0", features = ["derive"] } reqwest = { version = "0.11", features = ["json", "rustls-tls"] } -sysproxy = { git="https://github.com/clash-verge-rev/sysproxy-rs", branch = "main" } +sysproxy = { git="https://github.com/zzzgydi/sysproxy-rs", branch = "main" } tauri = { version = "1.5", features = [ "dialog-open", "notification-all", "icon-png", "clipboard-all", "global-shortcut-all", "process-all", "shell-all", "system-tray", "updater", "window-all"] } [target.'cfg(windows)'.dependencies] diff --git a/src-tauri/src/config/verge.rs b/src-tauri/src/config/verge.rs index 3d18157f..f67a35af 100644 --- a/src-tauri/src/config/verge.rs +++ b/src-tauri/src/config/verge.rs @@ -58,9 +58,6 @@ pub struct IVerge { /// set system proxy bypass pub system_proxy_bypass: Option, - /// set system proxy method - pub system_proxy_registry_mode: Option, - /// proxy guard duration pub proxy_guard_duration: Option, @@ -161,7 +158,6 @@ impl IVerge { enable_auto_launch: Some(false), enable_silent_start: Some(false), enable_system_proxy: Some(false), - system_proxy_registry_mode: Some(false), enable_random_port: Some(false), verge_mixed_port: Some(7897), enable_proxy_guard: Some(false), @@ -209,7 +205,6 @@ impl IVerge { patch!(enable_system_proxy); patch!(enable_proxy_guard); patch!(system_proxy_bypass); - patch!(system_proxy_registry_mode); patch!(proxy_guard_duration); patch!(theme_setting); diff --git a/src-tauri/src/core/sysopt.rs b/src-tauri/src/core/sysopt.rs index 9f00c7b9..e993a04d 100644 --- a/src-tauri/src/core/sysopt.rs +++ b/src-tauri/src/core/sysopt.rs @@ -58,12 +58,6 @@ impl Sysopt { ) }; - let registry_mode = { - let verge = Config::verge(); - let verge = verge.latest(); - verge.system_proxy_registry_mode.unwrap_or(false) - }; - let current = Sysproxy { enable, host: String::from("127.0.0.1"), @@ -73,15 +67,7 @@ impl Sysopt { if enable { let old = Sysproxy::get_system_proxy().ok(); - - if registry_mode { - #[cfg(windows)] - current.set_system_proxy_with_registry()?; - #[cfg(not(windows))] - current.set_system_proxy()?; - } else { - current.set_system_proxy()?; - } + current.set_system_proxy()?; *self.old_sysproxy.lock() = old; *self.cur_sysproxy.lock() = Some(current); @@ -111,13 +97,6 @@ impl Sysopt { verge.system_proxy_bypass.clone(), ) }; - - let registry_mode = { - let verge = Config::verge(); - let verge = verge.latest(); - verge.system_proxy_registry_mode.unwrap_or(false) - }; - let mut sysproxy = cur_sysproxy.take().unwrap(); sysproxy.enable = enable; @@ -129,14 +108,7 @@ impl Sysopt { .unwrap_or(Config::clash().data().get_mixed_port()); sysproxy.port = port; - if registry_mode { - #[cfg(windows)] - sysproxy.set_system_proxy_with_registry()?; - #[cfg(not(windows))] - sysproxy.set_system_proxy()?; - } else { - sysproxy.set_system_proxy()?; - } + sysproxy.set_system_proxy()?; *cur_sysproxy = Some(sysproxy); Ok(()) @@ -146,11 +118,7 @@ impl Sysopt { pub fn reset_sysproxy(&self) -> Result<()> { let mut cur_sysproxy = self.cur_sysproxy.lock(); let mut old_sysproxy = self.old_sysproxy.lock(); - let registry_mode = { - let verge = Config::verge(); - let verge = verge.latest(); - verge.system_proxy_registry_mode.unwrap_or(false) - }; + let cur_sysproxy = cur_sysproxy.take(); if let Some(mut old) = old_sysproxy.take() { @@ -165,26 +133,12 @@ impl Sysopt { log::info!(target: "app", "reset proxy to the original proxy"); } - if registry_mode { - #[cfg(windows)] - old.set_system_proxy_with_registry()?; - #[cfg(not(windows))] - old.set_system_proxy()?; - } else { - old.set_system_proxy()?; - } + old.set_system_proxy()?; } else if let Some(mut cur @ Sysproxy { enable: true, .. }) = cur_sysproxy { // 没有原代理,就按现在的代理设置disable即可 log::info!(target: "app", "reset proxy by disabling the current proxy"); cur.enable = false; - if registry_mode { - #[cfg(windows)] - cur.set_system_proxy_with_registry()?; - #[cfg(not(windows))] - cur.set_system_proxy()?; - } else { - cur.set_system_proxy()?; - } + cur.set_system_proxy()?; } else { log::info!(target: "app", "reset proxy with no action"); } @@ -303,11 +257,7 @@ impl Sysopt { use tokio::time::{sleep, Duration}; let guard_state = self.guard_state.clone(); - let registry_mode = { - let verge = Config::verge(); - let verge = verge.latest(); - verge.system_proxy_registry_mode.unwrap_or(false) - }; + tauri::async_runtime::spawn(async move { // if it is running, exit let mut state = guard_state.lock().await; @@ -357,14 +307,8 @@ impl Sysopt { port, bypass: bypass.unwrap_or(DEFAULT_BYPASS.into()), }; - if registry_mode { - #[cfg(windows)] - log_err!(sysproxy.set_system_proxy_with_registry()); - #[cfg(not(windows))] - log_err!(sysproxy.set_system_proxy()); - } else { - log_err!(sysproxy.set_system_proxy()); - } + + log_err!(sysproxy.set_system_proxy()); } let mut state = guard_state.lock().await; diff --git a/src/components/setting/mods/sysproxy-viewer.tsx b/src/components/setting/mods/sysproxy-viewer.tsx index 0cca2b4d..8e47d005 100644 --- a/src/components/setting/mods/sysproxy-viewer.tsx +++ b/src/components/setting/mods/sysproxy-viewer.tsx @@ -11,15 +11,11 @@ import { Switch, TextField, Typography, - Tooltip, } from "@mui/material"; -import getSystem from "@/utils/get-system"; import { useVerge } from "@/hooks/use-verge"; import { getSystemProxy } from "@/services/cmds"; import { BaseDialog, DialogRef, Notice } from "@/components/base"; -const OS = getSystem(); - export const SysproxyViewer = forwardRef((props, ref) => { const { t } = useTranslation(); @@ -35,14 +31,12 @@ export const SysproxyViewer = forwardRef((props, ref) => { enable_proxy_guard, system_proxy_bypass, proxy_guard_duration, - system_proxy_registry_mode, } = verge ?? {}; const [value, setValue] = useState({ guard: enable_proxy_guard, bypass: system_proxy_bypass, duration: proxy_guard_duration ?? 10, - registryMode: system_proxy_registry_mode, }); useImperativeHandle(ref, () => ({ @@ -52,7 +46,6 @@ export const SysproxyViewer = forwardRef((props, ref) => { guard: enable_proxy_guard, bypass: system_proxy_bypass, duration: proxy_guard_duration ?? 10, - registryMode: system_proxy_registry_mode, }); getSystemProxy().then((p) => setSysproxy(p)); }, @@ -76,9 +69,6 @@ export const SysproxyViewer = forwardRef((props, ref) => { if (value.bypass !== system_proxy_bypass) { patch.system_proxy_bypass = value.bypass; } - if (value.registryMode !== system_proxy_registry_mode) { - patch.system_proxy_registry_mode = value.registryMode; - } try { await patchVerge(patch); @@ -92,7 +82,7 @@ export const SysproxyViewer = forwardRef((props, ref) => { setOpen(false)} @@ -144,27 +134,6 @@ export const SysproxyViewer = forwardRef((props, ref) => { } /> - {OS === "windows" && ( - - - - - setValue((v) => ({ ...v, registryMode: e })) - } - /> - - - )} diff --git a/src/locales/en.json b/src/locales/en.json index d9b75550..d07d93e6 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -93,7 +93,6 @@ "Proxy Guard": "Proxy Guard", "Guard Duration": "Guard Duration", "Proxy Bypass": "Proxy Bypass", - "Use Registry": "Use Registry", "Enable status": "Enable status", "Server Addr": "Server Addr", "Bypass": "Bypass", @@ -160,7 +159,5 @@ "Retain 30 Days": "Retain 30 Days", "Retain 90 Days": "Retain 90 Days", - "Portable Updater Error": "The portable version does not support in-app updates. Please manually download and replace it", - "Please disable the system proxy": "Please disable the system proxy", - "Using the registry instead of Windows API": "Using the registry instead of Windows API" + "Portable Updater Error": "The portable version does not support in-app updates. Please manually download and replace it" } diff --git a/src/locales/ru.json b/src/locales/ru.json index 39cf0045..74b0a7c0 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -88,7 +88,6 @@ "Proxy Guard": "Защита прокси", "Guard Duration": "Период защиты", "Proxy Bypass": "Игнорирование прокси", - "Use Registry": "Использование реестра", "Current System Proxy": "Текущий системный прокси", "Theme Mode": "Режим темы", "Tray Click Event": "Событие щелчка в лотке", @@ -131,7 +130,5 @@ "enable_tun_mode": "Включить режим туннеля", "disable_tun_mode": "Отключить режим туннеля", - "Portable Updater Error": "Портативная версия не поддерживает обновление внутри приложения, пожалуйста, скачайте и замените вручную", - "Please disable the system proxy": "Пожалуйста, отключите системный прокси", - "Using the registry instead of Windows API": "Использование реестра вместо Windows API" + "Portable Updater Error": "Портативная версия не поддерживает обновление внутри приложения, пожалуйста, скачайте и замените вручную" } diff --git a/src/locales/zh.json b/src/locales/zh.json index da9fc251..f30ecf3e 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -93,7 +93,6 @@ "Proxy Guard": "系统代理守卫", "Guard Duration": "代理守卫间隔", "Proxy Bypass": "代理绕过", - "Use Registry": "使用注册表", "Current System Proxy": "当前系统代理", "Enable status": "开启状态:", "Server Addr": "服务地址:", @@ -160,7 +159,5 @@ "Retain 30 Days": "保留30天", "Retain 90 Days": "保留90天", - "Portable Updater Error": "便携版不支持应用内更新,请手动下载替换", - "Please disable the system proxy": "请先关闭系统代理", - "Using the registry instead of Windows API": "使用注册表替代Windows API" + "Portable Updater Error": "便携版不支持应用内更新,请手动下载替换" } diff --git a/src/services/types.d.ts b/src/services/types.d.ts index c437cb1a..abcb818b 100644 --- a/src/services/types.d.ts +++ b/src/services/types.d.ts @@ -199,7 +199,6 @@ interface IVergeConfig { enable_proxy_guard?: boolean; proxy_guard_duration?: number; system_proxy_bypass?: string; - system_proxy_registry_mode?: boolean; web_ui_list?: string[]; hotkeys?: string[]; theme_setting?: {