aboutsummaryrefslogtreecommitdiffstats
path: root/src/notification.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/notification.rs')
-rw-r--r--src/notification.rs68
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
32pub fn notify_queue_ended() { 37pub 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
40pub fn notify_change(state: &str) { 47pub 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
48pub fn notify_error(context: &str) { 59pub 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
56pub fn notify(summary: &str, body: &str) { 70pub 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}