From 7c4e8dc267b418d61411a34cc5de1b781aa0f63c Mon Sep 17 00:00:00 2001 From: Connor Yoh Date: Tue, 15 Jul 2025 15:58:45 +0100 Subject: [PATCH] Open with stirling mac --- frontend/src-tauri/src/lib.rs | 29 +++++++++++++---------------- frontend/src-tauri/tauri.conf.json | 3 ++- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/frontend/src-tauri/src/lib.rs b/frontend/src-tauri/src/lib.rs index 141573a45..aa88ec413 100644 --- a/frontend/src-tauri/src/lib.rs +++ b/frontend/src-tauri/src/lib.rs @@ -11,7 +11,19 @@ pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_fs::init()) - .setup(|_app| {Ok(())}) + .setup(|app| { + // Check command line arguments at startup for macOS file opening + let args: Vec = std::env::args().collect(); + for arg in args.iter().skip(1) { + if arg.ends_with(".pdf") && std::path::Path::new(arg).exists() { + add_log(format!("📂 File argument detected at startup: {}", arg)); + set_opened_file(arg.clone()); + break; // Only handle the first PDF file + } + } + + Ok(()) + }) .invoke_handler(tauri::generate_handler![start_backend, check_backend_health, get_opened_file, clear_opened_file]) .build(tauri::generate_context!()) .expect("error while building tauri application") @@ -28,21 +40,6 @@ pub fn run() { cleanup_backend(); // Allow the window to close } - // 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()); - } - } - } - } - } _ => {} } }); diff --git a/frontend/src-tauri/tauri.conf.json b/frontend/src-tauri/tauri.conf.json index d57c88f78..e2f63473c 100644 --- a/frontend/src-tauri/tauri.conf.json +++ b/frontend/src-tauri/tauri.conf.json @@ -38,7 +38,8 @@ "ext": ["pdf"], "name": "PDF Document", "description": "Open PDF files with Stirling-PDF", - "role": "Editor" + "role": "Editor", + "mimeType": "application/pdf" } ] },