Skip to content

Commit 8b2cc26

Browse files
authored
fix(core): dialog's defaultPath behavior on Linux, closes #2232 (#2382)
1 parent 9c4032b commit 8b2cc26

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

Diff for: .changes/fix-dialog-save-default-path-linux.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Fixes `defaultPath` option on dialog API not setting the file name if it doesn't exist on Linux.

Diff for: core/tauri/src/endpoints/dialog.rs

+5-22
Original file line numberDiff line numberDiff line change
@@ -114,35 +114,18 @@ impl Cmd {
114114
}
115115
}
116116

117-
#[cfg(all(target_os = "linux", any(dialog_open, dialog_save)))]
117+
#[cfg(any(dialog_open, dialog_save))]
118118
fn set_default_path(
119119
mut dialog_builder: FileDialogBuilder,
120120
default_path: PathBuf,
121121
) -> FileDialogBuilder {
122122
if default_path.is_file() || !default_path.exists() {
123-
dialog_builder = dialog_builder.set_file_name(&default_path.to_string_lossy().to_string());
124-
dialog_builder.set_directory(default_path.parent().unwrap())
125-
} else {
126-
dialog_builder.set_directory(default_path)
127-
}
128-
}
129-
130-
#[cfg(all(any(windows, target_os = "macos"), any(dialog_open, dialog_save)))]
131-
fn set_default_path(
132-
mut dialog_builder: FileDialogBuilder,
133-
default_path: PathBuf,
134-
) -> FileDialogBuilder {
135-
if default_path.is_file() {
136-
if let Some(parent) = default_path.parent() {
123+
if let (Some(parent), Some(file_name)) = (default_path.parent(), default_path.file_name()) {
137124
dialog_builder = dialog_builder.set_directory(parent);
125+
dialog_builder = dialog_builder.set_file_name(&file_name.to_string_lossy().to_string());
126+
} else {
127+
dialog_builder = dialog_builder.set_directory(default_path);
138128
}
139-
dialog_builder = dialog_builder.set_file_name(
140-
&default_path
141-
.file_name()
142-
.unwrap()
143-
.to_string_lossy()
144-
.to_string(),
145-
);
146129
dialog_builder
147130
} else {
148131
dialog_builder.set_directory(default_path)

Diff for: core/tauri/src/updater/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl RemoteRelease {
9191

9292
let download_url;
9393
#[cfg(target_os = "windows")]
94-
let mut with_elevated_task = false;
94+
let with_elevated_task;
9595

9696
match release.get("platforms") {
9797
//

Diff for: tooling/api/src/dialog.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ interface OpenDialogOptions {
5757
interface SaveDialogOptions {
5858
/** The filters of the dialog. */
5959
filters?: DialogFilter[]
60-
/** Initial directory or file path. It must exist. */
60+
/**
61+
* Initial directory or file path.
62+
* If it's a directory path, the dialog interface will change to that folder.
63+
* If it's not an existing directory, the file name will be set to the dialog's file name input and the dialog will be set to the parent folder.
64+
*/
6165
defaultPath?: string
6266
}
6367

0 commit comments

Comments
 (0)