From 85934e4625dc7ae673518c87f60c3bc5c8e8d945 Mon Sep 17 00:00:00 2001 From: James Brunton Date: Fri, 14 Nov 2025 14:24:03 +0000 Subject: [PATCH] Only read commandline args on startup --- frontend/src-tauri/src/commands/files.rs | 22 +++++----------------- frontend/src-tauri/src/lib.rs | 10 ++++++++++ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/frontend/src-tauri/src/commands/files.rs b/frontend/src-tauri/src/commands/files.rs index 2d22ac53e..7faadf0db 100644 --- a/frontend/src-tauri/src/commands/files.rs +++ b/frontend/src-tauri/src/commands/files.rs @@ -14,23 +14,11 @@ pub fn add_opened_file(file_path: String) { // Command to get opened file paths (if app was launched with files) #[tauri::command] pub async fn get_opened_files() -> Result, String> { - let mut all_files: Vec = Vec::new(); - - // Get files from command line arguments (Windows/Linux 'Open With Stirling' behaviour) - let args: Vec = std::env::args().collect(); - let pdf_files: Vec = args.iter() - .skip(1) - .filter(|arg| std::path::Path::new(arg).exists()) - .cloned() - .collect(); - - all_files.extend(pdf_files); - - // Add any files sent via events or other instances (macOS 'Open With Stirling' behaviour, also Windows/Linux extra files) - { - let opened_files = OPENED_FILES.lock().unwrap(); - all_files.extend(opened_files.clone()); - } + // Get all files from the OPENED_FILES store + // Command line args are processed in setup() callback and added to this store + // Additional files from second instances or events are also added here + let opened_files = OPENED_FILES.lock().unwrap(); + let all_files = opened_files.clone(); add_log(format!("📂 Returning {} opened file(s)", all_files.len())); Ok(all_files) diff --git a/frontend/src-tauri/src/lib.rs b/frontend/src-tauri/src/lib.rs index 02343b290..969479666 100644 --- a/frontend/src-tauri/src/lib.rs +++ b/frontend/src-tauri/src/lib.rs @@ -45,6 +45,16 @@ pub fn run() { })) .setup(|_app| { add_log("🚀 Tauri app setup started".to_string()); + + // Process command line arguments on first launch + let args: Vec = std::env::args().collect(); + for arg in args.iter().skip(1) { + if std::path::Path::new(arg).exists() { + add_log(format!("📂 Initial file from command line: {}", arg)); + add_opened_file(arg.clone()); + } + } + add_log("🔍 DEBUG: Setup completed".to_string()); Ok(()) })