revert: Support both registry and api for windows sysproxy

This commit is contained in:
MystiPanda 2024-01-20 12:16:46 +08:00
parent 02d89072bc
commit ef9bbaca19
9 changed files with 22 additions and 124 deletions

18
src-tauri/Cargo.lock generated
View File

@ -2962,9 +2962,9 @@ dependencies = [
[[package]] [[package]]
name = "openssl" name = "openssl"
version = "0.10.62" version = "0.10.63"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cde4d2d9200ad5909f8dac647e29482e07c3a35de8a13fce7c9c7747ad9f671" checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8"
dependencies = [ dependencies = [
"bitflags 2.4.2", "bitflags 2.4.2",
"cfg-if", "cfg-if",
@ -2994,9 +2994,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]] [[package]]
name = "openssl-sys" name = "openssl-sys"
version = "0.9.98" version = "0.9.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1665caf8ab2dc9aef43d1c0023bd904633a6a05cb30b0ad59bec2ae986e57a7" checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae"
dependencies = [ dependencies = [
"cc", "cc",
"libc", "libc",
@ -4303,9 +4303,9 @@ dependencies = [
[[package]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.12.0" version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
[[package]] [[package]]
name = "smol" name = "smol"
@ -4477,7 +4477,7 @@ dependencies = [
[[package]] [[package]]
name = "sysproxy" name = "sysproxy"
version = "0.3.0" 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 = [ dependencies = [
"interfaces", "interfaces",
"iptools", "iptools",
@ -5392,9 +5392,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "1.6.1" version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a"
dependencies = [ dependencies = [
"getrandom 0.2.12", "getrandom 0.2.12",
] ]

View File

@ -38,7 +38,7 @@ window-shadows = { version = "0.2" }
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
reqwest = { version = "0.11", features = ["json", "rustls-tls"] } 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"] } 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] [target.'cfg(windows)'.dependencies]

View File

@ -58,9 +58,6 @@ pub struct IVerge {
/// set system proxy bypass /// set system proxy bypass
pub system_proxy_bypass: Option<String>, pub system_proxy_bypass: Option<String>,
/// set system proxy method
pub system_proxy_registry_mode: Option<bool>,
/// proxy guard duration /// proxy guard duration
pub proxy_guard_duration: Option<u64>, pub proxy_guard_duration: Option<u64>,
@ -161,7 +158,6 @@ impl IVerge {
enable_auto_launch: Some(false), enable_auto_launch: Some(false),
enable_silent_start: Some(false), enable_silent_start: Some(false),
enable_system_proxy: Some(false), enable_system_proxy: Some(false),
system_proxy_registry_mode: Some(false),
enable_random_port: Some(false), enable_random_port: Some(false),
verge_mixed_port: Some(7897), verge_mixed_port: Some(7897),
enable_proxy_guard: Some(false), enable_proxy_guard: Some(false),
@ -209,7 +205,6 @@ impl IVerge {
patch!(enable_system_proxy); patch!(enable_system_proxy);
patch!(enable_proxy_guard); patch!(enable_proxy_guard);
patch!(system_proxy_bypass); patch!(system_proxy_bypass);
patch!(system_proxy_registry_mode);
patch!(proxy_guard_duration); patch!(proxy_guard_duration);
patch!(theme_setting); patch!(theme_setting);

View File

@ -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 { let current = Sysproxy {
enable, enable,
host: String::from("127.0.0.1"), host: String::from("127.0.0.1"),
@ -73,15 +67,7 @@ impl Sysopt {
if enable { if enable {
let old = Sysproxy::get_system_proxy().ok(); let old = Sysproxy::get_system_proxy().ok();
current.set_system_proxy()?;
if registry_mode {
#[cfg(windows)]
current.set_system_proxy_with_registry()?;
#[cfg(not(windows))]
current.set_system_proxy()?;
} else {
current.set_system_proxy()?;
}
*self.old_sysproxy.lock() = old; *self.old_sysproxy.lock() = old;
*self.cur_sysproxy.lock() = Some(current); *self.cur_sysproxy.lock() = Some(current);
@ -111,13 +97,6 @@ impl Sysopt {
verge.system_proxy_bypass.clone(), 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(); let mut sysproxy = cur_sysproxy.take().unwrap();
sysproxy.enable = enable; sysproxy.enable = enable;
@ -129,14 +108,7 @@ impl Sysopt {
.unwrap_or(Config::clash().data().get_mixed_port()); .unwrap_or(Config::clash().data().get_mixed_port());
sysproxy.port = port; sysproxy.port = port;
if registry_mode { sysproxy.set_system_proxy()?;
#[cfg(windows)]
sysproxy.set_system_proxy_with_registry()?;
#[cfg(not(windows))]
sysproxy.set_system_proxy()?;
} else {
sysproxy.set_system_proxy()?;
}
*cur_sysproxy = Some(sysproxy); *cur_sysproxy = Some(sysproxy);
Ok(()) Ok(())
@ -146,11 +118,7 @@ impl Sysopt {
pub fn reset_sysproxy(&self) -> Result<()> { pub fn reset_sysproxy(&self) -> Result<()> {
let mut cur_sysproxy = self.cur_sysproxy.lock(); let mut cur_sysproxy = self.cur_sysproxy.lock();
let mut old_sysproxy = self.old_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(); let cur_sysproxy = cur_sysproxy.take();
if let Some(mut old) = old_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"); log::info!(target: "app", "reset proxy to the original proxy");
} }
if registry_mode { old.set_system_proxy()?;
#[cfg(windows)]
old.set_system_proxy_with_registry()?;
#[cfg(not(windows))]
old.set_system_proxy()?;
} else {
old.set_system_proxy()?;
}
} else if let Some(mut cur @ Sysproxy { enable: true, .. }) = cur_sysproxy { } else if let Some(mut cur @ Sysproxy { enable: true, .. }) = cur_sysproxy {
// 没有原代理就按现在的代理设置disable即可 // 没有原代理就按现在的代理设置disable即可
log::info!(target: "app", "reset proxy by disabling the current proxy"); log::info!(target: "app", "reset proxy by disabling the current proxy");
cur.enable = false; cur.enable = false;
if registry_mode { cur.set_system_proxy()?;
#[cfg(windows)]
cur.set_system_proxy_with_registry()?;
#[cfg(not(windows))]
cur.set_system_proxy()?;
} else {
cur.set_system_proxy()?;
}
} else { } else {
log::info!(target: "app", "reset proxy with no action"); log::info!(target: "app", "reset proxy with no action");
} }
@ -303,11 +257,7 @@ impl Sysopt {
use tokio::time::{sleep, Duration}; use tokio::time::{sleep, Duration};
let guard_state = self.guard_state.clone(); 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 { tauri::async_runtime::spawn(async move {
// if it is running, exit // if it is running, exit
let mut state = guard_state.lock().await; let mut state = guard_state.lock().await;
@ -357,14 +307,8 @@ impl Sysopt {
port, port,
bypass: bypass.unwrap_or(DEFAULT_BYPASS.into()), bypass: bypass.unwrap_or(DEFAULT_BYPASS.into()),
}; };
if registry_mode {
#[cfg(windows)] log_err!(sysproxy.set_system_proxy());
log_err!(sysproxy.set_system_proxy_with_registry());
#[cfg(not(windows))]
log_err!(sysproxy.set_system_proxy());
} else {
log_err!(sysproxy.set_system_proxy());
}
} }
let mut state = guard_state.lock().await; let mut state = guard_state.lock().await;

View File

@ -11,15 +11,11 @@ import {
Switch, Switch,
TextField, TextField,
Typography, Typography,
Tooltip,
} from "@mui/material"; } from "@mui/material";
import getSystem from "@/utils/get-system";
import { useVerge } from "@/hooks/use-verge"; import { useVerge } from "@/hooks/use-verge";
import { getSystemProxy } from "@/services/cmds"; import { getSystemProxy } from "@/services/cmds";
import { BaseDialog, DialogRef, Notice } from "@/components/base"; import { BaseDialog, DialogRef, Notice } from "@/components/base";
const OS = getSystem();
export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => { export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation(); const { t } = useTranslation();
@ -35,14 +31,12 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
enable_proxy_guard, enable_proxy_guard,
system_proxy_bypass, system_proxy_bypass,
proxy_guard_duration, proxy_guard_duration,
system_proxy_registry_mode,
} = verge ?? {}; } = verge ?? {};
const [value, setValue] = useState({ const [value, setValue] = useState({
guard: enable_proxy_guard, guard: enable_proxy_guard,
bypass: system_proxy_bypass, bypass: system_proxy_bypass,
duration: proxy_guard_duration ?? 10, duration: proxy_guard_duration ?? 10,
registryMode: system_proxy_registry_mode,
}); });
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
@ -52,7 +46,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
guard: enable_proxy_guard, guard: enable_proxy_guard,
bypass: system_proxy_bypass, bypass: system_proxy_bypass,
duration: proxy_guard_duration ?? 10, duration: proxy_guard_duration ?? 10,
registryMode: system_proxy_registry_mode,
}); });
getSystemProxy().then((p) => setSysproxy(p)); getSystemProxy().then((p) => setSysproxy(p));
}, },
@ -76,9 +69,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
if (value.bypass !== system_proxy_bypass) { if (value.bypass !== system_proxy_bypass) {
patch.system_proxy_bypass = value.bypass; patch.system_proxy_bypass = value.bypass;
} }
if (value.registryMode !== system_proxy_registry_mode) {
patch.system_proxy_registry_mode = value.registryMode;
}
try { try {
await patchVerge(patch); await patchVerge(patch);
@ -92,7 +82,7 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
<BaseDialog <BaseDialog
open={open} open={open}
title={t("System Proxy Setting")} title={t("System Proxy Setting")}
contentSx={{ width: 450, maxHeight: 500 }} contentSx={{ width: 450, maxHeight: 300 }}
okBtn={t("Save")} okBtn={t("Save")}
cancelBtn={t("Cancel")} cancelBtn={t("Cancel")}
onClose={() => setOpen(false)} onClose={() => setOpen(false)}
@ -144,27 +134,6 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
} }
/> />
</ListItem> </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> </List>
<Box sx={{ mt: 2.5 }}> <Box sx={{ mt: 2.5 }}>

View File

@ -93,7 +93,6 @@
"Proxy Guard": "Proxy Guard", "Proxy Guard": "Proxy Guard",
"Guard Duration": "Guard Duration", "Guard Duration": "Guard Duration",
"Proxy Bypass": "Proxy Bypass", "Proxy Bypass": "Proxy Bypass",
"Use Registry": "Use Registry",
"Enable status": "Enable status", "Enable status": "Enable status",
"Server Addr": "Server Addr", "Server Addr": "Server Addr",
"Bypass": "Bypass", "Bypass": "Bypass",
@ -160,7 +159,5 @@
"Retain 30 Days": "Retain 30 Days", "Retain 30 Days": "Retain 30 Days",
"Retain 90 Days": "Retain 90 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", "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"
} }

View File

@ -88,7 +88,6 @@
"Proxy Guard": "Защита прокси", "Proxy Guard": "Защита прокси",
"Guard Duration": "Период защиты", "Guard Duration": "Период защиты",
"Proxy Bypass": "Игнорирование прокси", "Proxy Bypass": "Игнорирование прокси",
"Use Registry": "Использование реестра",
"Current System Proxy": "Текущий системный прокси", "Current System Proxy": "Текущий системный прокси",
"Theme Mode": "Режим темы", "Theme Mode": "Режим темы",
"Tray Click Event": "Событие щелчка в лотке", "Tray Click Event": "Событие щелчка в лотке",
@ -131,7 +130,5 @@
"enable_tun_mode": "Включить режим туннеля", "enable_tun_mode": "Включить режим туннеля",
"disable_tun_mode": "Отключить режим туннеля", "disable_tun_mode": "Отключить режим туннеля",
"Portable Updater Error": "Портативная версия не поддерживает обновление внутри приложения, пожалуйста, скачайте и замените вручную", "Portable Updater Error": "Портативная версия не поддерживает обновление внутри приложения, пожалуйста, скачайте и замените вручную"
"Please disable the system proxy": "Пожалуйста, отключите системный прокси",
"Using the registry instead of Windows API": "Использование реестра вместо Windows API"
} }

View File

@ -93,7 +93,6 @@
"Proxy Guard": "系统代理守卫", "Proxy Guard": "系统代理守卫",
"Guard Duration": "代理守卫间隔", "Guard Duration": "代理守卫间隔",
"Proxy Bypass": "代理绕过", "Proxy Bypass": "代理绕过",
"Use Registry": "使用注册表",
"Current System Proxy": "当前系统代理", "Current System Proxy": "当前系统代理",
"Enable status": "开启状态:", "Enable status": "开启状态:",
"Server Addr": "服务地址:", "Server Addr": "服务地址:",
@ -160,7 +159,5 @@
"Retain 30 Days": "保留30天", "Retain 30 Days": "保留30天",
"Retain 90 Days": "保留90天", "Retain 90 Days": "保留90天",
"Portable Updater Error": "便携版不支持应用内更新,请手动下载替换", "Portable Updater Error": "便携版不支持应用内更新,请手动下载替换"
"Please disable the system proxy": "请先关闭系统代理",
"Using the registry instead of Windows API": "使用注册表替代Windows API"
} }

View File

@ -199,7 +199,6 @@ interface IVergeConfig {
enable_proxy_guard?: boolean; enable_proxy_guard?: boolean;
proxy_guard_duration?: number; proxy_guard_duration?: number;
system_proxy_bypass?: string; system_proxy_bypass?: string;
system_proxy_registry_mode?: boolean;
web_ui_list?: string[]; web_ui_list?: string[];
hotkeys?: string[]; hotkeys?: string[];
theme_setting?: { theme_setting?: {