mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 13:43:45 +03:00
1a97382305
The pattern to construct `Application` was to use the `try_create` method from the `C_OBJECT` macro. While being safe from an OOM perspective, this method doesn't propagate errors from the constructor. This patch make `Application` use the `C_OBJECT_ABSTRACT` and manually define a `create` method that can bubble up errors from the construction stage. This commit also removes the ability to use `argc` and `argv` to create an `Application`, only `Main`'s `Arguments` can be used. From a user point of view, the patch renames `try_create` => `create`, hence the huge number of modified files.
36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibCore/ArgsParser.h>
|
|
#include <LibGUI/Application.h>
|
|
#include <LibGUI/Notification.h>
|
|
#include <LibGfx/Bitmap.h>
|
|
#include <LibMain/Main.h>
|
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|
{
|
|
auto app = TRY(GUI::Application::create(arguments));
|
|
|
|
Core::ArgsParser args_parser;
|
|
StringView title {};
|
|
StringView message {};
|
|
StringView icon_path {};
|
|
args_parser.add_positional_argument(title, "Title of the notification", "title");
|
|
args_parser.add_positional_argument(message, "Message to display in the notification", "message");
|
|
args_parser.add_positional_argument(icon_path, "Path of icon to display in the notification", "icon-path", Core::ArgsParser::Required::No);
|
|
args_parser.parse(arguments);
|
|
|
|
auto notification = TRY(GUI::Notification::try_create());
|
|
notification->set_text(message);
|
|
notification->set_title(title);
|
|
if (!icon_path.is_empty()) {
|
|
notification->set_icon(TRY(Gfx::Bitmap::load_from_file(icon_path)));
|
|
}
|
|
notification->show();
|
|
|
|
return 0;
|
|
}
|