From 4283702fb859538084d117bf2bbef25ce58fd004 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 24 Nov 2021 00:11:56 +0100 Subject: [PATCH] Playground: Port to LibMain :^) --- Userland/DevTools/Playground/CMakeLists.txt | 2 +- Userland/DevTools/Playground/main.cpp | 27 +++++++-------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/Userland/DevTools/Playground/CMakeLists.txt b/Userland/DevTools/Playground/CMakeLists.txt index 8b8a2604ebb..9490122ff35 100644 --- a/Userland/DevTools/Playground/CMakeLists.txt +++ b/Userland/DevTools/Playground/CMakeLists.txt @@ -9,4 +9,4 @@ set(SOURCES ) serenity_app(Playground ICON app-playground) -target_link_libraries(Playground LibDesktop LibGUI) +target_link_libraries(Playground LibDesktop LibGUI LibMain) diff --git a/Userland/DevTools/Playground/main.cpp b/Userland/DevTools/Playground/main.cpp index 78f51c7fa4e..f35f5543c28 100644 --- a/Userland/DevTools/Playground/main.cpp +++ b/Userland/DevTools/Playground/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,7 @@ #include #include #include +#include #include #include @@ -58,20 +60,12 @@ void UnregisteredWidget::paint_event(GUI::PaintEvent& event) } -int main(int argc, char** argv) +ErrorOr serenity_main(Main::Arguments arguments) { - if (pledge("stdio thread recvfd sendfd cpath rpath wpath unix", nullptr) < 0) { - perror("pledge"); - return 1; - } - - auto app = GUI::Application::construct(argc, argv); - - if (pledge("stdio thread recvfd sendfd rpath cpath wpath unix", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(Core::System::pledge("stdio thread recvfd sendfd cpath rpath wpath unix", nullptr)); + auto app = TRY(GUI::Application::try_create(arguments)); + TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath unix", nullptr)); if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls( "/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/Playground.md") }) @@ -80,18 +74,15 @@ int main(int argc, char** argv) return 1; } - if (pledge("stdio thread recvfd sendfd rpath cpath wpath", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath", nullptr)); const char* path = nullptr; Core::ArgsParser args_parser; args_parser.add_positional_argument(path, "GML file to edit", "file", Core::ArgsParser::Required::No); - args_parser.parse(argc, argv); + args_parser.parse(arguments); auto app_icon = GUI::Icon::default_icon("app-playground"); - auto window = GUI::Window::construct(); + auto window = TRY(GUI::Window::try_create()); window->set_title("GML Playground"); window->set_icon(app_icon.bitmap_for_size(16)); window->resize(800, 600);