diff --git a/Changelog.md b/Changelog.md index 4bca5f200..ac3c3dd26 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,13 +11,15 @@ - 修复 macOS 开关代理时可能的卡死 - 修复修改定时自动更新后记时未及时刷新 - 修复 Linux 关闭 TUN 不立即生效 +- 修复系统代理关闭序列逻辑(防止快速退出时系统代理关闭状态没有保存) ### ✨ 新增功能 - 订阅 QR code 分享 - 新增 macOS 托盘速率显示 - 快捷键操作通知操作结果 +- 软件自动更新(后台下载,下次启动自动安装) ### 🚀 优化改进 -- 优化 macOS 读取系统代理性能 +- 优化 macOS 读取系统代理性能 \ No newline at end of file diff --git a/src-tauri/src/cmd/network.rs b/src-tauri/src/cmd/network.rs index de6dc11f6..6068ab998 100644 --- a/src-tauri/src/cmd/network.rs +++ b/src-tauri/src/cmd/network.rs @@ -1,5 +1,6 @@ use super::CmdResult; use crate::cmd::StringifyErr as _; +use crate::core::sysopt::Sysopt; use clash_verge_logging::{Type, logging}; use gethostname::gethostname; use network_interface::NetworkInterface; @@ -13,6 +14,7 @@ use tauri_plugin_clash_verge_sysinfo; pub async fn get_sys_proxy() -> CmdResult { logging!(debug, Type::Network, "异步获取系统代理配置"); + Sysopt::global().wait_idle().await; let sys_proxy = Sysproxy::get_system_proxy().stringify_err()?; let Sysproxy { ref host, @@ -40,6 +42,7 @@ pub async fn get_sys_proxy() -> CmdResult { /// 获取自动代理配置 #[tauri::command] pub async fn get_auto_proxy() -> CmdResult { + Sysopt::global().wait_idle().await; let auto_proxy = Autoproxy::get_auto_proxy().stringify_err()?; let Autoproxy { ref enable, ref url } = auto_proxy; diff --git a/src-tauri/src/core/sysopt.rs b/src-tauri/src/core/sysopt.rs index b3d0a7a98..163c7adca 100644 --- a/src-tauri/src/core/sysopt.rs +++ b/src-tauri/src/core/sysopt.rs @@ -106,6 +106,14 @@ impl Sysopt { } } + /// Wait for any in-progress `update_sysproxy` to finish, so that a + /// subsequent read of OS-level sysproxy state sees a fully applied + /// configuration instead of a partially-applied one (e.g. SOCKS already + /// disabled but HTTP still enabled mid-transition). + pub async fn wait_idle(&self) { + let _ = self.update_lock.lock().await; + } + /// init the sysproxy pub async fn update_sysproxy(&self) -> Result<()> { let _lock = self.update_lock.lock().await; diff --git a/src/hooks/use-system-proxy-state.ts b/src/hooks/use-system-proxy-state.ts index 40307e064..8b62c4aec 100644 --- a/src/hooks/use-system-proxy-state.ts +++ b/src/hooks/use-system-proxy-state.ts @@ -57,10 +57,10 @@ export const useSystemProxyState = () => { while (pendingRef.current !== null) { const target = pendingRef.current pendingRef.current = null + await patchVerge({ enable_system_proxy: target }) if (!target && verge?.auto_close_connection) { await closeAllConnections().catch(() => {}) } - await patchVerge({ enable_system_proxy: target }) } } finally { busyRef.current = false