#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] use std::sync::Mutex; use tauri::{Emitter, Manager, RunEvent, Wry}; struct PendingOpens(Mutex>); #[tauri::command] fn take_pending_opens(state: tauri::State) -> Vec { let mut pending = state.0.lock().expect("pending opens lock"); pending.drain(..).collect() } fn main() { tauri::Builder::default() .manage(PendingOpens(Mutex::new(Vec::new()))) .invoke_handler(tauri::generate_handler![take_pending_opens]) .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_clipboard_manager::init()) .plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_sql::Builder::default().build()) .plugin( tauri::plugin::Builder::::new("file-open") .on_event(|app, event| { #[cfg(any(target_os = "macos", target_os = "ios"))] if let RunEvent::Opened { urls } = event { let paths: Vec = urls .iter() .filter_map(|url| url.to_file_path().ok()) .map(|path| path.to_string_lossy().to_string()) .collect(); if paths.is_empty() { return; } if let Some(state) = app.try_state::() { let mut pending = state.0.lock().expect("pending opens lock"); pending.extend(paths.iter().cloned()); } let _ = app.emit("file-opened", paths); } }) .build(), ) .run(tauri::generate_context!()) .expect("error while running tauri application"); }