« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/ui.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js73
1 files changed, 55 insertions, 18 deletions
diff --git a/ui.js b/ui.js
index 8d89722..fb0916e 100644
--- a/ui.js
+++ b/ui.js
@@ -206,7 +206,8 @@ class AppElement extends FocusElement {
       canSuspend: true,
       menubarColor: 4, // blue
       showTabberPane: true,
-      stopPlayingUponQuit: true
+      stopPlayingUponQuit: true,
+      showPartyControls: false
     }, config)
 
     // TODO: Move edit mode stuff to the backend!
@@ -456,6 +457,8 @@ class AppElement extends FocusElement {
       'handleAddedQueuePlayer',
       'handleRemovedQueuePlayer',
       'handleLogMessage',
+      'handleGotPartyGrouplike',
+      'handlePartyGrouplikeUpdated',
       'handleSetLoopQueueAtEnd'
     ]) {
       this[key] = this[key].bind(this)
@@ -528,6 +531,8 @@ 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('got party grouplike', this.handleGotPartyGrouplike)
+    this.backend.on('party grouplike updated', this.handlePartyGrouplikeUpdated)
     this.backend.on('set-loop-queue-at-end', this.handleSetLoopQueueAtEnd)
   }
 
@@ -536,6 +541,8 @@ 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('got party grouplike', this.handleGotPartyGrouplike)
+    this.backend.removeListener('party grouplike updated', this.handlePartyGrouplikeUpdated)
     this.backend.removeListener('set-loop-queue-at-end', this.handleSetLoopQueueAtEnd)
   }
 
@@ -554,6 +561,18 @@ class AppElement extends FocusElement {
     this.log.newLogMessage(messageInfo)
   }
 
+  handleGotPartyGrouplike(partyGrouplike) {
+    this.newPartyTab(partyGrouplike)
+  }
+
+  handlePartyGrouplikeUpdated(partyGrouplike) {
+    for (const grouplikeListing of this.tabber.tabberElements) {
+      if (grouplikeListing.grouplike === partyGrouplike) {
+        grouplikeListing.loadGrouplike(partyGrouplike, false)
+      }
+    }
+  }
+
   handleSetLoopQueueAtEnd() {
     this.updateQueueLengthLabel()
   }
@@ -888,6 +907,10 @@ class AppElement extends FocusElement {
     this.queueListingElement.selectAndShow(item)
   }
 
+  shareWithParty(item) {
+    this.backend.shareWithParty(item)
+  }
+
   replaceMark(items) {
     this.markGrouplike.items = items.slice(0) // Don't share the array! :)
     this.emitMarkChanged()
@@ -1124,7 +1147,9 @@ class AppElement extends FocusElement {
         })
       }
 
+      const rootGroup = getItemPath(item)[0]
       const hasNotesFile = !!getCorrespondingFileForItem(item, '.txt')
+
       if (listing.grouplike.isTheQueue && isTrack(item)) {
         return [
           item[parentSymbol] && this.tabberPane.visible && {label: 'Reveal', action: () => this.reveal(item)},
@@ -1169,23 +1194,30 @@ class AppElement extends FocusElement {
           {divider: true},
           */
 
-          canControlQueue && isPlayable(item) && {element: this.whereControl},
-          canControlQueue && isGroup(item) && {element: this.orderControl},
-          canControlQueue && isPlayable(item) && {label: 'Play!', action: emitControls(true)},
-          canControlQueue && isPlayable(item) && {label: 'Queue!', action: emitControls(false)},
-          {divider: true},
-
-          canProcessMetadata && isGroup(item) && {label: 'Process metadata (new entries)', action: () => setTimeout(() => this.processMetadata(item, false))},
-          canProcessMetadata && isGroup(item) && {label: 'Process metadata (reprocess)', action: () => setTimeout(() => this.processMetadata(item, true))},
-          canProcessMetadata && isTrack(item) && {label: 'Process metadata', action: () => setTimeout(() => this.processMetadata(item, true))},
-          isOpenable(item) && item.url.endsWith('.json') && {label: 'Open (JSON Playlist)', action: () => this.openSpecialOrThroughSystem(item)},
-          isOpenable(item) && {label: 'Open (System)', action: () => this.openThroughSystem(item)},
-          /*
-          !hasNotesFile && isPlayable(item) && {label: 'Create notes file', action: () => this.editNotesFile(item, true)},
-          hasNotesFile && isPlayable(item) && {label: 'Edit notes file', action: () => this.editNotesFile(item, true)},
-          */
-          canControlQueue && isPlayable(item) && {label: 'Remove from queue', action: () => this.unqueue(item)},
-          {divider: true},
+          ...((this.config.showPartyControls && !rootGroup.isPartySources)
+            ? [
+              {label: 'Share with party', action: () => this.shareWithParty(item)},
+              {divider: true}
+            ]
+            : [
+              canControlQueue && isPlayable(item) && {element: this.whereControl},
+              canControlQueue && isGroup(item) && {element: this.orderControl},
+              canControlQueue && isPlayable(item) && {label: 'Play!', action: emitControls(true)},
+              canControlQueue && isPlayable(item) && {label: 'Queue!', action: emitControls(false)},
+              {divider: true},
+
+              canProcessMetadata && isGroup(item) && {label: 'Process metadata (new entries)', action: () => setTimeout(() => this.processMetadata(item, false))},
+              canProcessMetadata && isGroup(item) && {label: 'Process metadata (reprocess)', action: () => setTimeout(() => this.processMetadata(item, true))},
+              canProcessMetadata && isTrack(item) && {label: 'Process metadata', action: () => setTimeout(() => this.processMetadata(item, true))},
+              isOpenable(item) && item.url.endsWith('.json') && {label: 'Open (JSON Playlist)', action: () => this.openSpecialOrThroughSystem(item)},
+              isOpenable(item) && {label: 'Open (System)', action: () => this.openThroughSystem(item)},
+              /*
+              !hasNotesFile && isPlayable(item) && {label: 'Create notes file', action: () => this.editNotesFile(item, true)},
+              hasNotesFile && isPlayable(item) && {label: 'Edit notes file', action: () => this.editNotesFile(item, true)},
+              */
+              canControlQueue && isPlayable(item) && {label: 'Remove from queue', action: () => this.unqueue(item)},
+              {divider: true},
+            ]),
 
           ...(item === this.markGrouplike
             ? [{label: 'Deselect all', action: () => this.unmarkAll()}]
@@ -1547,6 +1579,11 @@ class AppElement extends FocusElement {
     })
   }
 
+  newPartyTab(partyGrouplike) {
+    const listing = this.newGrouplikeListing()
+    listing.loadGrouplike(partyGrouplike)
+  }
+
   cloneCurrentTab() {
     const grouplike = this.tabber.currentElement.grouplike
     const listing = this.newGrouplikeListing()