Skip to content

Commit

Permalink
Fix doubleclicking on a given item in the playerqueue
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Apr 14, 2024
1 parent 36f2d74 commit fd5f1db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
12 changes: 12 additions & 0 deletions Harmony/Player/PlayerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
34 changes: 10 additions & 24 deletions Harmony/Player/PlayerQueueView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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) })
}
Expand All @@ -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: {
Expand All @@ -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)
Expand Down

0 comments on commit fd5f1db

Please sign in to comment.