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

Chess: Port to LibMain

Simplified two pledge() and five unveil() by using TRY().
This commit is contained in:
Pedro Pereira 2021-11-22 22:44:07 +00:00 committed by Andreas Kling
parent b65a039db7
commit 55db1811c7
2 changed files with 12 additions and 36 deletions

View file

@ -13,4 +13,4 @@ set(SOURCES
) )
serenity_app(Chess ICON app-chess) serenity_app(Chess ICON app-chess)
target_link_libraries(Chess LibChess LibConfig LibGUI LibCore) target_link_libraries(Chess LibChess LibConfig LibGUI LibCore LibMain)

View file

@ -16,53 +16,29 @@
#include <LibGUI/Menubar.h> #include <LibGUI/Menubar.h>
#include <LibGUI/MessageBox.h> #include <LibGUI/MessageBox.h>
#include <LibGUI/Window.h> #include <LibGUI/Window.h>
#include <unistd.h> #include <LibMain/Main.h>
#include <LibSystem/Wrappers.h>
int main(int argc, char** argv) ErrorOr<int> serenity_main(Main::Arguments arguments)
{ {
if (pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec unix", nullptr) < 0) { TRY(System::pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec unix", nullptr));
perror("pledge");
return 1;
}
auto app = GUI::Application::construct(argc, argv); auto app = GUI::Application::construct(arguments.argc, arguments.argv);
Config::pledge_domains("Chess"); Config::pledge_domains("Chess");
if (pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec", nullptr) < 0) { TRY(System::pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec", nullptr));
perror("pledge");
return 1;
}
auto app_icon = GUI::Icon::default_icon("app-chess"); auto app_icon = GUI::Icon::default_icon("app-chess");
auto window = GUI::Window::construct(); auto window = GUI::Window::construct();
auto& widget = window->set_main_widget<ChessWidget>(); auto& widget = window->set_main_widget<ChessWidget>();
if (unveil("/res", "r") < 0) { TRY(System::unveil("/res", "r"));
perror("unveil"); TRY(System::unveil("/bin/ChessEngine", "x"));
return 1; TRY(System::unveil("/etc/passwd", "r"));
} TRY(System::unveil(Core::StandardPaths::home_directory().characters(), "wcbr"));
TRY(System::unveil(nullptr, nullptr));
if (unveil("/bin/ChessEngine", "x") < 0) {
perror("unveil");
return 1;
}
if (unveil("/etc/passwd", "r") < 0) {
perror("unveil");
return 1;
}
if (unveil(Core::StandardPaths::home_directory().characters(), "wcbr") < 0) {
perror("unveil");
return 1;
}
if (unveil(nullptr, nullptr) < 0) {
perror("unveil");
return 1;
}
auto size = Config::read_i32("Chess", "Display", "size", 512); auto size = Config::read_i32("Chess", "Display", "size", 512);
window->set_title("Chess"); window->set_title("Chess");