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

Userland: Use GUI::Process::spawn_or_show_error() for spawn() from a GUI

This commit is contained in:
MacDue 2022-05-11 19:41:33 +01:00 committed by Linus Groh
parent 2f2671f2d3
commit 7c8541b914
7 changed files with 39 additions and 26 deletions

View file

@ -11,7 +11,6 @@
#include <LibConfig/Client.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Process.h>
#include <LibCore/StandardPaths.h>
#include <LibCore/System.h>
#include <LibDesktop/AppFile.h>
@ -21,6 +20,7 @@
#include <LibGUI/ConnectionToWindowMangerServer.h>
#include <LibGUI/ConnectionToWindowServer.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Process.h>
#include <LibGfx/SystemTheme.h>
#include <LibMain/Main.h>
#include <WindowServer/Window.h>
@ -32,7 +32,15 @@
#include <unistd.h>
static ErrorOr<Vector<String>> discover_apps_and_categories();
static ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu();
struct WindowRefence {
GUI::Window* window { nullptr };
GUI::Window* get()
{
VERIFY(window);
return window;
}
};
static ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu(WindowRefence&);
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
@ -53,10 +61,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio recvfd sendfd proc exec rpath"));
auto menu = TRY(build_system_menu());
// FIXME: Have to awkwardly pass a reference to the window pointer to build_system_menu(), that will be resolved later.
// (It is always valid at use)
WindowRefence window_ref {};
auto menu = TRY(build_system_menu(window_ref));
menu->realize_menu_if_needed();
auto window = TRY(TaskbarWindow::try_create(move(menu)));
window_ref.window = window.ptr();
window->show();
window->make_window_manager(
@ -103,13 +116,13 @@ ErrorOr<Vector<String>> discover_apps_and_categories()
return sorted_app_categories;
}
ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu()
ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu(WindowRefence& window_ref)
{
Vector<String> const sorted_app_categories = TRY(discover_apps_and_categories());
auto system_menu = TRY(GUI::Menu::try_create("\xE2\x9A\xA1")); // HIGH VOLTAGE SIGN
system_menu->add_action(GUI::Action::create("&About SerenityOS", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/ladyball.png").release_value_but_fixme_should_propagate_errors(), [](auto&) {
MUST(Core::Process::spawn("/bin/About"sv));
system_menu->add_action(GUI::Action::create("&About SerenityOS", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/ladyball.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
GUI::Process::spawn_or_show_error(window_ref.get(), "/bin/About"sv);
}));
system_menu->add_separator();
@ -228,13 +241,13 @@ ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu()
}
}
system_menu->add_action(GUI::Action::create("&Settings", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-settings.png").release_value_but_fixme_should_propagate_errors(), [](auto&) {
MUST(Core::Process::spawn("/bin/Settings"sv));
system_menu->add_action(GUI::Action::create("&Settings", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-settings.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
GUI::Process::spawn_or_show_error(window_ref.get(), "/bin/Settings"sv);
}));
system_menu->add_separator();
system_menu->add_action(GUI::Action::create("&Help", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-help.png").release_value_but_fixme_should_propagate_errors(), [](auto&) {
MUST(Core::Process::spawn("/bin/Help"sv));
system_menu->add_action(GUI::Action::create("&Help", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-help.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
GUI::Process::spawn_or_show_error(window_ref.get(), "/bin/Help"sv);
}));
system_menu->add_action(GUI::Action::create("&Run...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-run.png").release_value_but_fixme_should_propagate_errors(), [](auto&) {
posix_spawn_file_actions_t spawn_actions;