aboutsummaryrefslogtreecommitdiffstats
path: root/src/notification.rs
blob: 4947e6f42c04d969a90edc11b84cdfd749fcd572 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::queue::Track;

pub fn notify_track(track: &Track, format: Option<&str>) {
    let body = match format {
        Some(fmt) => track.format(fmt),
        None => 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();
}