« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--backend.js4
-rw-r--r--ui.js16
2 files changed, 18 insertions, 2 deletions
diff --git a/backend.js b/backend.js
index 98d748b..ad13127 100644
--- a/backend.js
+++ b/backend.js
@@ -573,6 +573,7 @@ class QueuePlayer extends EventEmitter {
 
   setLoopQueueAtEnd(value) {
     this.loopQueueAtEnd = !!value
+    this.emit('set-loop-queue-at-end', !!value)
   }
 
   get remainingTracks() {
@@ -667,7 +668,8 @@ class Backend extends EventEmitter {
       'vol-up',
       'vol-down',
       'set-volume',
-      'set-pause-next-track'
+      'set-pause-next-track',
+      'set-loop-queue-at-end'
     ]) {
       queuePlayer.on(event, (...data) => {
         this.emit(event, queuePlayer, ...data)
diff --git a/ui.js b/ui.js
index de73a81..a167dab 100644
--- a/ui.js
+++ b/ui.js
@@ -435,7 +435,8 @@ class AppElement extends FocusElement {
       'handleProcessMetadataProgress',
       'handleQueueUpdated',
       'handleAddedQueuePlayer',
-      'handleRemovedQueuePlayer'
+      'handleRemovedQueuePlayer',
+      'handleSetLoopQueueAtEnd'
     ]) {
       this[key] = this[key].bind(this)
     }
@@ -506,12 +507,14 @@ class AppElement extends FocusElement {
     this.backend.on('processMetadata progress', this.handleProcessMetadataProgress)
     this.backend.on('added queue player', this.handleAddedQueuePlayer)
     this.backend.on('removed queue player', this.handleRemovedQueuePlayer)
+    this.backend.on('set-loop-queue-at-end', this.handleSetLoopQueueAtEnd)
   }
 
   removeBackendListeners() {
     this.backend.removeListener('processMetadata progress', this.handleProcessMetadataProgress)
     this.backend.removeListener('added queue player', this.handleAddedQueuePlayer)
     this.backend.removeListener('removed queue player', this.handleRemovedQueuePlayer)
+    this.backend.removeListener('set-loop-queue-at-end', this.handleSetLoopQueueAtEnd)
   }
 
   handleAddedQueuePlayer(queuePlayer) {
@@ -525,6 +528,10 @@ class AppElement extends FocusElement {
     }
   }
 
+  handleSetLoopQueueAtEnd() {
+    this.updateQueueLengthLabel()
+  }
+
   async handlePlaying(track, oldTrack, queuePlayer) {
     const PIE = this.getPlaybackInfoElementForQueuePlayer(queuePlayer)
     if (PIE) {
@@ -1725,13 +1732,16 @@ class AppElement extends FocusElement {
     const { duration: durationString } = getTimeStringsFromSec(0, durationTotal)
     this.queueTimeLabel.text = `(${durationSymbol + durationString + approxSymbol})`
 
+    let collapseExtraInfo = false
     if (playingTrack) {
       let insertString
       const distance = Math.abs(selectedIndex - playingIndex)
       if (selectedIndex < playingIndex) {
         insertString = ` (-${distance})`
+        collapseExtraInfo = true
       } else if (selectedIndex > playingIndex) {
         insertString = ` (+${distance})`
+        collapseExtraInfo = true
       } else {
         insertString = ''
       }
@@ -1740,6 +1750,10 @@ class AppElement extends FocusElement {
       this.queueLengthLabel.text = `(${items.length})`
     }
 
+    if (this.SQP.loopQueueAtEnd) {
+      this.queueLengthLabel.text += (collapseExtraInfo ? ` [L${unic.ELLIPSIS}]` : ` [Looping]`)
+    }
+
     // Layout stuff to position the length and time labels correctly.
     this.queueLengthLabel.centerInParent()
     this.queueTimeLabel.centerInParent()