mum_cli/notifications.rs
1/// Try to initialize the notification daemon.
2///
3/// Does nothing if compiled without notification support.
4pub fn init() {
5 #[cfg(feature = "notifications")]
6 if let Err(e) = libnotify::init("mumd") {
7 log::warn!("Unable to initialize notifications: {}", e);
8 }
9}
10
11#[cfg(feature = "notifications")]
12/// Send a notification non-blocking, returning a JoinHandle that resolves to
13/// whether the notification was sent or not.
14///
15/// The notification is sent on its own thread since a timeout otherwise might
16/// block for several seconds.
17///
18/// None is returned iff the program was compiled without notification support.
19pub fn send(msg: String) -> Option<std::thread::JoinHandle<bool>> {
20 Some(std::thread::spawn(move || {
21 let status = libnotify::Notification::new("mumd", Some(msg.as_str()), None).show();
22 if let Err(e) = &status {
23 log::warn!("Unable to send notification: {}", e);
24 }
25 status.is_ok()
26 }))
27}
28
29#[cfg(not(feature = "notifications"))]
30/// Send a notification. Without the `notifications`-feature, this will never do
31/// anything and always return None.
32pub fn send(_: String) -> Option<std::thread::JoinHandle<bool>> {
33 None
34}