notify: Add --launch-url option

This also makes the icon path an option (rather than a positional
argument) for convenience, as both `--icon-path` and `--launch-url` are
optional.
This commit is contained in:
MacDue
2024-11-17 14:09:47 +00:00
committed by Nico Weber
parent 1e0cca5d09
commit 437cb55159
3 changed files with 16 additions and 8 deletions

View File

@@ -5,21 +5,26 @@ notify - create a notification
## Synopsis
```**sh
$ notify <title> <message> [icon-path]
$ notify <title> <message> [-I icon-path] [-L launch-url]
```
## Options
- `-I`, `--icon-path`: Path to icon image file
- `-L`, `--launch-url`: Notification launch URL
## Arguments
- `title`: The title of notification
- `message`: The message of notification
- `icon-path`: Path to icon image file
- `title`: Notification title
- `message`: Notification message
## Description
`notify` creates a WindowServer notification with title `title` and message `message`. You can also provide an icon path; by default, no icon will be used.
`notify` creates a WindowServer notification with the title `title` and message `message`. Optionally, you can also provide an icon path and/or a launch URL
for the notification.
## Examples
```sh
$ <command> && notify "Information" "Command succeeded" /res/icons/32x32/msgbox-information.png
$ <command> && notify "Information" "Command succeeded" -I /res/icons/32x32/msgbox-information.png
```

View File

@@ -124,7 +124,7 @@ target_link_libraries(md PRIVATE LibMarkdown)
target_link_libraries(mkfs.fat PRIVATE LibFileSystem)
target_link_libraries(mktemp PRIVATE LibFileSystem)
target_link_libraries(mv PRIVATE LibFileSystem)
target_link_libraries(notify PRIVATE LibGfx LibGUI)
target_link_libraries(notify PRIVATE LibGfx LibGUI LibURL)
target_link_libraries(open PRIVATE LibDesktop LibFileSystem LibURL)
target_link_libraries(passwd PRIVATE LibCrypt)
target_link_libraries(paste PRIVATE LibGUI)

View File

@@ -18,9 +18,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
String title {};
String message {};
StringView icon_path {};
StringView launch_url {};
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.add_option(icon_path, "Path of icon to display in the notification", "icon-path", 'I', "icon_path");
args_parser.add_option(launch_url, "Launch URL for the notification", "launch-url", 'L', "launch_url");
args_parser.parse(arguments);
auto notification = GUI::Notification::construct();
@@ -29,6 +31,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (!icon_path.is_empty()) {
notification->set_icon(TRY(Gfx::Bitmap::load_from_file(icon_path)));
}
notification->set_launch_url(launch_url);
notification->show();
return 0;