use tauri_plugin_fs::FsExt; #[tauri::command] fn get_portable_data_dir() -> Result { let exe_path = std::env::current_exe().map_err(|e| e.to_string())?; let exe_dir = exe_path .parent() .ok_or_else(|| "Failed to get exe directory".to_string())?; let data_dir = exe_dir.join("data"); Ok(data_dir.to_string_lossy().to_string()) } #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_notification::init()) .setup(|app| { // Get portable data directory next to the exe let exe_path = std::env::current_exe().expect("Failed to get exe path"); let exe_dir = exe_path .parent() .expect("Failed to get exe directory"); let data_dir = exe_dir.join("data"); // Ensure data directory exists std::fs::create_dir_all(&data_dir) .expect("Failed to create portable data directory"); // Allow FS plugin access to the portable data directory app.fs_scope() .allow_directory(&data_dir, true) .expect("Failed to allow data directory in FS scope"); Ok(()) }) .invoke_handler(tauri::generate_handler![get_portable_data_dir]) .run(tauri::generate_context!()) .expect("error while running tauri application"); }