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.
This commit is contained in:
2026-03-18 09:56:42 +01:00
parent 3d70655cfa
commit d032950dfb

View File

@@ -57,7 +57,21 @@ pub fn disconnect(app: &AppHandle, profile_path: &Path) -> Result<(), String> {
} }
pub fn is_active(app: &AppHandle, profile_path: &Path) -> Result<bool, String> { pub fn is_active(app: &AppHandle, profile_path: &Path) -> Result<bool, String> {
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<TunnelMetrics, String> { pub fn metrics(app: &AppHandle, profile_path: &Path) -> Result<TunnelMetrics, String> {