From d032950dfb3005711941448e0dddae751ab2310d Mon Sep 17 00:00:00 2001 From: nessi Date: Wed, 18 Mar 2026 09:56:42 +0100 Subject: [PATCH] refactor: replace metrics-based tunnel status check with direct status command in is_active function Replace metrics query in is_active with direct tunnel_backend status command call to avoid unnecessary metrics overhead when only checking tunnel state. Parse status command stdout and compare against "active" string case-insensitively. Add Windows CREATE_NO_WINDOW flag to status command execution. --- desktop-client/src-tauri/src/tunnel_manager.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/desktop-client/src-tauri/src/tunnel_manager.rs b/desktop-client/src-tauri/src/tunnel_manager.rs index 8dde6af..79b3692 100644 --- a/desktop-client/src-tauri/src/tunnel_manager.rs +++ b/desktop-client/src-tauri/src/tunnel_manager.rs @@ -57,7 +57,21 @@ pub fn disconnect(app: &AppHandle, profile_path: &Path) -> Result<(), String> { } pub fn is_active(app: &AppHandle, profile_path: &Path) -> Result { - Ok(metrics(app, profile_path)?.active) + let backend = bundled_backend(app)?; + let mut command = Command::new(backend); + command.arg("status").arg("--profile").arg(profile_path); + #[cfg(target_os = "windows")] + command.creation_flags(CREATE_NO_WINDOW); + let output = command + .output() + .map_err(|err| format!("Unable to query embedded tunnel backend status: {}", err))?; + + if !output.status.success() { + return Err(format_helper_error("status", &output)); + } + + let stdout = String::from_utf8_lossy(&output.stdout); + Ok(stdout.trim().eq_ignore_ascii_case("active")) } pub fn metrics(app: &AppHandle, profile_path: &Path) -> Result {