From 9b22aeac63c68b2c510ac1e87cbc8b3a65059adb Mon Sep 17 00:00:00 2001 From: Connor Yoh Date: Fri, 4 Jul 2025 17:21:49 +0100 Subject: [PATCH] Cleanup logs, remove redundant code --- frontend/src-tauri/src/commands/files.rs | 61 ----------------------- frontend/src-tauri/src/commands/health.rs | 7 ++- frontend/src-tauri/src/commands/mod.rs | 2 +- frontend/src-tauri/src/lib.rs | 4 +- frontend/src-tauri/src/utils/logging.rs | 6 ++- 5 files changed, 13 insertions(+), 67 deletions(-) diff --git a/frontend/src-tauri/src/commands/files.rs b/frontend/src-tauri/src/commands/files.rs index 797187795..e77917e1f 100644 --- a/frontend/src-tauri/src/commands/files.rs +++ b/frontend/src-tauri/src/commands/files.rs @@ -1,4 +1,3 @@ -use tauri::Manager; use crate::utils::add_log; // Command to get opened file path (if app was launched with a file) @@ -18,63 +17,3 @@ pub async fn get_opened_file() -> Result, String> { Ok(None) } -// Command to check bundled runtime and JAR -#[tauri::command] -pub async fn check_jar_exists(app: tauri::AppHandle) -> Result { - println!("🔍 Checking for bundled JRE and JAR files..."); - - if let Ok(resource_dir) = app.path().resource_dir() { - let mut status_parts = Vec::new(); - - // Check bundled JRE - let jre_dir = resource_dir.join("runtime").join("jre"); - let java_executable = if cfg!(windows) { - jre_dir.join("bin").join("java.exe") - } else { - jre_dir.join("bin").join("java") - }; - - if java_executable.exists() { - status_parts.push("✅ Bundled JRE found".to_string()); - } else { - status_parts.push("❌ Bundled JRE not found".to_string()); - } - - // Check JAR files - let libs_dir = resource_dir.join("libs"); - if libs_dir.exists() { - match std::fs::read_dir(&libs_dir) { - Ok(entries) => { - let jar_files: Vec = entries - .filter_map(|entry| entry.ok()) - .filter(|entry| { - let path = entry.path(); - // Match any .jar file containing "stirling-pdf" (case-insensitive) - path.extension().and_then(|s| s.to_str()).map(|ext| ext.eq_ignore_ascii_case("jar")).unwrap_or(false) - && path.file_name() - .and_then(|f| f.to_str()) - .map(|name| name.to_ascii_lowercase().contains("stirling-pdf")) - .unwrap_or(false) - }) - .map(|entry| entry.file_name().to_string_lossy().to_string()) - .collect(); - - if !jar_files.is_empty() { - status_parts.push(format!("✅ Found JAR files: {:?}", jar_files)); - } else { - status_parts.push("❌ No Stirling-PDF JAR files found".to_string()); - } - } - Err(e) => { - status_parts.push(format!("❌ Failed to read libs directory: {}", e)); - } - } - } else { - status_parts.push("❌ Libs directory not found".to_string()); - } - - Ok(status_parts.join("\n")) - } else { - Ok("❌ Could not access bundled resources".to_string()) - } -} \ No newline at end of file diff --git a/frontend/src-tauri/src/commands/health.rs b/frontend/src-tauri/src/commands/health.rs index a7b7f1b0f..394c8462c 100644 --- a/frontend/src-tauri/src/commands/health.rs +++ b/frontend/src-tauri/src/commands/health.rs @@ -9,10 +9,10 @@ pub async fn check_backend_health() -> Result { match client.get("http://localhost:8080/api/v1/info/status").send().await { Ok(response) => { let status = response.status(); - println!("💓 Health check response status: {}", status); if status.is_success() { match response.text().await { Ok(_body) => { + println!("✅ Backend health check successful"); Ok(true) } Err(e) => { @@ -26,7 +26,10 @@ pub async fn check_backend_health() -> Result { } } Err(e) => { - println!("❌ Health check error: {}", e); + // Only log connection errors if they're not the common "connection refused" during startup + if !e.to_string().contains("connection refused") && !e.to_string().contains("No connection could be made") { + println!("❌ Health check error: {}", e); + } Ok(false) } } diff --git a/frontend/src-tauri/src/commands/mod.rs b/frontend/src-tauri/src/commands/mod.rs index 4c8d87851..97cd657d2 100644 --- a/frontend/src-tauri/src/commands/mod.rs +++ b/frontend/src-tauri/src/commands/mod.rs @@ -4,4 +4,4 @@ pub mod files; pub use backend::{start_backend, cleanup_backend}; pub use health::check_backend_health; -pub use files::{get_opened_file, check_jar_exists}; \ No newline at end of file +pub use files::get_opened_file; \ No newline at end of file diff --git a/frontend/src-tauri/src/lib.rs b/frontend/src-tauri/src/lib.rs index d1654a662..084c57f6d 100644 --- a/frontend/src-tauri/src/lib.rs +++ b/frontend/src-tauri/src/lib.rs @@ -3,7 +3,7 @@ use tauri::{RunEvent, WindowEvent}; mod utils; mod commands; -use commands::{start_backend, check_backend_health, check_jar_exists, get_opened_file, cleanup_backend}; +use commands::{start_backend, check_backend_health, get_opened_file, cleanup_backend}; use utils::add_log; #[cfg_attr(mobile, tauri::mobile_entry_point)] @@ -12,7 +12,7 @@ pub fn run() { .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_fs::init()) .setup(|_app| {Ok(())}) - .invoke_handler(tauri::generate_handler![start_backend, check_backend_health, check_jar_exists, get_opened_file]) + .invoke_handler(tauri::generate_handler![start_backend, check_backend_health, get_opened_file]) .build(tauri::generate_context!()) .expect("error while building tauri application") .run(|app_handle, event| { diff --git a/frontend/src-tauri/src/utils/logging.rs b/frontend/src-tauri/src/utils/logging.rs index d529a1a3f..c5c0fccab 100644 --- a/frontend/src-tauri/src/utils/logging.rs +++ b/frontend/src-tauri/src/utils/logging.rs @@ -6,11 +6,15 @@ static BACKEND_LOGS: Mutex> = Mutex::new(VecDeque::new()); // Helper function to add log entry pub fn add_log(message: String) { + let mut logs = BACKEND_LOGS.lock().unwrap(); logs.push_back(format!("{}: {}", std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs(), message)); // Keep only last 100 log entries if logs.len() > 100 { logs.pop_front(); } - println!("{}", message); // Also print to console + + // Remove trailing newline if present + let clean_message = message.trim_end_matches('\n').to_string(); + println!("{}", clean_message); // Also print to console } \ No newline at end of file