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

Snake: Port to LibMain

Simplified two pledge() and two unveil() by using TRY().
This commit is contained in:
Pedro Pereira 2021-11-23 10:41:55 +00:00 committed by Andreas Kling
parent 02a7cfaad6
commit c4e49e1955
2 changed files with 9 additions and 21 deletions

View file

@ -10,4 +10,4 @@ set(SOURCES
) )
serenity_app(Snake ICON app-snake) serenity_app(Snake ICON app-snake)
target_link_libraries(Snake LibGUI LibConfig) target_link_libraries(Snake LibGUI LibConfig LibMain)

View file

@ -6,6 +6,7 @@
#include "SnakeGame.h" #include "SnakeGame.h"
#include <LibConfig/Client.h> #include <LibConfig/Client.h>
#include <LibCore/System.h>
#include <LibGUI/Action.h> #include <LibGUI/Action.h>
#include <LibGUI/Application.h> #include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h> #include <LibGUI/BoxLayout.h>
@ -14,34 +15,21 @@
#include <LibGUI/Menu.h> #include <LibGUI/Menu.h>
#include <LibGUI/Menubar.h> #include <LibGUI/Menubar.h>
#include <LibGUI/Window.h> #include <LibGUI/Window.h>
#include <LibMain/Main.h>
#include <stdio.h> #include <stdio.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(Core::System::pledge("stdio rpath recvfd sendfd unix", nullptr));
perror("pledge");
return 1;
}
auto app = GUI::Application::construct(argc, argv); auto app = GUI::Application::construct(arguments);
Config::pledge_domains("Snake"); Config::pledge_domains("Snake");
if (pledge("stdio rpath recvfd sendfd", nullptr) < 0) { TRY(Core::System::pledge("stdio rpath recvfd sendfd", nullptr));
perror("pledge");
return 1;
}
if (unveil("/res", "r") < 0) { TRY(Core::System::unveil("/res", "r"));
perror("unveil"); TRY(Core::System::unveil(nullptr, nullptr));
return 1;
}
if (unveil(nullptr, nullptr) < 0) {
perror("unveil");
return 1;
}
auto app_icon = GUI::Icon::default_icon("app-snake"); auto app_icon = GUI::Icon::default_icon("app-snake");