mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Add a function for sending desktop notifications
This commit is contained in:
@@ -391,3 +391,15 @@ Configuration load_config_for(const fs::path& yabridge_path) {
|
|||||||
|
|
||||||
return Configuration(*config_file, 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -264,6 +264,21 @@ boost::filesystem::path get_this_file_location();
|
|||||||
*/
|
*/
|
||||||
Configuration load_config_for(const boost::filesystem::path& yabridge_path);
|
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
|
* Starting from the starting file or directory, go up in the directory
|
||||||
* hierarchy until we find a file named `filename`.
|
* hierarchy until we find a file named `filename`.
|
||||||
|
|||||||
Reference in New Issue
Block a user