From c88f056289040533b692fdf0e7cd06d2988e5c92 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 8 May 2026 00:55:52 +0200 Subject: Add desktop notifications for track changes, queue end, and errors Uses notify-rust to send D-Bus desktop notifications from the daemon when tracks change, the queue empties, or audio errors occur. --- src/notification.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/notification.rs (limited to 'src/notification.rs') diff --git a/src/notification.rs b/src/notification.rs new file mode 100644 index 0000000..2f7baa2 --- /dev/null +++ b/src/notification.rs @@ -0,0 +1,36 @@ +use crate::queue::Track; + +pub fn notify_track(track: &Track) { + let body = match (track.artist.as_deref(), track.title.as_deref()) { + (Some(a), Some(t)) => format!("{} - {}", a, t), + (_, Some(t)) => t.to_string(), + _ => track + .path + .file_name() + .and_then(|n| n.to_str()) + .unwrap_or("Unknown") + .to_string(), + }; + + let _ = notify_rust::Notification::new() + .summary("Now Playing") + .body(&body) + .appname("rsp") + .show(); +} + +pub fn notify_queue_ended() { + let _ = notify_rust::Notification::new() + .summary("Playback Ended") + .body("The queue is empty") + .appname("rsp") + .show(); +} + +pub fn notify_error(context: &str) { + let _ = notify_rust::Notification::new() + .summary("rsp Error") + .body(&format!("{} - Check the logs for details", context)) + .appname("rsp") + .show(); +} -- cgit v1.2.3