diff --git a/Userland/Applets/Keymap/KeymapStatusWindow.cpp b/Userland/Applets/Keymap/KeymapStatusWindow.cpp index ae4c1bd068..850198682b 100644 --- a/Userland/Applets/Keymap/KeymapStatusWindow.cpp +++ b/Userland/Applets/Keymap/KeymapStatusWindow.cpp @@ -6,9 +6,9 @@ */ #include "KeymapStatusWindow.h" -#include #include #include +#include #include void KeymapStatusWidget::mousedown_event(GUI::MouseEvent& event) @@ -16,7 +16,7 @@ void KeymapStatusWidget::mousedown_event(GUI::MouseEvent& event) if (event.button() != GUI::MouseButton::Primary) return; - MUST(Core::Process::spawn("/bin/KeyboardSettings")); + GUI::Process::spawn_or_show_error(window(), "/bin/KeyboardSettings"); } KeymapStatusWindow::KeymapStatusWindow() diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index fd81e4263c..8f66fef667 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -16,7 +16,6 @@ #include "Tab.h" #include #include -#include #include #include #include @@ -27,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -301,8 +301,8 @@ void BrowserWindow::build_menus() settings_menu.add_separator(); auto open_settings_action = GUI::Action::create("&Settings", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png").release_value_but_fixme_should_propagate_errors(), - [](auto&) { - MUST(Core::Process::spawn("/bin/BrowserSettings")); + [this](auto&) { + GUI::Process::spawn_or_show_error(this, "/bin/BrowserSettings"); }); settings_menu.add_action(move(open_settings_action)); diff --git a/Userland/Applications/Settings/main.cpp b/Userland/Applications/Settings/main.cpp index 9d62b24a92..74368deef9 100644 --- a/Userland/Applications/Settings/main.cpp +++ b/Userland/Applications/Settings/main.cpp @@ -5,7 +5,6 @@ */ #include -#include #include #include #include @@ -14,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -104,7 +104,7 @@ ErrorOr serenity_main(Main::Arguments arguments) auto launch_origin_rect = icon_view->to_widget_rect(icon_view->content_rect(index)).translated(icon_view->screen_relative_rect().location()); setenv("__libgui_launch_origin_rect", String::formatted("{},{},{},{}", launch_origin_rect.x(), launch_origin_rect.y(), launch_origin_rect.width(), launch_origin_rect.height()).characters(), 1); - MUST(Core::Process::spawn(executable)); + GUI::Process::spawn_or_show_error(window, executable); }; auto statusbar = TRY(main_widget->try_add()); diff --git a/Userland/Applications/Terminal/main.cpp b/Userland/Applications/Terminal/main.cpp index 3ebdae7b11..8a20d59897 100644 --- a/Userland/Applications/Terminal/main.cpp +++ b/Userland/Applications/Terminal/main.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -27,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -328,7 +328,7 @@ ErrorOr serenity_main(Main::Arguments arguments) auto open_settings_action = GUI::Action::create("&Settings", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) { - MUST(Core::Process::spawn("/bin/TerminalSettings")); + GUI::Process::spawn_or_show_error(window, "/bin/TerminalSettings"); }); TRY(terminal->context_menu().try_add_separator()); @@ -336,7 +336,7 @@ ErrorOr serenity_main(Main::Arguments arguments) auto file_menu = TRY(window->try_add_menu("&File")); TRY(file_menu->try_add_action(GUI::Action::create("Open New &Terminal", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-terminal.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) { - MUST(Core::Process::spawn("/bin/Terminal")); + GUI::Process::spawn_or_show_error(window, "/bin/Terminal"); }))); TRY(file_menu->try_add_action(open_settings_action)); diff --git a/Userland/Applications/Welcome/WelcomeWidget.cpp b/Userland/Applications/Welcome/WelcomeWidget.cpp index 3ce0cacf6f..e580d0d717 100644 --- a/Userland/Applications/Welcome/WelcomeWidget.cpp +++ b/Userland/Applications/Welcome/WelcomeWidget.cpp @@ -9,12 +9,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include #include @@ -53,8 +53,8 @@ WelcomeWidget::WelcomeWidget() m_help_button = *find_descendant_of_type_named("help_button"); m_help_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/book-open.png").release_value_but_fixme_should_propagate_errors()); - m_help_button->on_click = [](auto) { - MUST(Core::Process::spawn("/bin/Help"sv)); + m_help_button->on_click = [&](auto) { + GUI::Process::spawn_or_show_error(window(), "/bin/Help"sv); }; m_new_button = *find_descendant_of_type_named("new_button"); diff --git a/Userland/Services/Taskbar/ClockWidget.cpp b/Userland/Services/Taskbar/ClockWidget.cpp index 0c5a0649f6..abbf982df9 100644 --- a/Userland/Services/Taskbar/ClockWidget.cpp +++ b/Userland/Services/Taskbar/ClockWidget.cpp @@ -6,8 +6,8 @@ #include "ClockWidget.h" #include -#include #include +#include #include #include #include @@ -153,8 +153,8 @@ ClockWidget::ClockWidget() m_calendar_launcher->set_fixed_size(24, 24); m_calendar_launcher->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-calendar.png").release_value_but_fixme_should_propagate_errors()); m_calendar_launcher->set_tooltip("Calendar"); - m_calendar_launcher->on_click = [](auto) { - MUST(Core::Process::spawn("/bin/Calendar")); + m_calendar_launcher->on_click = [this](auto) { + GUI::Process::spawn_or_show_error(window(), "/bin/Calendar"); }; } diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp index 852663946e..5778cd9042 100644 --- a/Userland/Services/Taskbar/main.cpp +++ b/Userland/Services/Taskbar/main.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -21,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -32,7 +32,15 @@ #include static ErrorOr> discover_apps_and_categories(); -static ErrorOr> build_system_menu(); +struct WindowRefence { + GUI::Window* window { nullptr }; + GUI::Window* get() + { + VERIFY(window); + return window; + } +}; +static ErrorOr> build_system_menu(WindowRefence&); ErrorOr serenity_main(Main::Arguments arguments) { @@ -53,10 +61,15 @@ ErrorOr 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> discover_apps_and_categories() return sorted_app_categories; } -ErrorOr> build_system_menu() +ErrorOr> build_system_menu(WindowRefence& window_ref) { Vector 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> 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;