diff options
| author | salmonik <raisersoft@proton.me> | 2026-07-06 15:49:27 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-07-06 15:49:27 +0200 |
| commit | 547e7ac5218327216704e1fb72004a3de6992940 (patch) | |
| tree | 2913726087b10d9ad0083ef1196fb52439705035 /src/notification.rs | |
| parent | fix -a to work properly (diff) | |
| download | rsplayer-547e7ac5218327216704e1fb72004a3de6992940.tar.gz rsplayer-547e7ac5218327216704e1fb72004a3de6992940.zip | |
add MPRIS support and non-blocking notifs
Diffstat (limited to 'src/notification.rs')
| -rw-r--r-- | src/notification.rs | 68 |
1 files changed, 43 insertions, 25 deletions
diff --git a/src/notification.rs b/src/notification.rs index b2d2b56..9c19b0b 100644 --- a/src/notification.rs +++ b/src/notification.rs | |||
| @@ -22,41 +22,59 @@ pub fn notify_track(track: &Track, format: Option<&str>) { | |||
| 22 | }, | 22 | }, |
| 23 | }; | 23 | }; |
| 24 | 24 | ||
| 25 | let _ = notify_rust::Notification::new() | 25 | // show() is a synchronous D-Bus call that blocks until the notification |
| 26 | .summary("Now Playing") | 26 | // daemon responds. Spawn it on a separate thread so it never blocks the |
| 27 | .body(&body) | 27 | // player event loop or CLI command processing. |
| 28 | .appname("RSPlayer") | 28 | std::thread::spawn(move || { |
| 29 | .show(); | 29 | let _ = notify_rust::Notification::new() |
| 30 | .summary("Now Playing") | ||
| 31 | .body(&body) | ||
| 32 | .appname("RSPlayer") | ||
| 33 | .show(); | ||
| 34 | }); | ||
| 30 | } | 35 | } |
| 31 | 36 | ||
| 32 | pub fn notify_queue_ended() { | 37 | pub fn notify_queue_ended() { |
| 33 | let _ = notify_rust::Notification::new() | 38 | std::thread::spawn(|| { |
| 34 | .summary("Playback Ended") | 39 | let _ = notify_rust::Notification::new() |
| 35 | .body("The queue is empty") | 40 | .summary("Playback Ended") |
| 36 | .appname("RSPlayer") | 41 | .body("The queue is empty") |
| 37 | .show(); | 42 | .appname("RSPlayer") |
| 43 | .show(); | ||
| 44 | }); | ||
| 38 | } | 45 | } |
| 39 | 46 | ||
| 40 | pub fn notify_change(state: &str) { | 47 | pub fn notify_change(state: &str) { |
| 41 | let _ = notify_rust::Notification::new() | 48 | let summary = state.to_owned(); |
| 42 | .summary(state) | 49 | let body = format!("Playback {}", state.to_lowercase()); |
| 43 | .body(&format!("Playback {}", state.to_lowercase())) | 50 | std::thread::spawn(move || { |
| 44 | .appname("RSPlayer") | 51 | let _ = notify_rust::Notification::new() |
| 45 | .show(); | 52 | .summary(&summary) |
| 53 | .body(&body) | ||
| 54 | .appname("RSPlayer") | ||
| 55 | .show(); | ||
| 56 | }); | ||
| 46 | } | 57 | } |
| 47 | 58 | ||
| 48 | pub fn notify_error(context: &str) { | 59 | pub fn notify_error(context: &str) { |
| 49 | let _ = notify_rust::Notification::new() | 60 | let body = format!("{} - Check the logs for details", context); |
| 50 | .summary("RSPlayer Error") | 61 | std::thread::spawn(move || { |
| 51 | .body(&format!("{} - Check the logs for details", context)) | 62 | let _ = notify_rust::Notification::new() |
| 52 | .appname("RSPlayer") | 63 | .summary("RSPlayer Error") |
| 53 | .show(); | 64 | .body(&body) |
| 65 | .appname("RSPlayer") | ||
| 66 | .show(); | ||
| 67 | }); | ||
| 54 | } | 68 | } |
| 55 | 69 | ||
| 56 | pub fn notify(summary: &str, body: &str) { | 70 | pub fn notify(summary: &str, body: &str) { |
| 57 | let _ = notify_rust::Notification::new() | 71 | let summary = summary.to_owned(); |
| 58 | .summary(summary) | 72 | let body = body.to_owned(); |
| 59 | .body(body) | 73 | std::thread::spawn(move || { |
| 60 | .appname("RSPlayer") | 74 | let _ = notify_rust::Notification::new() |
| 61 | .show(); | 75 | .summary(&summary) |
| 76 | .body(&body) | ||
| 77 | .appname("RSPlayer") | ||
| 78 | .show(); | ||
| 79 | }); | ||
| 62 | } | 80 | } |
