summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Applications/Settings/CMakeLists.txt2
-rw-r--r--Userland/Applications/Settings/main.cpp52
2 files changed, 25 insertions, 29 deletions
diff --git a/Userland/Applications/Settings/CMakeLists.txt b/Userland/Applications/Settings/CMakeLists.txt
index edbabd23b2..772c0fbb3e 100644
--- a/Userland/Applications/Settings/CMakeLists.txt
+++ b/Userland/Applications/Settings/CMakeLists.txt
@@ -9,4 +9,4 @@ set(SOURCES
)
serenity_app(Settings ICON app-settings)
-target_link_libraries(Settings LibGUI LibDesktop)
+target_link_libraries(Settings LibGUI LibDesktop LibMain)
diff --git a/Userland/Applications/Settings/main.cpp b/Userland/Applications/Settings/main.cpp
index 15795d1835..7d470bb8d9 100644
--- a/Userland/Applications/Settings/main.cpp
+++ b/Userland/Applications/Settings/main.cpp
@@ -6,6 +6,7 @@
#include <AK/QuickSort.h>
#include <LibCore/Process.h>
+#include <LibCore/System.h>
#include <LibDesktop/AppFile.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
@@ -15,6 +16,7 @@
#include <LibGUI/Model.h>
#include <LibGUI/Statusbar.h>
#include <LibGUI/Window.h>
+#include <LibMain/Main.h>
#include <serenity.h>
#include <stdio.h>
#include <unistd.h>
@@ -66,62 +68,56 @@ private:
Vector<NonnullRefPtr<Desktop::AppFile>> m_apps;
};
-int main(int argc, char** argv)
+ErrorOr<int> serenity_main(Main::Arguments arguments)
{
- if (pledge("stdio thread recvfd sendfd rpath cpath wpath unix proc exec", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath unix proc exec", nullptr));
- auto app = GUI::Application::construct(argc, argv);
+ auto app = TRY(GUI::Application::try_create(arguments));
- if (pledge("stdio thread recvfd sendfd rpath cpath wpath proc exec", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath proc exec", nullptr));
auto app_icon = GUI::Icon::default_icon("app-settings");
- auto window = GUI::Window::construct();
+ auto window = TRY(GUI::Window::try_create());
window->set_title("Settings");
window->resize(360, 240);
- auto& file_menu = window->add_menu("&File");
- file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
+ auto file_menu = TRY(window->try_add_menu("&File"));
+ 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("Settings", app_icon, window));
+ auto help_menu = TRY(window->try_add_menu("&Help"));
+ TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action("Settings", app_icon, window)));
- auto& main_widget = window->set_main_widget<GUI::Widget>();
- main_widget.set_fill_with_background_color(true);
- main_widget.set_layout<GUI::VerticalBoxLayout>();
+ auto main_widget = TRY(window->try_set_main_widget<GUI::Widget>());
+ main_widget->set_fill_with_background_color(true);
+ main_widget->set_layout<GUI::VerticalBoxLayout>();
- auto& icon_view = main_widget.add<GUI::IconView>();
- icon_view.set_should_hide_unnecessary_scrollbars(true);
+ auto icon_view = TRY(main_widget->try_add<GUI::IconView>());
+ icon_view->set_should_hide_unnecessary_scrollbars(true);
auto model = adopt_ref(*new SettingsAppsModel);
- icon_view.set_model(*model);
+ icon_view->set_model(*model);
- icon_view.on_activation = [&](GUI::ModelIndex const& index) {
+ icon_view->on_activation = [&](GUI::ModelIndex const& index) {
auto executable = model->data(index, GUI::ModelRole::Custom).as_string();
- auto launch_origin_rect = icon_view.to_widget_rect(icon_view.content_rect(index)).translated(icon_view.screen_relative_rect().location());
+ auto launch_origin_rect = icon_view->to_widget_rect(icon_view->content_rect(index)).translated(icon_view->screen_relative_rect().location());
setenv("__libgui_launch_origin_rect", String::formatted("{},{},{},{}", launch_origin_rect.x(), launch_origin_rect.y(), launch_origin_rect.width(), launch_origin_rect.height()).characters(), 1);
Core::Process::spawn(executable);
};
- auto& statusbar = main_widget.add<GUI::Statusbar>();
+ auto statusbar = TRY(main_widget->try_add<GUI::Statusbar>());
- icon_view.on_selection_change = [&] {
- auto index = icon_view.selection().first();
+ icon_view->on_selection_change = [&] {
+ auto index = icon_view->selection().first();
if (!index.is_valid()) {
- statusbar.set_text({});
+ statusbar->set_text({});
return;
}
auto& app = *(NonnullRefPtr<Desktop::AppFile>*)index.internal_data();
- statusbar.set_text(app->description());
+ statusbar->set_text(app->description());
};
window->set_icon(app_icon.bitmap_for_size(16));