From 1bf445ddcc6891bc5847b2c4b00be9b3eb15e729 Mon Sep 17 00:00:00 2001 From: Slinetrac Date: Sun, 22 Feb 2026 21:09:47 +0800 Subject: [PATCH] fix(tun): avoid service IPC startup race on Windows (#6340) * fix(tun): avoid service IPC startup race on Windows * docs: Changelog.md * style: prettier --- Changelog.md | 2 ++ docs/Changelog.history.md | 1 - package.json | 2 +- src-tauri/src/core/manager/lifecycle.rs | 8 +++++++- src-tauri/tauri.conf.json | 25 ++++++------------------- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/Changelog.md b/Changelog.md index 3007b3b6b..c11f366ca 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,8 @@ ### 🐞 修复问题 +- 修复 Windows 管理员身份运行时开关 TUN 模式异常 +
✨ 新增功能 diff --git a/docs/Changelog.history.md b/docs/Changelog.history.md index 036e29b6b..c3e7bfe54 100644 --- a/docs/Changelog.history.md +++ b/docs/Changelog.history.md @@ -42,7 +42,6 @@
- ## v2.4.5 - **Mihomo(Meta) 内核升级至 v1.19.19** diff --git a/package.json b/package.json index 7fb532712..7578189be 100644 --- a/package.json +++ b/package.json @@ -141,4 +141,4 @@ "unrs-resolver" ] } -} \ No newline at end of file +} diff --git a/src-tauri/src/core/manager/lifecycle.rs b/src-tauri/src/core/manager/lifecycle.rs index 0298773a8..789103492 100644 --- a/src-tauri/src/core/manager/lifecycle.rs +++ b/src-tauri/src/core/manager/lifecycle.rs @@ -83,7 +83,7 @@ impl CoreManager { #[cfg(target_os = "windows")] async fn wait_for_service_if_needed(&self) { - use crate::{config::Config, constants::timing}; + use crate::{config::Config, constants::timing, core::service}; use backoff::{Error as BackoffError, ExponentialBackoff}; let needs_service = Config::verge().await.latest_arc().enable_tun_mode.unwrap_or(false); @@ -108,6 +108,12 @@ impl CoreManager { return Ok(()); } + // If the service IPC path is not ready yet, treat it as transient and retry. + // Running init/refresh too early can mark service state unavailable and break later config reloads. + if !service::is_service_ipc_path_exists() { + return Err(BackoffError::transient(anyhow::anyhow!("Service IPC not ready"))); + } + manager.init().await.map_err(BackoffError::transient)?; let _ = manager.refresh().await; diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index b16f86db4..2a8e54689 100755 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -11,14 +11,9 @@ "icons/icon.icns", "icons/icon.ico" ], - "resources": [ - "resources" - ], + "resources": ["resources"], "publisher": "Clash Verge Rev", - "externalBin": [ - "sidecar/verge-mihomo", - "sidecar/verge-mihomo-alpha" - ], + "externalBin": ["sidecar/verge-mihomo", "sidecar/verge-mihomo-alpha"], "copyright": "GNU General Public License v3.0", "category": "DeveloperTool", "shortDescription": "Clash Verge Rev", @@ -47,29 +42,21 @@ }, "deep-link": { "desktop": { - "schemes": [ - "clash", - "clash-verge" - ] + "schemes": ["clash", "clash-verge"] } } }, "app": { "security": { - "capabilities": [ - "desktop-capability", - "migrated" - ], + "capabilities": ["desktop-capability", "migrated"], "assetProtocol": { "enable": true, "scope": { - "allow": [ - "**" - ], + "allow": ["**"], "requireLiteralLeadingDot": false } }, "csp": null } } -} \ No newline at end of file +}