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

2048: Port to LibMain

Simplified two pledge() and two unveil() by using TRY().
This commit is contained in:
Pedro Pereira 2021-11-22 22:29:16 +00:00 committed by Andreas Kling
parent 6e6228d40d
commit fb5ea617f1
2 changed files with 9 additions and 21 deletions

View file

@ -12,4 +12,4 @@ set(SOURCES
) )
serenity_app(2048 ICON app-2048) serenity_app(2048 ICON app-2048)
target_link_libraries(2048 LibConfig LibGUI) target_link_libraries(2048 LibConfig LibGUI LibMain)

View file

@ -19,40 +19,28 @@
#include <LibGUI/Statusbar.h> #include <LibGUI/Statusbar.h>
#include <LibGUI/Window.h> #include <LibGUI/Window.h>
#include <LibGfx/Painter.h> #include <LibGfx/Painter.h>
#include <LibMain/Main.h>
#include <LibSystem/Wrappers.h>
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <unistd.h>
int main(int argc, char** argv) ErrorOr<int> serenity_main(Main::Arguments arguments)
{ {
if (pledge("stdio rpath recvfd sendfd unix", nullptr) < 0) { TRY(System::pledge("stdio rpath recvfd sendfd unix", nullptr));
perror("pledge");
return 1;
}
srand(time(nullptr)); srand(time(nullptr));
auto app = GUI::Application::construct(argc, argv); auto app = GUI::Application::construct(arguments.argc, arguments.argv);
auto app_icon = GUI::Icon::default_icon("app-2048"); auto app_icon = GUI::Icon::default_icon("app-2048");
auto window = GUI::Window::construct(); auto window = GUI::Window::construct();
Config::pledge_domains("2048"); Config::pledge_domains("2048");
if (pledge("stdio rpath recvfd sendfd", nullptr) < 0) { TRY(System::pledge("stdio rpath recvfd sendfd", nullptr));
perror("pledge");
return 1;
}
if (unveil("/res", "r") < 0) { TRY(System::unveil("/res", "r"));
perror("unveil"); TRY(System::unveil(nullptr, nullptr));
return 1;
}
if (unveil(nullptr, nullptr) < 0) {
perror("unveil");
return 1;
}
size_t board_size = Config::read_i32("2048", "", "board_size", 4); size_t board_size = Config::read_i32("2048", "", "board_size", 4);
u32 target_tile = Config::read_i32("2048", "", "target_tile", 2048); u32 target_tile = Config::read_i32("2048", "", "target_tile", 2048);