Skip to content

Commit

Permalink
notify: Add --launch-url option
Browse files Browse the repository at this point in the history
This also makes the icon path an option (rather than a positional
argument) for convenience, as both `--icon-path` and `--launch-url` are
optional.
  • Loading branch information
MacDue authored and nico committed Nov 17, 2024
1 parent 1e0cca5 commit 437cb55
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
17 changes: 11 additions & 6 deletions Base/usr/share/man/man1/notify.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
2 changes: 1 addition & 1 deletion Userland/Utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion Userland/Utilities/notify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit 437cb55

Please sign in to comment.