From 38e0656e9804e49923b4a43318314274c5195097 Mon Sep 17 00:00:00 2001 From: Connor Yoh Date: Thu, 17 Jul 2025 12:13:16 +0100 Subject: [PATCH] Desktop upgrades and mac file handling --- frontend/src-tauri/src/file_handler.rs | 77 +++++++------------------ frontend/src-tauri/stirling-pdf.desktop | 6 +- scripts/build-tauri-jlink.sh | 2 +- 3 files changed, 23 insertions(+), 62 deletions(-) diff --git a/frontend/src-tauri/src/file_handler.rs b/frontend/src-tauri/src/file_handler.rs index b70e5ae6a..05ddc4df0 100644 --- a/frontend/src-tauri/src/file_handler.rs +++ b/frontend/src-tauri/src/file_handler.rs @@ -84,31 +84,6 @@ mod macos_native { // Store files opened during launch static LAUNCH_FILES: Lazy>> = Lazy::new(|| Mutex::new(Vec::new())); - // Track if app has finished launching - static APP_FINISHED_LAUNCHING: Lazy> = Lazy::new(|| Mutex::new(false)); - - extern "C" fn application_did_finish_launching(_self: &Object, _cmd: Sel, _notification: id) { - add_log("🚀 applicationDidFinishLaunching called".to_string()); - *APP_FINISHED_LAUNCHING.lock().unwrap() = true; - - // Process any files that were opened during launch - let launch_files = { - let mut files = LAUNCH_FILES.lock().unwrap(); - let result = files.clone(); - files.clear(); - result - }; - - for file_path in launch_files { - add_log(format!("📂 Processing launch file: {}", file_path)); - set_opened_file(file_path.clone()); - - if let Some(app) = APP_HANDLE.lock().unwrap().as_ref() { - let _ = app.emit("macos://open-file", file_path.clone()); - add_log(format!("✅ Emitted launch file event: {}", file_path)); - } - } - } extern "C" fn open_file(_self: &Object, _cmd: Sel, _sender: id, filename: id) -> bool { unsafe { @@ -119,20 +94,16 @@ mod macos_native { if let Ok(path) = cstr.to_str() { add_log(format!("📂 macOS native file open event: {}", path)); if path.ends_with(".pdf") { - let app_finished = *APP_FINISHED_LAUNCHING.lock().unwrap(); + // Always set the opened file for command-line interface + set_opened_file(path.to_string()); - if app_finished { - // App is running, handle immediately - add_log(format!("✅ App running, handling file immediately: {}", path)); - set_opened_file(path.to_string()); - - if let Some(app) = APP_HANDLE.lock().unwrap().as_ref() { - let _ = app.emit("macos://open-file", path.to_string()); - add_log(format!("✅ Emitted file open event: {}", path)); - } + if let Some(app) = APP_HANDLE.lock().unwrap().as_ref() { + // App is running, emit event immediately + add_log(format!("✅ App running, emitting file event: {}", path)); + let _ = app.emit("macos://open-file", path.to_string()); } else { - // App is launching, store for later - add_log(format!("🚀 App launching, storing file for later: {}", path)); + // App not ready yet, store for later processing + add_log(format!("🚀 App not ready, storing file for later: {}", path)); LAUNCH_FILES.lock().unwrap().push(path.to_string()); } } @@ -150,11 +121,7 @@ mod macos_native { let superclass = class!(NSObject); let mut decl = objc::declare::ClassDecl::new("StirlingAppDelegate", superclass).unwrap(); - // Add both delegate methods - decl.add_method( - sel!(applicationDidFinishLaunching:), - application_did_finish_launching as extern "C" fn(&Object, Sel, id) - ); + // Add file opening delegate method decl.add_method( sel!(application:openFile:), open_file as extern "C" fn(&Object, Sel, id, id) -> bool @@ -177,20 +144,18 @@ mod macos_native { // Store the app handle *APP_HANDLE.lock().unwrap() = Some(app.clone()); - // If app has finished launching and there are launch files, process them now - if *APP_FINISHED_LAUNCHING.lock().unwrap() { - let launch_files = { - let mut files = LAUNCH_FILES.lock().unwrap(); - let result = files.clone(); - files.clear(); - result - }; - - for file_path in launch_files { - add_log(format!("📂 Processing stored launch file: {}", file_path)); - set_opened_file(file_path.clone()); - let _ = app.emit("macos://open-file", file_path); - } + // Process any files that were opened during launch + let launch_files = { + let mut files = LAUNCH_FILES.lock().unwrap(); + let result = files.clone(); + files.clear(); + result + }; + + for file_path in launch_files { + add_log(format!("📂 Processing stored launch file: {}", file_path)); + set_opened_file(file_path.clone()); + let _ = app.emit("macos://open-file", file_path); } add_log("✅ macOS file handler connected successfully".to_string()); diff --git a/frontend/src-tauri/stirling-pdf.desktop b/frontend/src-tauri/stirling-pdf.desktop index 92e056922..9d6029377 100644 --- a/frontend/src-tauri/stirling-pdf.desktop +++ b/frontend/src-tauri/stirling-pdf.desktop @@ -3,16 +3,12 @@ Version=1.0 Type=Application Name=Stirling-PDF Comment=Locally hosted web application that allows you to perform various operations on PDF files -Exec={{bin}} Icon={{icon}} Terminal=false MimeType=application/pdf; Categories=Office;Graphics;Utility; -StartupNotify=true -StartupWMClass=stirling-pdf -NoDisplay=false Actions=open-file; [Desktop Action open-file] Name=Open PDF File -Exec={{bin}} %F \ No newline at end of file +Exec=/usr/bin/stirling-pdf %F \ No newline at end of file diff --git a/scripts/build-tauri-jlink.sh b/scripts/build-tauri-jlink.sh index d941773ec..10448173c 100644 --- a/scripts/build-tauri-jlink.sh +++ b/scripts/build-tauri-jlink.sh @@ -98,7 +98,7 @@ if command -v jdeps &> /dev/null; then if [ -n "$REQUIRED_MODULES" ]; then print_success "jdeps detected modules: $REQUIRED_MODULES" # Add additional modules we know Stirling-PDF needs - MODULES="$REQUIRED_MODULES,java.compiler,java.instrument,java.management,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.security.jgss,java.security.sasl,java.transaction.xa,java.xml.crypto,jdk.crypto.ec,jdk.crypto.cryptoki,jdk.unsupported" + MODULES="$REQUIRED_MODULES,java.compiler,java.instrument,java.management,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.security.jgss,java.security.sasl,java.sql,java.transaction.xa,java.xml.crypto,jdk.crypto.ec,jdk.crypto.cryptoki,jdk.unsupported" else print_warning "jdeps analysis failed, using predefined module list" MODULES="java.base,java.compiler,java.desktop,java.instrument,java.logging,java.management,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.security.jgss,java.security.sasl,java.sql,java.transaction.xa,java.xml,java.xml.crypto,jdk.crypto.ec,jdk.crypto.cryptoki,jdk.unsupported"