Add a function for sending desktop notifications

This commit is contained in:
Robbert van der Helm
2021-06-22 16:24:39 +02:00
parent 9f52aca451
commit 437a4dc5ec
2 changed files with 27 additions and 0 deletions
+12
View File
@@ -391,3 +391,15 @@ Configuration load_config_for(const fs::path& yabridge_path) {
return Configuration(*config_file, yabridge_path);
}
bool send_notification(const std::string& title, const std::string body) {
try {
return bp::system(bp::search_path("notify-send"), "--urgency=critical",
"--expire-time=20000", "--app-name=yabridge", title,
body) == EXIT_SUCCESS;
} catch (const boost::process::process_error&) {
// We will have printed the message to the terminal anyways, so if the
// user doesn't have libnotify installed we'll just fail silently
return false;
}
}
+15
View File
@@ -264,6 +264,21 @@ boost::filesystem::path get_this_file_location();
*/
Configuration load_config_for(const boost::filesystem::path& yabridge_path);
/**
* Send a desktop notification using `notify-send`. Used for diagnostics when a
* plugin fails to load since the user may not be checking the output in a
* terminal.
*
* @param title The title (or technically, summary) of the notification.
* @param body The message to display. This can contain line feeds and also
* basic HTML-like formatting, so special characters may need to be escaped.
* The message can also be empty.
*
* @return Whether the notification was sent. This will be false if
* `notify-send` is not available.
*/
bool send_notification(const std::string& title, const std::string body);
/**
* Starting from the starting file or directory, go up in the directory
* hierarchy until we find a file named `filename`.