diff options
| author | salmonik <raisersoft@proton.me> | 2026-05-08 00:55:52 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-05-08 00:55:52 +0200 |
| commit | c88f056289040533b692fdf0e7cd06d2988e5c92 (patch) | |
| tree | e18e0cfb02631b801c16d50808bc30bb85f50e4d /src/notification.rs | |
| parent | Extract queue module, add comprehensive tests, fix queue/play bugs (diff) | |
| download | rsplayer-c88f056289040533b692fdf0e7cd06d2988e5c92.tar.gz rsplayer-c88f056289040533b692fdf0e7cd06d2988e5c92.zip | |
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.
Diffstat (limited to '')
| -rw-r--r-- | src/notification.rs | 36 |
1 files changed, 36 insertions, 0 deletions
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 @@ | |||
| 1 | use crate::queue::Track; | ||
| 2 | |||
| 3 | pub fn notify_track(track: &Track) { | ||
| 4 | let body = match (track.artist.as_deref(), track.title.as_deref()) { | ||
| 5 | (Some(a), Some(t)) => format!("{} - {}", a, t), | ||
| 6 | (_, Some(t)) => t.to_string(), | ||
| 7 | _ => track | ||
| 8 | .path | ||
| 9 | .file_name() | ||
| 10 | .and_then(|n| n.to_str()) | ||
| 11 | .unwrap_or("Unknown") | ||
| 12 | .to_string(), | ||
| 13 | }; | ||
| 14 | |||
| 15 | let _ = notify_rust::Notification::new() | ||
| 16 | .summary("Now Playing") | ||
| 17 | .body(&body) | ||
| 18 | .appname("rsp") | ||
| 19 | .show(); | ||
| 20 | } | ||
| 21 | |||
| 22 | pub fn notify_queue_ended() { | ||
| 23 | let _ = notify_rust::Notification::new() | ||
| 24 | .summary("Playback Ended") | ||
| 25 | .body("The queue is empty") | ||
| 26 | .appname("rsp") | ||
| 27 | .show(); | ||
| 28 | } | ||
| 29 | |||
| 30 | pub fn notify_error(context: &str) { | ||
| 31 | let _ = notify_rust::Notification::new() | ||
| 32 | .summary("rsp Error") | ||
| 33 | .body(&format!("{} - Check the logs for details", context)) | ||
| 34 | .appname("rsp") | ||
| 35 | .show(); | ||
| 36 | } | ||
