From d8faa8743129644b69064e5b92e44a9cec78fbb7 Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Tue, 23 May 2023 01:51:29 +0800 Subject: [PATCH] Fix incorrect notification ID reuse on XDG (#1150) * Fix incorrect notification ID reuse on XDG * Remove `notification_id` persistence --------- Co-authored-by: Henrik Friedrichsen --- src/queue.rs | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/src/queue.rs b/src/queue.rs index e138221..dd83307 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -1,6 +1,4 @@ use std::cmp::Ordering; -#[cfg(feature = "notify")] -use std::sync::atomic::AtomicU32; use std::sync::{Arc, RwLock}; use log::{debug, error, info}; @@ -47,10 +45,6 @@ pub struct Queue { current_track: RwLock>, spotify: Spotify, cfg: Arc, - /// The notification id that uniquely identifies the notification of the - /// currently playing song. - #[cfg(feature = "notify")] - notification_id: Arc, library: Arc, } @@ -64,8 +58,6 @@ impl Queue { current_track: RwLock::new(queue_state.current_track), random_order: RwLock::new(queue_state.random_order), cfg, - #[cfg(feature = "notify")] - notification_id: Arc::new(AtomicU32::new(0)), library, }; @@ -321,7 +313,6 @@ impl Queue { #[cfg(feature = "notify")] if self.cfg.values().notify.unwrap_or(false) { - let notification_id = self.notification_id.clone(); std::thread::spawn({ // use same parser as track_format, Playable::format let format = self @@ -339,7 +330,7 @@ impl Queue { let summary_txt = Playable::format(track, &title, &self.library); let body_txt = Playable::format(track, &body, &self.library); let cover_url = track.cover_url(); - move || send_notification(&summary_txt, &body_txt, cover_url, notification_id) + move || send_notification(&summary_txt, &body_txt, cover_url) }); } } @@ -503,19 +494,9 @@ impl Queue { /// `notification_id`: Unique id for a notification, that can be used to operate /// on a previous notification (for example to close it). #[cfg(feature = "notify")] -pub fn send_notification( - summary_txt: &str, - body_txt: &str, - cover_url: Option, - notification_id: Arc, -) { - let current_notification_id = notification_id.load(std::sync::atomic::Ordering::Relaxed); - +pub fn send_notification(summary_txt: &str, body_txt: &str, cover_url: Option) { let mut n = Notification::new(); - n.appname("ncspot") - .id(current_notification_id) - .summary(summary_txt) - .body(body_txt); + n.appname("ncspot").summary(summary_txt).body(body_txt); // album cover image if let Some(u) = cover_url { @@ -535,18 +516,10 @@ pub fn send_notification( .hint(Hint::DesktopEntry("ncspot".into())); match n.show() { - Ok(_handle) => { + Ok(handle) => { // only available for XDG #[cfg(all(unix, not(target_os = "macos")))] - { - let new_notification_id = _handle.id(); - log::debug!( - "new notification id: {}, previously: {}", - new_notification_id, - current_notification_id - ); - notification_id.store(new_notification_id, std::sync::atomic::Ordering::Relaxed); - } + info!("Created notification: {}", handle.id()); } Err(e) => error!("Failed to send notification cover: {}", e), }