Serenity Operating System
at master 75 lines 2.6 kB view raw
1/* 2 * Copyright (c) 2022, Oleg Kosenkov <oleg@kosenkov.ca> 3 * Copyright (c) 2022, the SerenityOS developers. 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#include "ColorLines.h" 9#include <AK/URL.h> 10#include <LibConfig/Client.h> 11#include <LibCore/System.h> 12#include <LibDesktop/Launcher.h> 13#include <LibGUI/Action.h> 14#include <LibGUI/Application.h> 15#include <LibGUI/Icon.h> 16#include <LibGUI/Menu.h> 17#include <LibGUI/Menubar.h> 18#include <LibGUI/Window.h> 19#include <LibMain/Main.h> 20 21ErrorOr<int> serenity_main(Main::Arguments arguments) 22{ 23 TRY(Core::System::pledge("stdio rpath recvfd sendfd unix")); 24 25 auto app = TRY(GUI::Application::try_create(arguments)); 26 27 auto const app_name = "ColorLines"sv; 28 auto const title = "Color Lines"sv; 29 auto const man_file = "/usr/share/man/man6/ColorLines.md"sv; 30 31 Config::pledge_domain(app_name); 32 33 TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_scheme(man_file) })); 34 TRY(Desktop::Launcher::seal_allowlist()); 35 36 TRY(Core::System::pledge("stdio rpath recvfd sendfd")); 37 38 TRY(Core::System::unveil("/tmp/session/%sid/portal/launch", "rw")); 39 TRY(Core::System::unveil("/res", "r")); 40 TRY(Core::System::unveil(nullptr, nullptr)); 41 42 auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-colorlines"sv)); 43 44 auto window = TRY(GUI::Window::try_create()); 45 46 window->set_double_buffering_enabled(false); 47 window->set_title(title); 48 window->resize(436, 481); 49 window->set_resizable(false); 50 51 auto game = TRY(window->set_main_widget<ColorLines>(app_name)); 52 53 auto game_menu = TRY(window->try_add_menu("&Game")); 54 55 TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) { 56 game->reset(); 57 }))); 58 TRY(game_menu->try_add_separator()); 59 TRY(game_menu->try_add_action(GUI::CommonActions::make_quit_action([](auto&) { 60 GUI::Application::the()->quit(); 61 }))); 62 63 auto help_menu = TRY(window->try_add_menu("&Help")); 64 TRY(help_menu->try_add_action(GUI::CommonActions::make_command_palette_action(window))); 65 TRY(help_menu->try_add_action(GUI::CommonActions::make_help_action([&man_file](auto&) { 66 Desktop::Launcher::open(URL::create_with_file_scheme(man_file), "/bin/Help"); 67 }))); 68 TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action(title, app_icon, window))); 69 70 window->show(); 71 72 window->set_icon(app_icon.bitmap_for_size(16)); 73 74 return app->exec(); 75}