tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
78.1k stars 2.31k forks source link

[bug] The blocking file dialog builder crashes. #9641

Closed 0samuraiE closed 2 weeks ago

0samuraiE commented 2 weeks ago

Describe the bug

My tauri builder is below. When I try to open file folder from menu, the application crashes with no log. Please show me how do I treat this API.

    use tauri::{api::dialog::blocking::FileDialogBuilder, CustomMenuItem, Menu, MenuItem, Submenu};
    tauri::Builder::default()
        .menu(menu)
        .on_menu_event(|event| match event.menu_item_id() {
            "open" => {
                match FileDialogBuilder::new().set_directory(".").pick_folder() {
                    Some(buf) => {
                        let path = buf.to_string_lossy().to_string();
                        let window: &tauri::Window = event.window();

                        window
                            .emit("open-folder", Payload { path })
                            .expect("error while passing message");
                    }
                    None => {}
                };
            }
            _ => {}
        })
        .invoke_handler(tauri::generate_handler![commands::compute_hash])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");

Reproduction

No response

Expected behavior

Perhaps the app shows file dialog.

Full tauri info output

[✔] Environment
    - OS: EndeavourOS Rolling Release X64
    ✔ webkit2gtk-4.0: 2.44.1
    ✔ rsvg2: 2.58.0
    ✔ rustc: 1.77.2 (25ef9e3d8 2024-04-09)
    ✔ cargo: 1.77.2 (e52e36006 2024-03-26)
    ✔ rustup: 1.27.0 (bbb9276d2 2024-03-08)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
    - node: 20.12.2
    - yarn: 1.22.22
    - npm: 10.5.2

[-] Packages
    - tauri [RUST]: 1.6.2
    - tauri-build [RUST]: 1.5.1
    - wry [RUST]: 0.24.8
    - tao [RUST]: 0.16.9
    - @tauri-apps/api [NPM]: 1.5.4
    - @tauri-apps/cli [NPM]: 1.5.12

[-] App
    - build-type: bundle
    - CSP: default-src 'self'; img-src 'self' asset: https://asset.localhost
    - distDir: ../dist
    - devPath: http://localhost:1420/
    - framework: React
    - bundler: Vite

Stack trace

No response

Additional context

No response

0samuraiE commented 2 weeks ago

I didnot read "Shows the dialog to select a single file. This is a blocking operation, and should NOT be used when running on the main thread context." on docs.