2025-06-24 15:18:27 +01:00
|
|
|
use tauri::{RunEvent, WindowEvent};
|
2025-06-09 10:04:40 +01:00
|
|
|
|
2025-07-04 17:02:59 +01:00
|
|
|
mod utils;
|
|
|
|
mod commands;
|
2025-06-09 10:04:40 +01:00
|
|
|
|
2025-07-15 15:48:33 +01:00
|
|
|
use commands::{start_backend, check_backend_health, get_opened_file, clear_opened_file, cleanup_backend, set_opened_file};
|
2025-07-04 17:02:59 +01:00
|
|
|
use utils::add_log;
|
2025-06-24 15:18:27 +01:00
|
|
|
|
2025-06-05 14:56:16 +01:00
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
|
|
pub fn run() {
|
|
|
|
tauri::Builder::default()
|
2025-06-09 10:04:40 +01:00
|
|
|
.plugin(tauri_plugin_shell::init())
|
2025-07-04 14:33:59 +01:00
|
|
|
.plugin(tauri_plugin_fs::init())
|
2025-07-04 16:07:10 +01:00
|
|
|
.setup(|_app| {Ok(())})
|
2025-07-15 15:48:33 +01:00
|
|
|
.invoke_handler(tauri::generate_handler![start_backend, check_backend_health, get_opened_file, clear_opened_file])
|
2025-06-24 15:18:27 +01:00
|
|
|
.build(tauri::generate_context!())
|
|
|
|
.expect("error while building tauri application")
|
|
|
|
.run(|app_handle, event| {
|
|
|
|
match event {
|
2025-07-01 14:22:19 +01:00
|
|
|
RunEvent::ExitRequested { .. } => {
|
2025-06-24 15:18:27 +01:00
|
|
|
add_log("🔄 App exit requested, cleaning up...".to_string());
|
|
|
|
cleanup_backend();
|
|
|
|
// Use Tauri's built-in cleanup
|
|
|
|
app_handle.cleanup_before_exit();
|
|
|
|
}
|
2025-07-01 14:22:19 +01:00
|
|
|
RunEvent::WindowEvent { event: WindowEvent::CloseRequested {.. }, .. } => {
|
2025-06-24 15:18:27 +01:00
|
|
|
add_log("🔄 Window close requested, cleaning up...".to_string());
|
|
|
|
cleanup_backend();
|
|
|
|
// Allow the window to close
|
|
|
|
}
|
2025-07-15 15:48:33 +01:00
|
|
|
// Handle macOS file open events
|
|
|
|
RunEvent::Opened { urls } => {
|
|
|
|
for url in urls {
|
|
|
|
add_log(format!("📂 File opened via macOS event: {}", url));
|
|
|
|
|
|
|
|
// Convert URL to file path if it's a file URL
|
|
|
|
if let Ok(path) = url.to_file_path() {
|
|
|
|
if let Some(path_str) = path.to_str() {
|
|
|
|
if path_str.ends_with(".pdf") {
|
|
|
|
set_opened_file(path_str.to_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-06-24 15:18:27 +01:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
});
|
2025-07-04 17:02:59 +01:00
|
|
|
}
|