summaryrefslogtreecommitdiff
path: root/Userland/Demos
diff options
context:
space:
mode:
authorpbrw <borowski.pb1@gmail.com>2021-11-25 02:54:54 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-25 08:49:31 +0100
commitabf86b750100cc97bef0703c0e675bd2c30e4c2b (patch)
treeaeb3523a251cfea9915def542a70697864787ccb /Userland/Demos
parent2642abb77309c232b98b9176877454ca845810e2 (diff)
downloadserenity-abf86b750100cc97bef0703c0e675bd2c30e4c2b.zip
Fire: Use TRY() a lot more :^)
Diffstat (limited to 'Userland/Demos')
-rw-r--r--Userland/Demos/Fire/CMakeLists.txt2
-rw-r--r--Userland/Demos/Fire/Fire.cpp39
2 files changed, 16 insertions, 25 deletions
diff --git a/Userland/Demos/Fire/CMakeLists.txt b/Userland/Demos/Fire/CMakeLists.txt
index 31e7aaf90f..67480837c4 100644
--- a/Userland/Demos/Fire/CMakeLists.txt
+++ b/Userland/Demos/Fire/CMakeLists.txt
@@ -8,4 +8,4 @@ set(SOURCES
)
serenity_app(Fire ICON app-fire)
-target_link_libraries(Fire LibGUI LibCore LibGfx)
+target_link_libraries(Fire LibGUI LibCore LibGfx LibMain)
diff --git a/Userland/Demos/Fire/Fire.cpp b/Userland/Demos/Fire/Fire.cpp
index 7e9fdbc155..63f98edd5c 100644
--- a/Userland/Demos/Fire/Fire.cpp
+++ b/Userland/Demos/Fire/Fire.cpp
@@ -23,6 +23,7 @@
*/
#include <LibCore/ElapsedTimer.h>
+#include <LibCore/System.h>
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
#include <LibGUI/Frame.h>
@@ -33,6 +34,7 @@
#include <LibGUI/Painter.h>
#include <LibGUI/Window.h>
#include <LibGfx/Bitmap.h>
+#include <LibMain/Main.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@@ -195,40 +197,29 @@ void Fire::mouseup_event(GUI::MouseEvent& event)
return GUI::Widget::mouseup_event(event);
}
-int main(int argc, char** argv)
+ErrorOr<int> serenity_main(Main::Arguments arguments)
{
- auto app = GUI::Application::construct(argc, argv);
+ auto app = TRY(GUI::Application::try_create(arguments));
- if (pledge("stdio recvfd sendfd rpath", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
-
- if (unveil("/res", "r") < 0) {
- perror("unveil");
- return 1;
- }
-
- if (unveil(nullptr, nullptr) < 0) {
- perror("unveil");
- return 1;
- }
+ TRY(Core::System::pledge("stdio recvfd sendfd rpath", nullptr));
+ TRY(Core::System::unveil("/res", "r"));
+ TRY(Core::System::unveil(nullptr, nullptr));
- auto window = GUI::Window::construct();
+ auto window = TRY(GUI::Window::try_create());
window->set_double_buffering_enabled(false);
window->set_title("Fire");
window->set_resizable(false);
window->resize(FIRE_WIDTH * 2 + 4, FIRE_HEIGHT * 2 + 4);
- auto& file_menu = window->add_menu("&File");
- file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));
+ auto file_menu = TRY(window->try_add_menu("&File"));
+ TRY(file_menu->try_add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })));
- auto& fire = window->set_main_widget<Fire>();
+ auto fire = TRY(window->try_set_main_widget<Fire>());
- auto& time = fire.add<GUI::Label>();
- time.set_relative_rect({ 0, 4, 40, 10 });
- time.move_by({ window->width() - time.width(), 0 });
- fire.set_stat_label(time);
+ auto time = TRY(fire->try_add<GUI::Label>());
+ time->set_relative_rect({ 0, 4, 40, 10 });
+ time->move_by({ window->width() - time->width(), 0 });
+ fire->set_stat_label(time);
window->show();