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.
This commit is contained in:
Jamie Pine
2026-01-26 17:17:57 -08:00
parent 6a0601bd6c
commit 1fdf61ca2e
3 changed files with 74 additions and 10 deletions
+23 -10
View File
@@ -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
);
}
}
Binary file not shown.
+51
View File
@@ -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::<u32>() {
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)]