« get me outta code hell

Merge commit 'fe603bc' into socket-mtui - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-03-24 00:37:43 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-03-24 00:37:43 -0300
commitbbca8d151cdf498bc67f3936859f8ab2299d5eac (patch)
tree83b2b50345e0ed5034d0683c889e551c16c78557
parent432c11bdc4a9f22fa179e6a45eff4da8d96392b6 (diff)
parentfe603bc08f14d8fb86d1d832850ee8709f307f75 (diff)
Merge commit 'fe603bc' into socket-mtui
-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 4c84b04..349d7f3 100644
--- a/backend.js
+++ b/backend.js
@@ -627,6 +627,7 @@ class QueuePlayer extends EventEmitter {
 
   setLoopQueueAtEnd(value) {
     this.loopQueueAtEnd = !!value
+    this.emit('set-loop-queue-at-end', !!value)
   }
 
   get remainingTracks() {
@@ -726,7 +727,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 c948080..8d89722 100644
--- a/ui.js
+++ b/ui.js
@@ -455,7 +455,8 @@ class AppElement extends FocusElement {
       'handleQueueUpdated',
       'handleAddedQueuePlayer',
       'handleRemovedQueuePlayer',
-      'handleLogMessage'
+      'handleLogMessage',
+      'handleSetLoopQueueAtEnd'
     ]) {
       this[key] = this[key].bind(this)
     }
@@ -527,6 +528,7 @@ class AppElement extends FocusElement {
     this.backend.on('added queue player', this.handleAddedQueuePlayer)
     this.backend.on('removed queue player', this.handleRemovedQueuePlayer)
     this.backend.on('log message', this.handleLogMessage)
+    this.backend.on('set-loop-queue-at-end', this.handleSetLoopQueueAtEnd)
   }
 
   removeBackendListeners() {
@@ -534,6 +536,7 @@ class AppElement extends FocusElement {
     this.backend.removeListener('added queue player', this.handleAddedQueuePlayer)
     this.backend.removeListener('removed queue player', this.handleRemovedQueuePlayer)
     this.backend.removeListener('log message', this.handleLogMessage)
+    this.backend.removeListener('set-loop-queue-at-end', this.handleSetLoopQueueAtEnd)
   }
 
   handleAddedQueuePlayer(queuePlayer) {
@@ -551,6 +554,10 @@ class AppElement extends FocusElement {
     this.log.newLogMessage(messageInfo)
   }
 
+  handleSetLoopQueueAtEnd() {
+    this.updateQueueLengthLabel()
+  }
+
   async handlePlayingDetails(track, oldTrack, queuePlayer) {
     const PIE = this.getPlaybackInfoElementForQueuePlayer(queuePlayer)
     if (PIE) {
@@ -1765,13 +1772,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 = ''
       }
@@ -1780,6 +1790,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()