forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.cpp
35 lines (30 loc) · 1.13 KB
/
notify.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Copyright (c) 2020, Andreas Kling <[email protected]>
*
* 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::try_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::try_load_from_file(icon_path)));
}
notification->show();
return 0;
}