From 19a95b7c458cd53944d4e91d514b78029a700cd0 Mon Sep 17 00:00:00 2001 From: Scott Reimers Date: Thu, 16 Apr 2026 15:49:56 -0400 Subject: [PATCH] Fix file picker for Android: gate blocking_pick behind desktop cfg Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/tauri-app/src/lib.rs | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/crates/tauri-app/src/lib.rs b/crates/tauri-app/src/lib.rs index 5431ad9..3e830e1 100644 --- a/crates/tauri-app/src/lib.rs +++ b/crates/tauri-app/src/lib.rs @@ -1645,21 +1645,37 @@ struct AddressInfoDto { #[tauri::command] async fn pick_file(app: tauri::AppHandle, title: String, filter_name: Option, filter_ext: Option>) -> Result, String> { - use tauri_plugin_dialog::DialogExt; - let mut builder = app.dialog().file().set_title(&title); - if let (Some(name), Some(exts)) = (filter_name, filter_ext) { - let ext_refs: Vec<&str> = exts.iter().map(|s| s.as_str()).collect(); - builder = builder.add_filter(&name, &ext_refs); + #[cfg(not(any(target_os = "android", target_os = "ios")))] + { + use tauri_plugin_dialog::DialogExt; + let mut builder = app.dialog().file().set_title(&title); + if let (Some(name), Some(exts)) = (filter_name, filter_ext) { + let ext_refs: Vec<&str> = exts.iter().map(|s| s.as_str()).collect(); + builder = builder.add_filter(&name, &ext_refs); + } + let path = builder.blocking_pick_file(); + Ok(path.map(|p| p.to_string())) + } + #[cfg(any(target_os = "android", target_os = "ios"))] + { + let _ = (app, title, filter_name, filter_ext); + Ok(None) // Mobile: file picker not supported via this command } - let path = builder.blocking_pick_file(); - Ok(path.map(|p| p.to_string())) } #[tauri::command] async fn pick_folder(app: tauri::AppHandle, title: String) -> Result, String> { - use tauri_plugin_dialog::DialogExt; - let path = app.dialog().file().set_title(&title).blocking_pick_folder(); - Ok(path.map(|p| p.to_string())) + #[cfg(not(any(target_os = "android", target_os = "ios")))] + { + use tauri_plugin_dialog::DialogExt; + let path = app.dialog().file().set_title(&title).blocking_pick_folder(); + Ok(path.map(|p| p.to_string())) + } + #[cfg(any(target_os = "android", target_os = "ios"))] + { + let _ = (app, title); + Ok(None) + } } #[tauri::command]