Просмотр исходного кода

fix(core): dialog crashing on macOS when the parent is empty (#4028)

Lucas Fernandes Nogueira 3 лет назад
Родитель
Сommit
d31167c520
2 измененных файлов с 8 добавлено и 1 удалено
  1. 5 0
      .changes/fix-dialog-default-path-crash.md
  2. 3 1
      core/tauri/src/endpoints/dialog.rs

+ 5 - 0
.changes/fix-dialog-default-path-crash.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Fix dialog crash on macOS when the `default_path` value is just the file name.

+ 3 - 1
core/tauri/src/endpoints/dialog.rs

@@ -205,7 +205,9 @@ fn set_default_path(
 ) -> FileDialogBuilder {
   if default_path.is_file() || !default_path.exists() {
     if let (Some(parent), Some(file_name)) = (default_path.parent(), default_path.file_name()) {
-      dialog_builder = dialog_builder.set_directory(parent);
+      if parent.components().count() > 0 {
+        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);