From 48acc10422a9eaa88f264efdfefb8fc183f9a501 Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Mon, 26 Jan 2026 17:20:46 -0800 Subject: [PATCH] Refactor Tauri server management and improve logging - Updated the server management logic in main.rs to include the PID of the existing voicebox server when reusing it, enhancing clarity in logging. - Improved the formatting of imports in App.tsx for better readability. --- app/src/App.tsx | 8 +++++++- tauri/src-tauri/src/main.rs | 13 ++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/App.tsx b/app/src/App.tsx index 9c7e1a2f..d38c4109 100644 --- a/app/src/App.tsx +++ b/app/src/App.tsx @@ -15,7 +15,13 @@ import { Toaster } from '@/components/ui/toaster'; import { ProfileList } from '@/components/VoiceProfiles/ProfileList'; import { useModelDownloadToast } from '@/lib/hooks/useModelDownloadToast'; import { MODEL_DISPLAY_NAMES, useRestoreActiveTasks } from '@/lib/hooks/useRestoreActiveTasks'; -import { isMacOS, isTauri, setupWindowCloseHandler, startServer, setKeepServerRunning } from '@/lib/tauri'; +import { + isMacOS, + isTauri, + setKeepServerRunning, + setupWindowCloseHandler, + startServer, +} from '@/lib/tauri'; import { useServerStore } from '@/stores/serverStore'; // Track if server is starting to prevent duplicate starts diff --git a/tauri/src-tauri/src/main.rs b/tauri/src-tauri/src/main.rs index 2dda00aa..b012c902 100644 --- a/tauri/src-tauri/src/main.rs +++ b/tauri/src-tauri/src/main.rs @@ -41,9 +41,14 @@ async fn start_server( let parts: Vec<&str> = line.split_whitespace().collect(); if parts.len() >= 2 { let command = parts[0]; + let pid_str = parts[1]; 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)); + if let Ok(pid) = pid_str.parse::() { + println!("Found existing voicebox-server on port {} (PID: {}), reusing it", SERVER_PORT, pid); + // Store the PID so we can kill it on exit if needed + *state.server_pid.lock().unwrap() = Some(pid); + return Ok(format!("http://127.0.0.1:{}", SERVER_PORT)); + } } } } @@ -68,7 +73,9 @@ async fn start_server( { 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); + println!("Found existing voicebox-server on port {} (PID: {}), reusing it", SERVER_PORT, pid); + // Store the PID so we can kill it on exit if needed + *state.server_pid.lock().unwrap() = Some(pid); return Ok(format!("http://127.0.0.1:{}", SERVER_PORT)); } }