tauri-apps / tauri

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

[bug] `FileDialogBuilder.set_directory` doesn't set the initial directory of the dialog #8500

Closed Crauzer closed 9 months ago

Crauzer commented 10 months ago

Describe the bug

Calling .set_directory on the blocking version of the FileDialogBuilder doesn't set the initial directory of the dialog

Reproduction

In this case, default_mount_directory is set to C:/Riot Games/League of Legends/Game/DATA/FINAL

When the dialog opens, the initial directory is set to the one from which I opened another file/directory previously using a different dialog.

#[tauri::command]
pub async fn mount_wads(
    mounted_wads: tauri::State<'_, MountedWadsState>,
    wad_hashtable: tauri::State<'_, WadHashtableState>,
    settings: tauri::State<'_, SettingsState>,
) -> Result<MountWadResponse, ApiError> {
    let mut mounted_wads_guard = mounted_wads.0.lock();

    let mut dialog =
        dialog::blocking::FileDialogBuilder::new().add_filter(".wad files", &["wad.client"]);

    if let Some(default_mount_directory) = &settings.0.read().default_mount_directory {
        dialog = dialog.set_directory(Path::new(default_mount_directory));
    }

    if let Some(wad_paths) = dialog.pick_files() {
       // rest of the code...
    }

    Err(ApiError::from_message("Failed to pick file"))
}

Expected behavior

No response

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.22621 X64
    ✔ WebView2: 120.0.2210.91
    ✔ MSVC:
        - Visual Studio Build Tools 2019
        - Visual Studio Community 2022
    ✔ rustc: 1.77.0-nightly (fb5ed726f 2023-12-28)
    ✔ Cargo: 1.77.0-nightly (ac6bbb332 2023-12-26)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: nightly-x86_64-pc-windows-msvc (default)
    - node: 16.11.0
    - pnpm: 8.7.6
    - yarn: 1.22.15
    - npm: 8.0.0

[-] Packages
    - tauri [RUST]: 1.5.4
    - tauri-build [RUST]: 1.5.1
    - wry [RUST]: 0.24.6
    - tao [RUST]: 0.16.5
    - cargo-tauri [RUST]: 1.0.0-beta.7
    - @tauri-apps/api [NPM]: 1.5.0 (outdated, latest: 1.5.3)
    - @tauri-apps/cli [NPM]: 1.5.0 (outdated, latest: 1.5.9)

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: http://localhost:1420/
    - framework: React
    - bundler: Vite

Stack trace

No response

Additional context

No response

amrbashir commented 9 months ago

This works fine on my end using your snippet, can you please share a minimal repro?