ソースを参照

revert: Support both registry and api for windows sysproxy

MystiPanda 1 年間 前
コミット
ebc63f479a

+ 9 - 9
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",
 ]

+ 1 - 1
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]

+ 0 - 5
src-tauri/src/config/verge.rs

@@ -58,9 +58,6 @@ pub struct IVerge {
     /// set system proxy bypass
     pub system_proxy_bypass: Option<String>,
 
-    /// set system proxy method
-    pub system_proxy_registry_mode: Option<bool>,
-
     /// proxy guard duration
     pub proxy_guard_duration: Option<u64>,
 
@@ -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);

+ 8 - 64
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;

+ 1 - 32
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<DialogRef>((props, ref) => {
   const { t } = useTranslation();
 
@@ -35,14 +31,12 @@ export const SysproxyViewer = forwardRef<DialogRef>((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<DialogRef>((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<DialogRef>((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<DialogRef>((props, ref) => {
     <BaseDialog
       open={open}
       title={t("System Proxy Setting")}
-      contentSx={{ width: 450, maxHeight: 500 }}
+      contentSx={{ width: 450, maxHeight: 300 }}
       okBtn={t("Save")}
       cancelBtn={t("Cancel")}
       onClose={() => setOpen(false)}
@@ -144,27 +134,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
             }
           />
         </ListItem>
-        {OS === "windows" && (
-          <Tooltip
-            title={
-              enabled
-                ? t("Please disable the system proxy")
-                : t("Using the registry instead of Windows API")
-            }
-          >
-            <ListItem sx={{ padding: "5px 2px" }}>
-              <ListItemText primary={t("Use Registry")} />
-              <Switch
-                edge="end"
-                disabled={enabled}
-                checked={value.registryMode}
-                onChange={(_, e) =>
-                  setValue((v) => ({ ...v, registryMode: e }))
-                }
-              />
-            </ListItem>
-          </Tooltip>
-        )}
       </List>
 
       <Box sx={{ mt: 2.5 }}>

+ 1 - 4
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"
 }

+ 1 - 4
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": "Портативная версия не поддерживает обновление внутри приложения, пожалуйста, скачайте и замените вручную"
 }

+ 1 - 4
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": "便携版不支持应用内更新,请手动下载替换"
 }

+ 0 - 1
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?: {