summaryrefslogtreecommitdiff
path: root/Userland/Services/Taskbar
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-23 14:31:53 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-23 15:44:59 +0100
commitadc83e5802faa9f239972040d7c340215e13340a (patch)
treeddbcf5ad279ae776a22c9ae7e33698f85ef0a38c /Userland/Services/Taskbar
parentb03f8d18c500380f304fd131ab737f21b427fe57 (diff)
downloadserenity-adc83e5802faa9f239972040d7c340215e13340a.zip
Taskbar: Port to LibMain :^)
This opens up using TRY() for syscalls, Core::Object creation, and even some Vector operations.
Diffstat (limited to 'Userland/Services/Taskbar')
-rw-r--r--Userland/Services/Taskbar/CMakeLists.txt2
-rw-r--r--Userland/Services/Taskbar/main.cpp38
2 files changed, 18 insertions, 22 deletions
diff --git a/Userland/Services/Taskbar/CMakeLists.txt b/Userland/Services/Taskbar/CMakeLists.txt
index 5f3770d0f5..b8c6d2293b 100644
--- a/Userland/Services/Taskbar/CMakeLists.txt
+++ b/Userland/Services/Taskbar/CMakeLists.txt
@@ -14,5 +14,5 @@ set(SOURCES
)
serenity_bin(Taskbar)
-target_link_libraries(Taskbar LibGUI LibDesktop LibConfig)
+target_link_libraries(Taskbar LibGUI LibDesktop LibConfig LibMain)
serenity_install_headers(Services/Taskbar)
diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp
index 5199d2586d..f093d6dec0 100644
--- a/Userland/Services/Taskbar/main.cpp
+++ b/Userland/Services/Taskbar/main.cpp
@@ -15,12 +15,14 @@
#include <LibCore/EventLoop.h>
#include <LibCore/Process.h>
#include <LibCore/StandardPaths.h>
+#include <LibCore/System.h>
#include <LibDesktop/AppFile.h>
#include <LibGUI/ActionGroup.h>
#include <LibGUI/Application.h>
#include <LibGUI/Menu.h>
#include <LibGUI/WindowManagerServerConnection.h>
#include <LibGUI/WindowServerConnection.h>
+#include <LibMain/Main.h>
#include <WindowServer/Window.h>
#include <serenity.h>
#include <signal.h>
@@ -29,16 +31,13 @@
#include <sys/wait.h>
#include <unistd.h>
-static Vector<String> discover_apps_and_categories();
-static NonnullRefPtr<GUI::Menu> build_system_menu();
+static ErrorOr<Vector<String>> discover_apps_and_categories();
+static ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu();
-int main(int argc, char** argv)
+ErrorOr<int> serenity_main(Main::Arguments arguments)
{
- if (pledge("stdio recvfd sendfd proc exec rpath unix sigaction", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
- auto app = GUI::Application::construct(argc, argv);
+ TRY(Core::System::pledge("stdio recvfd sendfd proc exec rpath unix sigaction", nullptr));
+ auto app = TRY(GUI::Application::try_create(arguments));
Config::pledge_domains("Taskbar");
Config::monitor_domain("Taskbar");
app->event_loop().register_signal(SIGCHLD, [](int) {
@@ -50,15 +49,12 @@ int main(int argc, char** argv)
// We need to obtain the WM connection here as well before the pledge shortening.
GUI::WindowManagerServerConnection::the();
- if (pledge("stdio recvfd sendfd proc exec rpath", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio recvfd sendfd proc exec rpath", nullptr));
- auto menu = build_system_menu();
+ auto menu = TRY(build_system_menu());
menu->realize_menu_if_needed();
- auto window = TaskbarWindow::construct(move(menu));
+ auto window = TRY(TaskbarWindow::try_create(move(menu)));
window->show();
window->make_window_manager(
@@ -90,7 +86,7 @@ Vector<ThemeMetadata> g_themes;
RefPtr<GUI::Menu> g_themes_menu;
GUI::ActionGroup g_themes_group;
-Vector<String> discover_apps_and_categories()
+ErrorOr<Vector<String>> discover_apps_and_categories()
{
HashTable<String> seen_app_categories;
Desktop::AppFile::for_each([&](auto af) {
@@ -102,18 +98,18 @@ Vector<String> discover_apps_and_categories()
quick_sort(g_apps, [](auto& a, auto& b) { return a.name < b.name; });
Vector<String> sorted_app_categories;
- for (auto& category : seen_app_categories) {
- sorted_app_categories.append(category);
- }
+ TRY(sorted_app_categories.try_ensure_capacity(seen_app_categories.size()));
+ for (auto const& category : seen_app_categories)
+ sorted_app_categories.unchecked_append(category);
quick_sort(sorted_app_categories);
return sorted_app_categories;
}
-NonnullRefPtr<GUI::Menu> build_system_menu()
+ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu()
{
- const Vector<String> sorted_app_categories = discover_apps_and_categories();
- auto system_menu = GUI::Menu::construct("\xE2\x9A\xA1"); // HIGH VOLTAGE SIGN
+ Vector<String> const sorted_app_categories = TRY(discover_apps_and_categories());
+ auto system_menu = TRY(GUI::Menu::try_create("\xE2\x9A\xA1")); // HIGH VOLTAGE SIGN
system_menu->add_action(GUI::Action::create("&About SerenityOS", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/ladyball.png").release_value_but_fixme_should_propagate_errors(), [](auto&) {
Core::Process::spawn("/bin/About"sv);