diff --git a/Harmony/Player/PlayerController.swift b/Harmony/Player/PlayerController.swift index 6d72b98..9b9e22e 100644 --- a/Harmony/Player/PlayerController.swift +++ b/Harmony/Player/PlayerController.swift @@ -317,6 +317,18 @@ class PlayerController: NSObject, ObservableObject { play() } + func playSongFromQueues(instanceId: ObjectIdentifier) { + if queue.pastSongs.contains(where: { $0.id == instanceId }) { + playSongFromPastSongs(instanceId: instanceId) + } else if queue.playNextSongs.contains(where: { $0.id == instanceId }) { + playSongFromPlayNext(instanceId: instanceId) + } else if queue.futureSongs.contains(where: { $0.id == instanceId }) { + playSongFromFutureSongs(instanceId: instanceId) + } else { + Logger.player.error("Song not found in any queue") + } + } + @discardableResult func togglePlayPause() -> MPRemoteCommandHandlerStatus { if timeControlStatus != .paused { return pause() diff --git a/Harmony/Player/PlayerQueueView.swift b/Harmony/Player/PlayerQueueView.swift index e471501..f42e1fa 100644 --- a/Harmony/Player/PlayerQueueView.swift +++ b/Harmony/Player/PlayerQueueView.swift @@ -25,14 +25,6 @@ struct PlayerQueueView: View { ForEach(queue.pastSongs) { song in PlayerQueueListItemView(song: song, isCurrentSong: false) .listRowBackground(rowBackground) - .contextMenu { _ in - // TODO: Add a context menu - } primaryAction: { - $0.forEach { - playerController.playSongFromPastSongs(instanceId: $0) - proxy.scrollTo(currentSongSectionId, anchor: .top) - } - } } .onDelete(perform: { indexSet in queue.removePastSongs(indexSet) }) } header: { @@ -62,14 +54,6 @@ struct PlayerQueueView: View { ForEach(queue.playNextSongs) { song in PlayerQueueListItemView(song: song, isCurrentSong: false) .listRowBackground(rowBackground) - .contextMenu { _ in - // TODO: Add a context menu - } primaryAction: { - $0.forEach { - playerController.playSongFromPlayNext(instanceId: $0) - proxy.scrollTo(currentSongSectionId, anchor: .top) - } - } } .onDelete(perform: { indexSet in queue.removePlayNextSongs(indexSet) }) } @@ -82,14 +66,6 @@ struct PlayerQueueView: View { .onAppear { queue.loadNextPageIfNeeded(song: song) } - .contextMenu { _ in - // TODO: Add a context menu - } primaryAction: { - $0.forEach { - playerController.playSongFromFutureSongs(instanceId: $0) - proxy.scrollTo(currentSongSectionId, anchor: .top) - } - } } .onDelete(perform: { indexSet in queue.removeFutureSongs(indexSet) }) } header: { @@ -107,6 +83,16 @@ struct PlayerQueueView: View { } } } + .contextMenu { _ in + // TODO: Add a context menu + } primaryAction: { + $0.forEach { + // HACK: This is a workaround for the fact that we can't get the section for a + // given item, so we need to call the generic method to check each subqueue + // rather than calling the playSongFromXXX for the specific subqueue. Slow! + playerController.playSongFromQueues(instanceId: $0) + } + } .onChange(of: queue.currentSong) { #if os(macOS) // TODO: iPadOS? proxy.scrollTo(currentSongSectionId, anchor: .top)