From 547e7ac5218327216704e1fb72004a3de6992940 Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 6 Jul 2026 15:49:27 +0200 Subject: add MPRIS support and non-blocking notifs --- src/notification.rs | 68 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 25 deletions(-) (limited to 'src/notification.rs') 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>) { }, }; - let _ = notify_rust::Notification::new() - .summary("Now Playing") - .body(&body) - .appname("RSPlayer") - .show(); + // show() is a synchronous D-Bus call that blocks until the notification + // daemon responds. Spawn it on a separate thread so it never blocks the + // player event loop or CLI command processing. + std::thread::spawn(move || { + let _ = notify_rust::Notification::new() + .summary("Now Playing") + .body(&body) + .appname("RSPlayer") + .show(); + }); } pub fn notify_queue_ended() { - let _ = notify_rust::Notification::new() - .summary("Playback Ended") - .body("The queue is empty") - .appname("RSPlayer") - .show(); + std::thread::spawn(|| { + let _ = notify_rust::Notification::new() + .summary("Playback Ended") + .body("The queue is empty") + .appname("RSPlayer") + .show(); + }); } pub fn notify_change(state: &str) { - let _ = notify_rust::Notification::new() - .summary(state) - .body(&format!("Playback {}", state.to_lowercase())) - .appname("RSPlayer") - .show(); + let summary = state.to_owned(); + let body = format!("Playback {}", state.to_lowercase()); + std::thread::spawn(move || { + let _ = notify_rust::Notification::new() + .summary(&summary) + .body(&body) + .appname("RSPlayer") + .show(); + }); } pub fn notify_error(context: &str) { - let _ = notify_rust::Notification::new() - .summary("RSPlayer Error") - .body(&format!("{} - Check the logs for details", context)) - .appname("RSPlayer") - .show(); + let body = format!("{} - Check the logs for details", context); + std::thread::spawn(move || { + let _ = notify_rust::Notification::new() + .summary("RSPlayer Error") + .body(&body) + .appname("RSPlayer") + .show(); + }); } pub fn notify(summary: &str, body: &str) { - let _ = notify_rust::Notification::new() - .summary(summary) - .body(body) - .appname("RSPlayer") - .show(); + let summary = summary.to_owned(); + let body = body.to_owned(); + std::thread::spawn(move || { + let _ = notify_rust::Notification::new() + .summary(&summary) + .body(&body) + .appname("RSPlayer") + .show(); + }); } -- cgit v1.2.3