diff options
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Services/Taskbar/ShutdownDialog.cpp | 15 | ||||
-rw-r--r-- | Userland/Services/Taskbar/ShutdownDialog.h | 8 | ||||
-rw-r--r-- | Userland/Services/Taskbar/main.cpp | 17 |
3 files changed, 17 insertions, 23 deletions
diff --git a/Userland/Services/Taskbar/ShutdownDialog.cpp b/Userland/Services/Taskbar/ShutdownDialog.cpp index fa89958c22..80471a9599 100644 --- a/Userland/Services/Taskbar/ShutdownDialog.cpp +++ b/Userland/Services/Taskbar/ShutdownDialog.cpp @@ -18,24 +18,23 @@ struct Option { DeprecatedString title; - Vector<char const*> cmd; + ShutdownDialog::Command command; bool enabled; bool default_action; }; -static Vector<Option> const options = { - { "Power off computer", { "/bin/shutdown", "--now", nullptr }, true, true }, - { "Reboot", { "/bin/reboot", nullptr }, true, false }, - { "Log out", { "/bin/logout", nullptr }, true, false }, +static Array const options = { + Option { "Power off computer", { "/bin/shutdown"sv, { "--now" } }, true, true }, + Option { "Reboot", { "/bin/reboot"sv, {} }, true, false }, + Option { "Log out", { "/bin/logout"sv, {} }, true, false }, }; -Vector<char const*> ShutdownDialog::show() +Optional<ShutdownDialog::Command const&> ShutdownDialog::show() { auto dialog = ShutdownDialog::construct(); auto rc = dialog->exec(); if (rc == ExecResult::OK && dialog->m_selected_option != -1) - return options[dialog->m_selected_option].cmd; - + return options[dialog->m_selected_option].command; return {}; } diff --git a/Userland/Services/Taskbar/ShutdownDialog.h b/Userland/Services/Taskbar/ShutdownDialog.h index 8a7fe14019..71d825feec 100644 --- a/Userland/Services/Taskbar/ShutdownDialog.h +++ b/Userland/Services/Taskbar/ShutdownDialog.h @@ -6,6 +6,7 @@ #pragma once +#include <AK/Optional.h> #include <AK/Vector.h> #include <LibGUI/Dialog.h> @@ -13,7 +14,12 @@ class ShutdownDialog : public GUI::Dialog { C_OBJECT(ShutdownDialog); public: - static Vector<char const*> show(); + struct Command { + StringView executable; + Vector<char const*, 2> arguments; + }; + + static Optional<Command const&> show(); private: ShutdownDialog(); diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp index ee44ae766f..29b0ede8b8 100644 --- a/Userland/Services/Taskbar/main.cpp +++ b/Userland/Services/Taskbar/main.cpp @@ -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; |