summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorpbrw <borowski.pb1@gmail.com>2021-11-25 02:54:16 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-25 08:49:31 +0100
commit79bc587d03f113310c41320e1951b152c6e493b4 (patch)
tree61543b8edf7e1a34a88d8e105106c112a4ad2767 /Userland
parent370c5986ab3531b638dd5cb92a7b5c1c4094eb25 (diff)
downloadserenity-79bc587d03f113310c41320e1951b152c6e493b4.zip
Cube: Use TRY() a lot more :^)
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Demos/Cube/CMakeLists.txt2
-rw-r--r--Userland/Demos/Cube/Cube.cpp59
2 files changed, 26 insertions, 35 deletions
diff --git a/Userland/Demos/Cube/CMakeLists.txt b/Userland/Demos/Cube/CMakeLists.txt
index 24e81b2556..f3c136e74d 100644
--- a/Userland/Demos/Cube/CMakeLists.txt
+++ b/Userland/Demos/Cube/CMakeLists.txt
@@ -8,4 +8,4 @@ set(SOURCES
)
serenity_app(Cube ICON app-cube)
-target_link_libraries(Cube LibGUI)
+target_link_libraries(Cube LibGUI LibMain)
diff --git a/Userland/Demos/Cube/Cube.cpp b/Userland/Demos/Cube/Cube.cpp
index cf6ea1e396..c9914e03e1 100644
--- a/Userland/Demos/Cube/Cube.cpp
+++ b/Userland/Demos/Cube/Cube.cpp
@@ -6,6 +6,7 @@
#include <LibCore/ArgsParser.h>
#include <LibCore/ElapsedTimer.h>
+#include <LibCore/System.h>
#include <LibGUI/Application.h>
#include <LibGUI/Icon.h>
#include <LibGUI/Label.h>
@@ -17,6 +18,7 @@
#include <LibGfx/Bitmap.h>
#include <LibGfx/Matrix4x4.h>
#include <LibGfx/Vector3.h>
+#include <LibMain/Main.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -198,31 +200,20 @@ void Cube::set_show_window_frame(bool show)
w.set_alpha_hit_threshold(m_show_window_frame ? 0 : 1);
}
-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));
Core::ArgsParser parser;
parser.set_general_help("Create a window with a spinning cube.");
parser.add_option(flag_hide_window_frame, "Hide window frame", "hide-window", 'h');
- parser.parse(argc, argv);
+ parser.parse(arguments);
- auto window = GUI::Window::construct();
+ auto window = TRY(GUI::Window::try_create());
window->set_double_buffering_enabled(true);
window->set_title("Cube");
window->set_resizable(false);
@@ -230,31 +221,31 @@ int main(int argc, char** argv)
window->set_has_alpha_channel(true);
window->set_alpha_hit_threshold(1);
- auto& cube = window->set_main_widget<Cube>();
+ auto cube = TRY(window->try_set_main_widget<Cube>());
- auto& time = cube.add<GUI::Label>();
- time.set_relative_rect({ 0, 4, 40, 10 });
- time.move_by({ window->width() - time.width(), 0 });
- cube.set_stat_label(time);
+ auto time = TRY(cube->try_add<GUI::Label>());
+ time->set_relative_rect({ 0, 4, 40, 10 });
+ time->move_by({ window->width() - time->width(), 0 });
+ cube->set_stat_label(time);
auto app_icon = GUI::Icon::default_icon("app-cube");
window->set_icon(app_icon.bitmap_for_size(16));
- auto& file_menu = window->add_menu("&File");
+ auto file_menu = TRY(window->try_add_menu("&File"));
auto show_window_frame_action = GUI::Action::create_checkable("Show Window &Frame", [&](auto& action) {
- cube.set_show_window_frame(action.is_checked());
+ cube->set_show_window_frame(action.is_checked());
});
- cube.set_show_window_frame(!flag_hide_window_frame);
- show_window_frame_action->set_checked(cube.show_window_frame());
- file_menu.add_action(move(show_window_frame_action));
- file_menu.add_separator();
- file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));
- auto& help_menu = window->add_menu("&Help");
- help_menu.add_action(GUI::CommonActions::make_about_action("Cube Demo", app_icon, window));
+ cube->set_show_window_frame(!flag_hide_window_frame);
+ show_window_frame_action->set_checked(cube->show_window_frame());
+ TRY(file_menu->try_add_action(move(show_window_frame_action)));
+ TRY(file_menu->try_add_separator());
+ TRY(file_menu->try_add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })));
+ auto help_menu = TRY(window->try_add_menu("&Help"));
+ TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action("Cube Demo", app_icon, window)));
- cube.on_context_menu_request = [&](auto& event) {
- file_menu.popup(event.screen_position());
+ cube->on_context_menu_request = [&](auto& event) {
+ file_menu->popup(event.screen_position());
};
window->show();