fix(quick-14): add roll-back-on-failure to queue index advancement

- Next() rolls back currentIndex and skips emitIndexChanged on load failure
- Previous() applies same pattern to all three branches (RepeatOne, restart, navigate)
- OnPlaybackFinished() rolls back currentIndex on playCurrentTrack failure
- PlayIndex() and playFromStart() also guard against load failures
- RepeatOne paths guard emitIndexChanged with the bool return value
This commit is contained in:
2026-03-05 15:03:29 -05:00
parent 6eeddda976
commit 2820de2510
2 changed files with 53 additions and 15 deletions
+10 -2
View File
@@ -12,8 +12,9 @@ func (q *Queue) OnPlaybackFinished() {
// Repeat One: replay the current track. // Repeat One: replay the current track.
if q.repeatMode == RepeatOne { if q.repeatMode == RepeatOne {
q.playCurrentTrack() if q.playCurrentTrack() {
q.emitIndexChanged() q.emitIndexChanged()
}
return return
} }
@@ -26,7 +27,14 @@ func (q *Queue) OnPlaybackFinished() {
return return
} }
prevIndex := q.currentIndex
q.currentIndex = nextIdx q.currentIndex = nextIdx
q.playCurrentTrack()
if !q.playCurrentTrack() {
q.currentIndex = prevIndex
return
}
q.emitIndexChanged() q.emitIndexChanged()
} }
+38 -8
View File
@@ -880,8 +880,9 @@ func (q *Queue) Next() {
// Repeat One: replay the current track. // Repeat One: replay the current track.
if q.repeatMode == RepeatOne { if q.repeatMode == RepeatOne {
q.playOrLoadCurrentTrack(wasPlaying) if q.playOrLoadCurrentTrack(wasPlaying) {
q.emitIndexChanged() q.emitIndexChanged()
}
return return
} }
@@ -893,8 +894,15 @@ func (q *Queue) Next() {
return return
} }
prevIndex := q.currentIndex
q.currentIndex = nextIdx q.currentIndex = nextIdx
q.playOrLoadCurrentTrack(wasPlaying)
if !q.playOrLoadCurrentTrack(wasPlaying) {
q.currentIndex = prevIndex
return
}
q.emitIndexChanged() q.emitIndexChanged()
} }
@@ -913,8 +921,9 @@ func (q *Queue) Previous() {
// Repeat One: replay the current track. // Repeat One: replay the current track.
if q.repeatMode == RepeatOne { if q.repeatMode == RepeatOne {
q.playOrLoadCurrentTrack(wasPlaying) if q.playOrLoadCurrentTrack(wasPlaying) {
q.emitIndexChanged() q.emitIndexChanged()
}
return return
} }
@@ -923,8 +932,9 @@ func (q *Queue) Previous() {
if q.player != nil { if q.player != nil {
posSecs, err := q.player.CurrentPositionSeconds() posSecs, err := q.player.CurrentPositionSeconds()
if err == nil && posSecs > PreviousRestartThreshold { if err == nil && posSecs > PreviousRestartThreshold {
q.playOrLoadCurrentTrack(wasPlaying) if q.playOrLoadCurrentTrack(wasPlaying) {
q.emitIndexChanged() q.emitIndexChanged()
}
return return
} }
@@ -933,14 +943,22 @@ func (q *Queue) Previous() {
prevIdx := q.previousIndex() prevIdx := q.previousIndex()
if prevIdx == -1 { if prevIdx == -1 {
// At the beginning — just restart the current track. // At the beginning — just restart the current track.
q.playOrLoadCurrentTrack(wasPlaying) if q.playOrLoadCurrentTrack(wasPlaying) {
q.emitIndexChanged() q.emitIndexChanged()
}
return return
} }
prevCurrentIndex := q.currentIndex
q.currentIndex = prevIdx q.currentIndex = prevIdx
q.playOrLoadCurrentTrack(wasPlaying)
if !q.playOrLoadCurrentTrack(wasPlaying) {
q.currentIndex = prevCurrentIndex
return
}
q.emitIndexChanged() q.emitIndexChanged()
} }
@@ -1002,7 +1020,12 @@ func (q *Queue) playFromStart() {
q.currentIndex = 0 q.currentIndex = 0
} }
q.playCurrentTrack() if !q.playCurrentTrack() {
q.currentIndex = -1
return
}
q.emitIndexChanged() q.emitIndexChanged()
} }
@@ -1024,8 +1047,15 @@ func (q *Queue) PlayIndex(index int) {
return return
} }
prevIndex := q.currentIndex
q.currentIndex = index q.currentIndex = index
q.playCurrentTrack()
if !q.playCurrentTrack() {
q.currentIndex = prevIndex
return
}
q.emitIndexChanged() q.emitIndexChanged()
} }