From 1346a653e48b5f734e3956bf8d05223bd8c2937a Mon Sep 17 00:00:00 2001 From: networkException Date: Sat, 10 Sep 2022 13:12:35 +0200 Subject: [PATCH] WidgetGallery: Port file picker to use FileSystemAccessClient Previously we would unveil the home directory of anon to allow showing anything in the file picker. This patch removes direct access to the home directory and instead makes WidgetGallery connect to FileSystemAccessServer to open a file, making the application more user agnostic and allowing directories outside /home/anon to be shown. --- Userland/Demos/WidgetGallery/CMakeLists.txt | 2 +- Userland/Demos/WidgetGallery/GalleryWidget.cpp | 7 ++++--- Userland/Demos/WidgetGallery/main.cpp | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Userland/Demos/WidgetGallery/CMakeLists.txt b/Userland/Demos/WidgetGallery/CMakeLists.txt index 71d1e410c8..3353f9d965 100644 --- a/Userland/Demos/WidgetGallery/CMakeLists.txt +++ b/Userland/Demos/WidgetGallery/CMakeLists.txt @@ -27,4 +27,4 @@ set(SOURCES ) serenity_app(WidgetGallery ICON app-widget-gallery) -target_link_libraries(WidgetGallery LibGUI LibMain) +target_link_libraries(WidgetGallery LibGUI LibMain LibFileSystemAccessClient) diff --git a/Userland/Demos/WidgetGallery/GalleryWidget.cpp b/Userland/Demos/WidgetGallery/GalleryWidget.cpp index 047f442cc2..b569e90a0b 100644 --- a/Userland/Demos/WidgetGallery/GalleryWidget.cpp +++ b/Userland/Demos/WidgetGallery/GalleryWidget.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -107,10 +108,10 @@ GalleryWidget::GalleryWidget() m_file_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png"sv).release_value_but_fixme_should_propagate_errors()); m_file_button->on_click = [&](auto) { - Optional open_path = GUI::FilePicker::get_open_filepath(window()); - if (!open_path.has_value()) + auto response = FileSystemAccessClient::Client::the().try_open_file(window()); + if (response.is_error()) return; - m_text_editor->set_text(open_path.value()); + m_text_editor->set_text(response.release_value()->filename()); }; m_input_button = basics_tab->find_descendant_of_type_named("input_button"); diff --git a/Userland/Demos/WidgetGallery/main.cpp b/Userland/Demos/WidgetGallery/main.cpp index 9ba23b82a1..7c7681ec86 100644 --- a/Userland/Demos/WidgetGallery/main.cpp +++ b/Userland/Demos/WidgetGallery/main.cpp @@ -17,9 +17,8 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio recvfd sendfd rpath unix thread")); auto app = TRY(GUI::Application::try_create(arguments, Core::EventLoop::MakeInspectable::Yes)); - TRY(Core::System::pledge("stdio recvfd sendfd rpath thread")); TRY(Core::System::unveil("/res", "r")); - TRY(Core::System::unveil("/home/anon", "r")); + TRY(Core::System::unveil("/tmp/user/%uid/portal/filesystemaccess", "rw")); TRY(Core::System::unveil("/etc/FileIconProvider.ini", "r")); TRY(Core::System::unveil(nullptr, nullptr)); auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-widget-gallery"sv));