1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:27:45 +00:00

Taskbar: Use Process::spawn_or_show_error() for shutdown actions

This commit is contained in:
MacDue 2023-03-13 20:35:34 +00:00 committed by Linus Groh
parent e46b9c189e
commit 43529ea25e
3 changed files with 17 additions and 23 deletions

View file

@ -31,7 +31,6 @@
#include <WindowServer/Window.h>
#include <serenity.h>
#include <signal.h>
#include <spawn.h>
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
@ -254,19 +253,9 @@ ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu(GUI::Window& window)
GUI::Process::spawn_or_show_error(&window, "/bin/Run"sv, ReadonlySpan<StringView> {}, Core::StandardPaths::home_directory());
}));
system_menu->add_separator();
system_menu->add_action(GUI::Action::create("E&xit...", TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/power.png"sv)), [](auto&) {
auto command = ShutdownDialog::show();
if (command.size() == 0)
return;
pid_t child_pid;
if ((errno = posix_spawn(&child_pid, command[0], nullptr, nullptr, const_cast<char**>(command.data()), environ))) {
perror("posix_spawn");
} else {
if (disown(child_pid) < 0)
perror("disown");
}
system_menu->add_action(GUI::Action::create("E&xit...", TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/power.png"sv)), [&](auto&) {
if (auto command = ShutdownDialog::show(); command.has_value())
GUI::Process::spawn_or_show_error(&window, command->executable, command->arguments);
}));
return system_menu;