diff options
author | Brendan Coles <bcoles@gmail.com> | 2021-03-12 12:25:38 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-12 15:22:12 +0100 |
commit | 8c0723960b3a27fa245bd96fb69c630f4dcf5083 (patch) | |
tree | ae967d72c550884b24d8ddccbd688aedd374d796 /Userland/Applications | |
parent | 612a5225fa42345c433b197f08e8bbaa774116c8 (diff) | |
download | serenity-8c0723960b3a27fa245bd96fb69c630f4dcf5083.zip |
QuickShow: Replace posix_spawn with LibDesktop::Launcher
When multiple images are dragged and dropped onto the image widget,
QuickShow will use LibDesktop::Launcher to launch a new instance
of QuickShow for each item, rather than spawn a child QuickShow
process for each item with posix_spawn.
This allows `proc` and `exec` pledges to be removed :^)
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/QuickShow/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Applications/QuickShow/main.cpp | 42 |
2 files changed, 24 insertions, 20 deletions
diff --git a/Userland/Applications/QuickShow/CMakeLists.txt b/Userland/Applications/QuickShow/CMakeLists.txt index 8d2b46e217..7fa51f67d8 100644 --- a/Userland/Applications/QuickShow/CMakeLists.txt +++ b/Userland/Applications/QuickShow/CMakeLists.txt @@ -4,4 +4,4 @@ set(SOURCES ) serenity_app(QuickShow ICON filetype-image) -target_link_libraries(QuickShow LibGUI LibGfx) +target_link_libraries(QuickShow LibDesktop LibGUI LibGfx) diff --git a/Userland/Applications/QuickShow/main.cpp b/Userland/Applications/QuickShow/main.cpp index 6ed4df5585..1130729c41 100644 --- a/Userland/Applications/QuickShow/main.cpp +++ b/Userland/Applications/QuickShow/main.cpp @@ -28,6 +28,7 @@ #include <AK/URL.h> #include <LibCore/ArgsParser.h> #include <LibCore/MimeData.h> +#include <LibDesktop/Launcher.h> #include <LibGUI/Action.h> #include <LibGUI/Application.h> #include <LibGUI/BoxLayout.h> @@ -45,24 +46,33 @@ #include <LibGfx/Palette.h> #include <LibGfx/Rect.h> #include <serenity.h> -#include <spawn.h> #include <stdio.h> #include <string.h> int main(int argc, char** argv) { - if (pledge("stdio recvfd sendfd accept cpath rpath wpath unix cpath fattr proc exec thread", nullptr) < 0) { + if (pledge("stdio recvfd sendfd accept rpath wpath cpath unix fattr thread", nullptr) < 0) { perror("pledge"); return 1; } auto app = GUI::Application::construct(argc, argv); - if (pledge("stdio recvfd sendfd accept cpath rpath wpath proc exec thread", nullptr) < 0) { + if (pledge("stdio recvfd sendfd accept cpath rpath wpath unix thread", nullptr) < 0) { perror("pledge"); return 1; } + if (!Desktop::Launcher::add_allowed_handler_with_any_url("/bin/QuickShow")) { + warnln("Failed to set up allowed launch URLs"); + return 1; + } + + if (!Desktop::Launcher::seal_allowlist()) { + warnln("Failed to seal allowed launch URLs"); + return 1; + } + auto app_icon = GUI::Icon::default_icon("filetype-image"); const char* path = nullptr; @@ -106,24 +116,18 @@ int main(int argc, char** argv) widget.on_drop = [&](auto& event) { window->move_to_front(); - if (event.mime_data().has_urls()) { - auto urls = event.mime_data().urls(); + if (!event.mime_data().has_urls()) + return; - if (!urls.is_empty()) { - auto url = urls.first(); - widget.load_from_file(url.path()); - } + auto urls = event.mime_data().urls(); - pid_t child; - for (size_t i = 1; i < urls.size(); ++i) { - const char* argv[] = { "/bin/QuickShow", urls[i].path().characters(), nullptr }; - if ((errno = posix_spawn(&child, "/bin/QuickShow", nullptr, nullptr, const_cast<char**>(argv), environ))) { - perror("posix_spawn"); - } else { - if (disown(child) < 0) - perror("disown"); - } - } + if (urls.is_empty()) + return; + + widget.load_from_file(urls.first().path()); + + for (size_t i = 1; i < urls.size(); ++i) { + Desktop::Launcher::open(URL::create_with_file_protocol(urls[i].path().characters()), "/bin/QuickShow"); } }; widget.on_doubleclick = [&] { |