From 1dcda5613afdfecd67f2a4379acd946f6ed58bc0 Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Fri, 19 Sep 2025 22:33:01 -0400 Subject: [PATCH] Fix Spotify flashing display issue (#54) - Implement proper significant change detection for Spotify polling - Only trigger significant changes for title, artist, album_art_url, is_playing changes - Progress updates (progress_ms) are now non-significant and won't cause flashing - Matches the logic used for YouTube Music polling - Prevents unnecessary album art re-fetching and display clearing every 2 seconds --- src/music_manager.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/music_manager.py b/src/music_manager.py index 37535857..17541c42 100644 --- a/src/music_manager.py +++ b/src/music_manager.py @@ -371,11 +371,33 @@ class MusicManager: with self.track_info_lock: if simplified_info_poll != self.current_track_info: + # Check for significant changes (same logic as YTM) + significant_change_detected = False + if self.current_track_info is None and simplified_info_poll.get('title') != 'Nothing Playing': + significant_change_detected = True + logger.debug("Polling Spotify: First valid track data, marking as significant.") + elif self.current_track_info is not None and ( + simplified_info_poll.get('title') != self.current_track_info.get('title') or + simplified_info_poll.get('artist') != self.current_track_info.get('artist') or + simplified_info_poll.get('album_art_url') != self.current_track_info.get('album_art_url') or + simplified_info_poll.get('is_playing') != self.current_track_info.get('is_playing') + ): + significant_change_detected = True + logger.debug("Polling Spotify: Significant change (title/artist/art/is_playing) detected.") + else: + logger.debug("Polling Spotify: Only progress changed, not significant.") + self.current_track_info = simplified_info_poll self.current_source = MusicSource.SPOTIFY - significant_change_for_callback = True # Spotify poll changes always considered significant + significant_change_for_callback = significant_change_detected simplified_info_for_callback = simplified_info_poll.copy() - self._needs_immediate_full_refresh = True # Reset display state + + if significant_change_detected: + self._needs_immediate_full_refresh = True # Reset display state + logger.info("Polling Spotify: Significant change detected.") + else: + logger.debug("Polling Spotify: Minor update (progress only), no full refresh needed.") + # Handle album art for Spotify if needed (similar to _process_ytm_data_update) old_album_art_url = self.current_track_info.get('album_art_url_prev_spotify') # Need a way to store prev new_album_art_url = simplified_info_poll.get('album_art_url') @@ -384,7 +406,6 @@ class MusicManager: self.last_album_art_url = new_album_art_url self.current_track_info['album_art_url_prev_spotify'] = new_album_art_url - logger.debug(f"Polling Spotify: Active track - {spotify_track.get('item', {}).get('name')}") else: logger.debug("Polling Spotify: No change in simplified track info.")