/* * This file is a part of RSPlayer * Licensed under the GPL-3.0 License * Copyright (C) 2026 Salmonik @ salmonik@tuta.io * https://codeberg.org/salmonik/RSPlayer */ 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(), }, }; // 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() { 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 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 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 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(); }); }