@@ -300,6 +300,30 @@ pub mod blocking {
300300 response
301301 }
302302
303+ /// Shows the dialog to select multiple folders.
304+ /// This is a blocking operation,
305+ /// and should *NOT* be used when running on the main thread context.
306+ ///
307+ /// # Examples
308+ ///
309+ /// ```rust,no_run
310+ /// use tauri::api::dialog::blocking::FileDialogBuilder;
311+ /// #[tauri::command]
312+ /// fn my_command() {
313+ /// let folder_paths = FileDialogBuilder::new().pick_folders();
314+ /// // do something with the optional folder paths here
315+ /// // the folder paths value is `None` if the user closed the dialog
316+ /// }
317+ /// ```
318+ pub fn pick_folders ( self ) -> Option < Vec < PathBuf > > {
319+ #[ allow( clippy:: let_and_return) ]
320+ let response = run_dialog_sync ! ( self . 0 . pick_folders( ) ) ;
321+ #[ cfg( not( target_os = "linux" ) ) ]
322+ let response =
323+ response. map ( |paths| paths. into_iter ( ) . map ( |p| p. path ( ) . to_path_buf ( ) ) . collect ( ) ) ;
324+ response
325+ }
326+
303327 /// Shows the dialog to save a file.
304328 /// This is a blocking operation,
305329 /// and should *NOT* be used when running on the main thread context.
@@ -515,6 +539,32 @@ mod nonblocking {
515539 run_file_dialog ! ( self . 0 . pick_folder( ) , f)
516540 }
517541
542+ /// Shows the dialog to select multiple folders.
543+ /// This is not a blocking operation,
544+ /// and should be used when running on the main thread to avoid deadlocks with the event loop.
545+ ///
546+ /// # Examples
547+ ///
548+ /// ```rust,no_run
549+ /// use tauri::api::dialog::FileDialogBuilder;
550+ /// tauri::Builder::default()
551+ /// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
552+ /// .expect("failed to build tauri app")
553+ /// .run(|_app, _event| {
554+ /// FileDialogBuilder::new().pick_folders(|file_paths| {
555+ /// // do something with the optional folder paths here
556+ /// // the folder paths value is `None` if the user closed the dialog
557+ /// })
558+ /// })
559+ /// ```
560+ pub fn pick_folders < F : FnOnce ( Option < Vec < PathBuf > > ) + Send + ' static > ( self , f : F ) {
561+ #[ cfg( not( target_os = "linux" ) ) ]
562+ let f = |paths : Option < Vec < rfd:: FileHandle > > | {
563+ f ( paths. map ( |list| list. into_iter ( ) . map ( |p| p. path ( ) . to_path_buf ( ) ) . collect ( ) ) )
564+ } ;
565+ run_file_dialog ! ( self . 0 . pick_folders( ) , f)
566+ }
567+
518568 /// Shows the dialog to save a file.
519569 ///
520570 /// This is not a blocking operation,
0 commit comments