diff options
-rw-r--r-- | ui.js | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/ui.js b/ui.js index d9db800..eb6b8f9 100644 --- a/ui.js +++ b/ui.js @@ -1117,7 +1117,23 @@ class AppElement extends FocusElement { trackRemainSec = lenSecTotal - curSecTotal } - const index = items.indexOf(this.playingTrack) + 1 + // Index of tracks "ahead" of the current track. All tracks before this + // index are accounted for by either being behind the current track (and + // thus ignorable) or being the current track (and thus having its + // remaining duration be counted by the time data stored on the playback + // info element). + let index = 0 + + if (this.playingTrack) { + index = items.indexOf(this.playingTrack) + // If it's NOT counted by the playback info element's time data yet, + // we skip this - the current track is counted as "ahead" and its + // duration will be tallied like the rest of the "ahead" tracks. + if (Object.keys(this.playbackInfoElement.timeData).length) { + index++ + } + } + const aheadRemainSec = items.slice(index).reduce(durationFn, 0) const totalRemainSec = trackRemainSec + aheadRemainSec @@ -2178,6 +2194,7 @@ class PlaybackInfoElement extends DisplayElement { this.trackNameLabel.text = track.name this.progressBarLabel.text = '' this.progressTextLabel.text = '(Starting..)' + this.timeData = {} this.fixLayout() } @@ -2187,6 +2204,7 @@ class PlaybackInfoElement extends DisplayElement { this.progressTextLabel.text = '' this.trackNameLabel.text = '' this.downloadLabel.text = '' + this.timeData = {} this.fixLayout() } } |