Skip to content

Commit

Permalink
[file_selector] Fix Linux cancel regression (#8051)
Browse files Browse the repository at this point in the history
Fixes a regression introduced during the Pigeon conversion where canceling a dialog would fail assertions due to accidentally returning a null list instead of an empty list.

Fixes flutter/flutter#158430
  • Loading branch information
stuartmorgan authored Nov 11, 2024
1 parent a9b7140 commit d681e4e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/file_selector/file_selector_linux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.3+1

* Fixes a regression in 0.9.3 with handling of canceled dialogs.

## 0.9.3

* Updates method channel implementation to use Pigeon.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ static FfsFileSelectorApiShowFileChooserResponse* handle_show_file_chooser(
return ffs_file_selector_api_show_file_chooser_response_new_error(
kBadArgumentsError, "Unable to create dialog from arguments", nullptr);
}
return show_file_chooser(GTK_FILE_CHOOSER_NATIVE(dialog),
gtk_native_dialog_run);
}

gint response = gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog));
g_autoptr(FlValue) result = nullptr;
FfsFileSelectorApiShowFileChooserResponse* show_file_chooser(
GtkFileChooserNative* dialog, gint (*run_dialog)(GtkNativeDialog*)) {
gint response = run_dialog(GTK_NATIVE_DIALOG(dialog));
g_autoptr(FlValue) result = fl_value_new_list();
if (response == GTK_RESPONSE_ACCEPT) {
result = fl_value_new_list();
g_autoptr(GSList) filenames =
gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
for (GSList* link = filenames; link != nullptr; link = link->next) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

#include <flutter_linux/flutter_linux.h>
#include <gtk/gtk.h>

#include "include/file_selector_linux/file_selector_plugin.h"
#include "messages.g.h"
Expand All @@ -17,3 +18,9 @@
GtkFileChooserNative* create_dialog_of_type(
GtkWindow* window, FfsPlatformFileChooserActionType type,
FfsPlatformFileChooserOptions* options);

// TODO(stuartmorgan): Fold this into handle_show_file_chooser as part of the
// above TODO. This only exists to allow testing response generation without
// mocking out all of the GTK calls.
FfsFileSelectorApiShowFileChooserResponse* show_file_chooser(
GtkFileChooserNative* dialog, gint (*run_dialog)(GtkNativeDialog*));
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,25 @@ TEST(FileSelectorPlugin, TestGetMultipleDirectories) {
EXPECT_EQ(gtk_file_chooser_get_select_multiple(GTK_FILE_CHOOSER(dialog)),
true);
}

static gint mock_run_dialog_cancel(GtkNativeDialog* dialog) {
return GTK_RESPONSE_CANCEL;
}

TEST(FileSelectorPlugin, TestGetDirectoryCancel) {
g_autoptr(FfsPlatformFileChooserOptions) options =
ffs_platform_file_chooser_options_new(nullptr, nullptr, nullptr, nullptr,
nullptr);

g_autoptr(GtkFileChooserNative) dialog = create_dialog_of_type(
nullptr,
FILE_SELECTOR_LINUX_PLATFORM_FILE_CHOOSER_ACTION_TYPE_CHOOSE_DIRECTORY,
options);

ASSERT_NE(dialog, nullptr);

g_autoptr(FfsFileSelectorApiShowFileChooserResponse) response =
show_file_chooser(dialog, mock_run_dialog_cancel);

EXPECT_NE(response, nullptr);
}
2 changes: 1 addition & 1 deletion packages/file_selector/file_selector_linux/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: file_selector_linux
description: Liunx implementation of the file_selector plugin.
repository: https://github.com/flutter/packages/tree/main/packages/file_selector/file_selector_linux
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22
version: 0.9.3
version: 0.9.3+1

environment:
sdk: ^3.3.0
Expand Down

0 comments on commit d681e4e

Please sign in to comment.