mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
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 :^)
This commit is contained in:
parent
612a5225fa
commit
8c0723960b
2 changed files with 24 additions and 20 deletions
|
@ -4,4 +4,4 @@ set(SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_app(QuickShow ICON filetype-image)
|
serenity_app(QuickShow ICON filetype-image)
|
||||||
target_link_libraries(QuickShow LibGUI LibGfx)
|
target_link_libraries(QuickShow LibDesktop LibGUI LibGfx)
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/MimeData.h>
|
#include <LibCore/MimeData.h>
|
||||||
|
#include <LibDesktop/Launcher.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
|
@ -45,24 +46,33 @@
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
#include <serenity.h>
|
#include <serenity.h>
|
||||||
#include <spawn.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
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");
|
perror("pledge");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto app = GUI::Application::construct(argc, argv);
|
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");
|
perror("pledge");
|
||||||
return 1;
|
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");
|
auto app_icon = GUI::Icon::default_icon("filetype-image");
|
||||||
|
|
||||||
const char* path = nullptr;
|
const char* path = nullptr;
|
||||||
|
@ -106,24 +116,18 @@ int main(int argc, char** argv)
|
||||||
widget.on_drop = [&](auto& event) {
|
widget.on_drop = [&](auto& event) {
|
||||||
window->move_to_front();
|
window->move_to_front();
|
||||||
|
|
||||||
if (event.mime_data().has_urls()) {
|
if (!event.mime_data().has_urls())
|
||||||
|
return;
|
||||||
|
|
||||||
auto urls = event.mime_data().urls();
|
auto urls = event.mime_data().urls();
|
||||||
|
|
||||||
if (!urls.is_empty()) {
|
if (urls.is_empty())
|
||||||
auto url = urls.first();
|
return;
|
||||||
widget.load_from_file(url.path());
|
|
||||||
}
|
widget.load_from_file(urls.first().path());
|
||||||
|
|
||||||
pid_t child;
|
|
||||||
for (size_t i = 1; i < urls.size(); ++i) {
|
for (size_t i = 1; i < urls.size(); ++i) {
|
||||||
const char* argv[] = { "/bin/QuickShow", urls[i].path().characters(), nullptr };
|
Desktop::Launcher::open(URL::create_with_file_protocol(urls[i].path().characters()), "/bin/QuickShow");
|
||||||
if ((errno = posix_spawn(&child, "/bin/QuickShow", nullptr, nullptr, const_cast<char**>(argv), environ))) {
|
|
||||||
perror("posix_spawn");
|
|
||||||
} else {
|
|
||||||
if (disown(child) < 0)
|
|
||||||
perror("disown");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
widget.on_doubleclick = [&] {
|
widget.on_doubleclick = [&] {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue