Open with stirling mac

This commit is contained in:
Connor Yoh 2025-07-15 15:58:45 +01:00
parent 499829bd69
commit 7c4e8dc267
2 changed files with 15 additions and 17 deletions

View File

@ -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<String> = 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());
}
}
}
}
}
_ => {}
}
});

View File

@ -38,7 +38,8 @@
"ext": ["pdf"],
"name": "PDF Document",
"description": "Open PDF files with Stirling-PDF",
"role": "Editor"
"role": "Editor",
"mimeType": "application/pdf"
}
]
},