diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-03-31 21:51:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-31 21:51:47 +0200 |
| commit | 3f6281020b72ba949147a282c18c60a2842ad3dc (patch) | |
| tree | 0ba20ba532d325bf072969013fe8cf5bde84f6ba /mumd/src/notifications.rs | |
| parent | 795e46c98616801c678bd0a403b08cb0fcd5ee43 (diff) | |
| parent | 46a3938b6d9d81649e38e6e793599a52991d803d (diff) | |
| download | mum-3f6281020b72ba949147a282c18c60a2842ad3dc.tar.gz | |
Merge pull request #42 from mum-rs/handle-panics
Diffstat (limited to 'mumd/src/notifications.rs')
| -rw-r--r-- | mumd/src/notifications.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/mumd/src/notifications.rs b/mumd/src/notifications.rs new file mode 100644 index 0000000..bccf4dd --- /dev/null +++ b/mumd/src/notifications.rs @@ -0,0 +1,24 @@ +use log::*; + +pub fn init() { + #[cfg(feature = "notifications")] + if let Err(e) = libnotify::init("mumd") { + warn!("Unable to initialize notifications: {}", e); + } +} + +#[cfg(feature = "notifications")] +pub fn send(msg: String) -> Option<bool> { + match libnotify::Notification::new("mumd", Some(msg.as_str()), None).show() { + Ok(_) => Some(true), + Err(e) => { + warn!("Unable to send notification: {}", e); + Some(false) + } + } +} + +#[cfg(not(feature = "notifications"))] +pub fn send(_: String) -> Option<bool> { + None +} |
