Skip to content

Commit

Permalink
fix(core): dialog's defaultPath behavior on Linux, closes #2232 (#2382
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lucasfernog committed Aug 10, 2021
1 parent 9c4032b commit 8b2cc26
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-dialog-save-default-path-linux.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Fixes `defaultPath` option on dialog API not setting the file name if it doesn't exist on Linux.
27 changes: 5 additions & 22 deletions core/tauri/src/endpoints/dialog.rs
Expand Up @@ -114,35 +114,18 @@ impl Cmd {
}
}

#[cfg(all(target_os = "linux", any(dialog_open, dialog_save)))]
#[cfg(any(dialog_open, dialog_save))]
fn set_default_path(
mut dialog_builder: FileDialogBuilder,
default_path: PathBuf,
) -> FileDialogBuilder {
if default_path.is_file() || !default_path.exists() {
dialog_builder = dialog_builder.set_file_name(&default_path.to_string_lossy().to_string());
dialog_builder.set_directory(default_path.parent().unwrap())
} else {
dialog_builder.set_directory(default_path)
}
}

#[cfg(all(any(windows, target_os = "macos"), any(dialog_open, dialog_save)))]
fn set_default_path(
mut dialog_builder: FileDialogBuilder,
default_path: PathBuf,
) -> FileDialogBuilder {
if default_path.is_file() {
if let Some(parent) = default_path.parent() {
if let (Some(parent), Some(file_name)) = (default_path.parent(), default_path.file_name()) {
dialog_builder = dialog_builder.set_directory(parent);
dialog_builder = dialog_builder.set_file_name(&file_name.to_string_lossy().to_string());
} else {
dialog_builder = dialog_builder.set_directory(default_path);
}
dialog_builder = dialog_builder.set_file_name(
&default_path
.file_name()
.unwrap()
.to_string_lossy()
.to_string(),
);
dialog_builder
} else {
dialog_builder.set_directory(default_path)
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/updater/core.rs
Expand Up @@ -91,7 +91,7 @@ impl RemoteRelease {

let download_url;
#[cfg(target_os = "windows")]
let mut with_elevated_task = false;
let with_elevated_task;

match release.get("platforms") {
//
Expand Down
6 changes: 5 additions & 1 deletion tooling/api/src/dialog.ts
Expand Up @@ -57,7 +57,11 @@ interface OpenDialogOptions {
interface SaveDialogOptions {
/** The filters of the dialog. */
filters?: DialogFilter[]
/** Initial directory or file path. It must exist. */
/**
* Initial directory or file path.
* If it's a directory path, the dialog interface will change to that folder.
* 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.
*/
defaultPath?: string
}

Expand Down

0 comments on commit 8b2cc26

Please sign in to comment.