mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
Userland: Use GUI::Process::spawn_or_show_error() for spawn() from a GUI
This commit is contained in:
parent
2f2671f2d3
commit
7c8541b914
Notes:
sideshowbarker
2024-07-17 10:39:48 +09:00
Author: https://github.com/MacDue
Commit: 7c8541b914
Pull-request: https://github.com/SerenityOS/serenity/pull/13999
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/linusg
7 changed files with 39 additions and 26 deletions
|
@ -6,9 +6,9 @@
|
|||
*/
|
||||
|
||||
#include "KeymapStatusWindow.h"
|
||||
#include <LibCore/Process.h>
|
||||
#include <LibGUI/ConnectionToWindowMangerServer.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/Process.h>
|
||||
#include <LibKeyboard/CharacterMap.h>
|
||||
|
||||
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()
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include "Tab.h"
|
||||
#include <Applications/Browser/BrowserWindowGML.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/Process.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibGUI/AboutDialog.h>
|
||||
|
@ -27,6 +26,7 @@
|
|||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/Menubar.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
#include <LibGUI/Process.h>
|
||||
#include <LibGUI/SeparatorWidget.h>
|
||||
#include <LibGUI/Statusbar.h>
|
||||
#include <LibGUI/TabWidget.h>
|
||||
|
@ -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));
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
|
||||
#include <AK/QuickSort.h>
|
||||
#include <LibCore/Process.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibDesktop/AppFile.h>
|
||||
#include <LibGUI/Application.h>
|
||||
|
@ -14,6 +13,7 @@
|
|||
#include <LibGUI/IconView.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/Model.h>
|
||||
#include <LibGUI/Process.h>
|
||||
#include <LibGUI/Statusbar.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibMain/Main.h>
|
||||
|
@ -104,7 +104,7 @@ ErrorOr<int> 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<GUI::Statusbar>());
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <LibConfig/Listener.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/Process.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibDesktop/Launcher.h>
|
||||
#include <LibGUI/Action.h>
|
||||
|
@ -27,6 +26,7 @@
|
|||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/Menubar.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
#include <LibGUI/Process.h>
|
||||
#include <LibGUI/TextBox.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
#include <LibGUI/Window.h>
|
||||
|
@ -328,7 +328,7 @@ ErrorOr<int> 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<int> 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));
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
#include <Applications/Welcome/WelcomeWindowGML.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Process.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/CheckBox.h>
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/Process.h>
|
||||
#include <LibGfx/Font/BitmapFont.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <LibMarkdown/Document.h>
|
||||
|
@ -53,8 +53,8 @@ WelcomeWidget::WelcomeWidget()
|
|||
|
||||
m_help_button = *find_descendant_of_type_named<GUI::Button>("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<GUI::Button>("new_button");
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
#include "ClockWidget.h"
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/Process.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/Process.h>
|
||||
#include <LibGUI/SeparatorWidget.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibGfx/Font/FontDatabase.h>
|
||||
|
@ -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");
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue