Cleanup logs, remove redundant code

This commit is contained in:
Connor Yoh 2025-07-04 17:21:49 +01:00
parent 31947c92f4
commit 9b22aeac63
5 changed files with 13 additions and 67 deletions

View File

@ -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<Option<String>, String> {
Ok(None)
}
// Command to check bundled runtime and JAR
#[tauri::command]
pub async fn check_jar_exists(app: tauri::AppHandle) -> Result<String, String> {
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<String> = 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())
}
}

View File

@ -9,10 +9,10 @@ pub async fn check_backend_health() -> Result<bool, String> {
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<bool, String> {
}
}
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)
}
}

View File

@ -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};
pub use files::get_opened_file;

View File

@ -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| {

View File

@ -6,11 +6,15 @@ static BACKEND_LOGS: Mutex<VecDeque<String>> = 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
}