@@ -184,88 +184,55 @@ class MusicManager: ObservableObject {
184184 self . updateSneakPeek ( )
185185 }
186186 }
187-
188- // Check for changes in track metadata using last artwork change values
187+
188+ // Determine if anything changed
189189 let titleChanged = state. title != self . lastArtworkTitle
190190 let artistChanged = state. artist != self . lastArtworkArtist
191191 let albumChanged = state. album != self . lastArtworkAlbum
192192 let bundleChanged = state. bundleIdentifier != self . lastArtworkBundleIdentifier
193-
194- // Check for artwork changes
195193 let artworkChanged = state. artwork != nil && state. artwork != self . artworkData
196194 let hasContentChange = titleChanged || artistChanged || albumChanged || artworkChanged || bundleChanged
197195
198- // Handle artwork and visual transitions for changed content
199196 if hasContentChange {
200- self . triggerFlipAnimation ( )
201-
202- if artworkChanged, let artwork = state. artwork {
203- self . updateArtwork ( artwork)
204- } else if state. artwork == nil {
205- // Try to use app icon if no artwork but track changed
206- if let appIconImage = AppIconAsNSImage ( for: state. bundleIdentifier) {
207- self . usingAppIconForArtwork = true
208- self . updateAlbumArt ( newAlbumArt: appIconImage)
209- }
210- }
197+ // Update last values
198+ self . lastArtworkTitle = state. title
199+ self . lastArtworkArtist = state. artist
200+ self . lastArtworkAlbum = state. album
201+ self . lastArtworkBundleIdentifier = state. bundleIdentifier
211202 self . artworkData = state. artwork
212203
213- if artworkChanged || state. artwork == nil {
214- // Update last artwork change values
215- self . lastArtworkTitle = state. title
216- self . lastArtworkArtist = state. artist
217- self . lastArtworkAlbum = state. album
218- self . lastArtworkBundleIdentifier = state. bundleIdentifier
204+ // Update all content together
205+ self . updatePlaybackContent (
206+ title: state. title,
207+ artist: state. artist,
208+ album: state. album,
209+ artworkData: state. artwork,
210+ bundleIdentifier: state. bundleIdentifier
211+ )
212+ }
213+
214+ // Playback state changes (play/pause)
215+ if state. isPlaying != self . isPlaying {
216+ withAnimation ( . smooth) {
217+ self . isPlaying = state. isPlaying
218+ self . updateIdleState ( state: state. isPlaying)
219219 }
220220
221- // Only update sneak peek if there's actual content and something changed
222- if !state. title. isEmpty && !state. artist. isEmpty && state. isPlaying {
221+ if state. isPlaying && !state. title. isEmpty && !state. artist. isEmpty {
223222 self . updateSneakPeek ( )
224223 }
225224 }
226225
227- let timeChanged = state. currentTime != self . elapsedTime
228- let durationChanged = state. duration != self . songDuration
229- let playbackRateChanged = state. playbackRate != self . playbackRate
230- let shuffleChanged = state. isShuffled != self . isShuffled
231- let repeatModeChanged = state. repeatMode != self . repeatMode
232-
233- if state. title != self . songTitle {
234- self . songTitle = state. title
235- }
236-
237- if state. artist != self . artistName {
238- self . artistName = state. artist
239- }
240-
241- if state. album != self . album {
242- self . album = state. album
243- }
244-
245- if timeChanged {
246- self . elapsedTime = state. currentTime
247- }
248-
249- if durationChanged {
250- self . songDuration = state. duration
251- }
252-
253- if playbackRateChanged {
254- self . playbackRate = state. playbackRate
255- }
256-
257- if shuffleChanged {
258- self . isShuffled = state. isShuffled
259- }
260-
261- if state. bundleIdentifier != self . bundleIdentifier {
262- self . bundleIdentifier = state. bundleIdentifier
263- }
264-
265- if repeatModeChanged {
266- self . repeatMode = state. repeatMode
267- }
268-
226+ // Other playback properties
227+ if state. currentTime != self . elapsedTime { self . elapsedTime = state. currentTime }
228+ if state. duration != self . songDuration { self . songDuration = state. duration }
229+ if state. playbackRate != self . playbackRate { self . playbackRate = state. playbackRate }
230+ if state. isShuffled != self . isShuffled { self . isShuffled = state. isShuffled }
231+ if state. repeatMode != self . repeatMode { self . repeatMode = state. repeatMode }
232+ if state. title != self . songTitle { self . songTitle = state. title }
233+ if state. artist != self . artistName { self . artistName = state. artist }
234+ if state. album != self . album { self . album = state. album }
235+ if state. bundleIdentifier != self . bundleIdentifier { self . bundleIdentifier = state. bundleIdentifier }
269236 self . timestampDate = state. lastUpdated
270237 }
271238
@@ -284,18 +251,30 @@ class MusicManager: ObservableObject {
284251 flipWorkItem = workItem
285252 DispatchQueue . main. async ( execute: workItem)
286253 }
287-
288- private func updateArtwork( _ artworkData: Data ) {
289- DispatchQueue . global ( qos: . userInitiated) . async { [ weak self] in
290- guard let self = self else { return }
291-
292- if let artworkImage = NSImage ( data: artworkData) {
293- DispatchQueue . main. async { [ weak self] in
294- self ? . usingAppIconForArtwork = false
295- self ? . updateAlbumArt ( newAlbumArt: artworkImage)
296- }
297- }
298- }
254+
255+ @MainActor
256+ private func updatePlaybackContent( title: String ,
257+ artist: String ,
258+ album: String ,
259+ artworkData: Data ? ,
260+ bundleIdentifier: String ? ) {
261+ var finalArtwork : NSImage = defaultImage
262+
263+ if let data = artworkData, let image = NSImage ( data: data) {
264+ finalArtwork = image
265+ self . usingAppIconForArtwork = false
266+ } else if let bundleID = bundleIdentifier,
267+ let appIcon = AppIconAsNSImage ( for: bundleID) {
268+ finalArtwork = appIcon
269+ self . usingAppIconForArtwork = true
270+ }
271+
272+ // Update properties on main actor
273+ self . songTitle = title
274+ self . artistName = artist
275+ self . album = album
276+ self . albumArt = finalArtwork
277+ self . triggerFlipAnimation ( )
299278 }
300279
301280 private func updateIdleState( state: Bool ) {
0 commit comments