From d8c269f66a4a5a17155bec5e2cb5ad97f3ba00fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 30 Mar 2021 11:27:10 +0200 Subject: rename notify -> notifications Notify is already taken, see https://lib.rs/crates/notify. --- mumd/src/notifications.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 mumd/src/notifications.rs (limited to 'mumd/src/notifications.rs') diff --git a/mumd/src/notifications.rs b/mumd/src/notifications.rs new file mode 100644 index 0000000..e52b909 --- /dev/null +++ b/mumd/src/notifications.rs @@ -0,0 +1,24 @@ +use log::*; + +pub fn init() { + #[cfg(feature = "notifications")] + if libnotify::init("mumd").is_err() { + warn!("Unable to initialize notifications"); + } +} + +#[cfg(feature = "notifications")] +pub fn send(msg: String) -> Option { + match libnotify::Notification::new("mumd", Some(msg.as_str()), None).show() { + Ok(_) => Some(true), + Err(_) => { + warn!("Unable to send notification"); + Some(false) + } + } +} + +#[cfg(not(feature = "notifications"))] +pub fn send(_: String) -> Option { + None +} -- cgit v1.2.1 From 69f189fd45b410be2db3c77e2a4bfa6d9ad8946d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 31 Mar 2021 09:05:12 +0200 Subject: review --- mumd/src/notifications.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'mumd/src/notifications.rs') diff --git a/mumd/src/notifications.rs b/mumd/src/notifications.rs index e52b909..bccf4dd 100644 --- a/mumd/src/notifications.rs +++ b/mumd/src/notifications.rs @@ -2,8 +2,8 @@ use log::*; pub fn init() { #[cfg(feature = "notifications")] - if libnotify::init("mumd").is_err() { - warn!("Unable to initialize notifications"); + if let Err(e) = libnotify::init("mumd") { + warn!("Unable to initialize notifications: {}", e); } } @@ -11,8 +11,8 @@ pub fn init() { pub fn send(msg: String) -> Option { match libnotify::Notification::new("mumd", Some(msg.as_str()), None).show() { Ok(_) => Some(true), - Err(_) => { - warn!("Unable to send notification"); + Err(e) => { + warn!("Unable to send notification: {}", e); Some(false) } } -- cgit v1.2.1