From e56a989944a443d96d9f586fa7a2f3132abfd299 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Fri, 12 Dec 2025 16:07:36 +0800 Subject: [PATCH] fix: improve service availability checks #5788 --- Cargo.lock | 24 ++++++++++++------------ src-tauri/Cargo.toml | 2 +- src-tauri/src/core/service.rs | 14 ++++++-------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6af53c014..f978326a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -147,7 +147,7 @@ dependencies = [ "objc2-foundation 0.3.2", "parking_lot", "percent-encoding", - "windows-sys 0.60.2", + "windows-sys 0.59.0", "wl-clipboard-rs", "x11rb", ] @@ -1312,8 +1312,8 @@ dependencies = [ [[package]] name = "clash_verge_service_ipc" -version = "2.0.24" -source = "git+https://github.com/clash-verge-rev/clash-verge-service-ipc#c5a557d5a9f15264697a8ac70d42946a881598d7" +version = "2.0.25" +source = "git+https://github.com/clash-verge-rev/clash-verge-service-ipc#c94cf2d5fde45d6c203c4d606dcdddfe0fc0a2fe" dependencies = [ "anyhow", "compact_str", @@ -1372,7 +1372,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" dependencies = [ "lazy_static", - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -2080,7 +2080,7 @@ dependencies = [ "libc", "option-ext", "redox_users 0.5.2", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -2353,7 +2353,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -3880,7 +3880,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" dependencies = [ "hermit-abi 0.5.2", "libc", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -4671,7 +4671,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -5165,7 +5165,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.45.0", ] [[package]] @@ -5994,7 +5994,7 @@ dependencies = [ "once_cell", "socket2 0.5.10", "tracing", - "windows-sys 0.60.2", + "windows-sys 0.59.0", ] [[package]] @@ -6557,7 +6557,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.11.0", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -8076,7 +8076,7 @@ dependencies = [ "getrandom 0.3.4", "once_cell", "rustix 1.1.2", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index d0f70a7e1..66251a95d 100755 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -94,7 +94,7 @@ tauri-plugin-devtools = { version = "2.0.1" } tauri-plugin-mihomo = { git = "https://github.com/clash-verge-rev/tauri-plugin-mihomo" } clash_verge_logger = { git = "https://github.com/clash-verge-rev/clash-verge-logger" } async-trait = "0.1.89" -clash_verge_service_ipc = { version = "2.0.24", features = [ +clash_verge_service_ipc = { version = "2.0.25", features = [ "client", ], git = "https://github.com/clash-verge-rev/clash-verge-service-ipc" } arc-swap = "1.7.1" diff --git a/src-tauri/src/core/service.rs b/src-tauri/src/core/service.rs index 305b3b290..1974473d6 100644 --- a/src-tauri/src/core/service.rs +++ b/src-tauri/src/core/service.rs @@ -469,9 +469,10 @@ pub(super) async fn stop_core_by_service() -> Result<()> { /// 检查服务是否正在运行 pub async fn is_service_available() -> Result<()> { - // Service client 当前会优先判断 IPC 文件是否存在 - // 睡一会等文件拉起服务 - tokio::time::sleep(Duration::from_millis(725)).await; + if let Err(e) = Path::metadata(clash_verge_service_ipc::IPC_PATH.as_ref()) { + logging!(warn, Type::Service, "Some issue with service IPC Path: {}", e); + return Err(e.into()); + } clash_verge_service_ipc::connect().await?; Ok(()) } @@ -480,8 +481,6 @@ pub async fn is_service_available() -> Result<()> { /// TODO 使用 tokio select 之类机制并结合 timeout 实现更优雅的等待机制,期望等待文件出现,再尝试连接 pub async fn wait_and_check_service_available(status: &mut ServiceManager) -> Result<()> { status.0 = ServiceStatus::Unavailable("Waiting for service to be available".into()); - // 过早返回可能导致 UI 侧积极尝试连接服务失败 - tokio::time::sleep(Duration::from_millis(725)).await; clash_verge_service_ipc::connect().await?; status.0 = ServiceStatus::Ready; Ok(()) @@ -498,8 +497,8 @@ impl ServiceManager { pub const fn config() -> clash_verge_service_ipc::IpcConfig { clash_verge_service_ipc::IpcConfig { - default_timeout: Duration::from_millis(60), - retry_delay: Duration::from_millis(250), + default_timeout: Duration::from_millis(100), + retry_delay: Duration::from_millis(200), max_retries: 6, } } @@ -525,7 +524,6 @@ impl ServiceManager { /// 综合服务状态检查(一次性完成所有检查) pub async fn check_service_comprehensive(&self) -> ServiceStatus { - tokio::time::sleep(Duration::from_millis(125)).await; match check_service_needs_reinstall().await { Ok(need) => { logging!(debug, Type::Service, "服务当前可用,检查是否需要重装");