From 1fdf61ca2e38f50a8be5e818fdbfd09ee0828fbc Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Mon, 26 Jan 2026 17:17:57 -0800 Subject: [PATCH] Implement server reuse logic and improve build script formatting - Added logic in main.rs to check for an existing voicebox server running on the designated port, allowing reuse of the server if found. - Enhanced the build.rs script by improving formatting and readability of the Swift library path definitions. - Updated logging to provide clearer warnings when the icon source is not found during the build process. --- tauri/src-tauri/build.rs | 33 ++++++++++++++------- tauri/src-tauri/gen/Assets.car | Bin 3847048 -> 3847048 bytes tauri/src-tauri/src/main.rs | 51 +++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/tauri/src-tauri/build.rs b/tauri/src-tauri/build.rs index 69b18c37..f2ca1700 100644 --- a/tauri/src-tauri/build.rs +++ b/tauri/src-tauri/build.rs @@ -7,12 +7,15 @@ fn main() { // Add Swift runtime library paths to RPATH println!("cargo:rustc-link-arg=-Wl,-rpath,/usr/lib/swift"); println!("cargo:rustc-link-arg=-L/usr/lib/swift"); - + // Also try Xcode's Swift libraries if let Ok(output) = Command::new("xcode-select").arg("-p").output() { if output.status.success() { let xcode_path = String::from_utf8_lossy(&output.stdout).trim().to_string(); - let swift_lib_path = format!("{}/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx", xcode_path); + let swift_lib_path = format!( + "{}/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx", + xcode_path + ); println!("cargo:rustc-link-arg=-Wl,-rpath,{}", swift_lib_path); println!("cargo:rustc-link-arg=-L{}", swift_lib_path); } @@ -38,14 +41,21 @@ fn main() { let output = Command::new("xcrun") .args([ "actool", - "--compile", &gen_dir, - "--output-format", "human-readable-text", - "--output-partial-info-plist", &partial_plist, - "--app-icon", "voicebox", + "--compile", + &gen_dir, + "--output-format", + "human-readable-text", + "--output-partial-info-plist", + &partial_plist, + "--app-icon", + "voicebox", "--include-all-app-icons", - "--target-device", "mac", - "--minimum-deployment-target", "11.0", - "--platform", "macosx", + "--target-device", + "mac", + "--minimum-deployment-target", + "11.0", + "--platform", + "macosx", &icon_source, ]) .output(); @@ -66,7 +76,10 @@ fn main() { } } } else { - println!("cargo:warning=Icon source not found at {}, skipping icon compilation", icon_source); + println!( + "cargo:warning=Icon source not found at {}, skipping icon compilation", + icon_source + ); } } diff --git a/tauri/src-tauri/gen/Assets.car b/tauri/src-tauri/gen/Assets.car index b7577eab8489c25657e09e4044c0a720dbfe403e..59f2c58afb043a8b40d5c80b5ec4fcec38f5450a 100644 GIT binary patch delta 811 zcmZwFy-rj?7zW^l6v$|2`1n&OtwSr<%vp#!b)33vDieWNKa8&M@>*#TV|1x9i4-Ltk35x zw|iCZL$`9Z%{DiNlo5(d$T)EDg`^858=FJXW;94@Bl#leZPQyAt2nW2ijq{av}Cd@ z#HFq&1g!&0AA5RJc2cN z3{T)GJcH-$&i0Gb(<gZjU!M ayYJ=}J01H2e}5eN3HJH+>&MN{lYaqTdEUnW delta 811 zcmZY7y>1gh5C?EO#^jPfOdt*<1V{k$z47ke?%Zw)F8g)LBjgR}P)Z6q3cHOW-XRhV zQi^jy!2=*s($Zm3pirgd9}!n~((k7G&(3JZzkavJ@cGA}ztC#6GU&lFEWzUG-@*6Z z5$_(KX@2}w^V2Ol?7SvJGACjrDKVv^Va|%gs!B#lMeb9qm{nA0#xFk2og$*jRetC2 z?VF?RjSo{hn%XwZK?klt7p}s5J+)ctmgK!l(d8@}WtmD&GFPA(MMG6g)`i?R`>5!v z@W0PyJub74ol@tH3mF7UA!w$eOVXrNBd9P^ z@ypTfj1KlQSb#-Xf@^RcmZ1kXU_UepKsFVD}*paf6GDJ%wSP)ZQ9TjQRzs&ywhL7HI diff --git a/tauri/src-tauri/src/main.rs b/tauri/src-tauri/src/main.rs index 4f61dbc4..2dda00aa 100644 --- a/tauri/src-tauri/src/main.rs +++ b/tauri/src-tauri/src/main.rs @@ -28,6 +28,57 @@ async fn start_server( return Ok(format!("http://127.0.0.1:{}", SERVER_PORT)); } + // Check if a voicebox server is already running on our port (from previous session with keep_running=true) + #[cfg(unix)] + { + use std::process::Command; + if let Ok(output) = Command::new("lsof") + .args(["-i", &format!(":{}", SERVER_PORT), "-sTCP:LISTEN"]) + .output() + { + let output_str = String::from_utf8_lossy(&output.stdout); + for line in output_str.lines().skip(1) { + let parts: Vec<&str> = line.split_whitespace().collect(); + if parts.len() >= 2 { + let command = parts[0]; + if command.contains("voicebox") { + println!("Found existing voicebox-server on port {}, reusing it", SERVER_PORT); + return Ok(format!("http://127.0.0.1:{}", SERVER_PORT)); + } + } + } + } + } + + #[cfg(windows)] + { + use std::process::Command; + if let Ok(output) = Command::new("netstat") + .args(["-ano"]) + .output() + { + let output_str = String::from_utf8_lossy(&output.stdout); + for line in output_str.lines() { + if line.contains(&format!(":{}", SERVER_PORT)) && line.contains("LISTENING") { + if let Some(pid_str) = line.split_whitespace().last() { + if let Ok(pid) = pid_str.parse::() { + if let Ok(tasklist_output) = Command::new("tasklist") + .args(["/FI", &format!("PID eq {}", pid), "/FO", "CSV", "/NH"]) + .output() + { + let tasklist_str = String::from_utf8_lossy(&tasklist_output.stdout); + if tasklist_str.to_lowercase().contains("voicebox") { + println!("Found existing voicebox-server on port {}, reusing it", SERVER_PORT); + return Ok(format!("http://127.0.0.1:{}", SERVER_PORT)); + } + } + } + } + } + } + } + } + // Kill any orphaned voicebox-server from previous session on legacy port 8000 // This handles upgrades from older versions that used a fixed port #[cfg(unix)]