« 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:
m---------tui-lib0
-rw-r--r--ui.js38
2 files changed, 13 insertions, 25 deletions
diff --git a/tui-lib b/tui-lib
-Subproject 6ca4f2e08d323b26940704eca89bdc71b4ed016
+Subproject aa38d1beb78635e5273b89b76c6a2b91428dd62
diff --git a/ui.js b/ui.js
index 6acebc7..12ef4b2 100644
--- a/ui.js
+++ b/ui.js
@@ -44,9 +44,6 @@ class AppElement extends FocusElement {
     this.markGrouplike = {name: 'Marked', items: []}
     this.editMode = false
 
-    // Crude hack...
-    this.recordStore.app = this
-
     this.rootDirectory = process.env.HOME + '/.mtui'
 
     this.paneLeft = new Pane()
@@ -60,7 +57,7 @@ class AppElement extends FocusElement {
 
     this.newGrouplikeListing()
 
-    this.queueListingElement = new QueueListingElement(this.recordStore)
+    this.queueListingElement = new QueueListingElement(this)
     this.setupCommonGrouplikeListingEvents(this.queueListingElement)
     this.queueListingElement.loadGrouplike(this.queueGrouplike)
     this.paneRight.addChild(this.queueListingElement)
@@ -122,7 +119,7 @@ class AppElement extends FocusElement {
   }
 
   newGrouplikeListing() {
-    const grouplikeListing = new GrouplikeListingElement(this.recordStore)
+    const grouplikeListing = new GrouplikeListingElement(this)
     this.tabber.addTab(grouplikeListing)
     this.tabber.selectTab(grouplikeListing)
 
@@ -770,7 +767,6 @@ class AppElement extends FocusElement {
       }
 
       await this.player.kill()
-      this.recordStore.getRecord(item).playing = true
       this.playingTrack = item
       this.playbackInfoElement.updateTrack(item)
 
@@ -785,13 +781,7 @@ class AppElement extends FocusElement {
           JSON.stringify(item, null, 2))
       ])
 
-      try {
-        await this.player.playFile(downloadFile)
-      } finally {
-        if (playingThisTrack || this.playingTrack !== item) {
-          this.recordStore.getRecord(item).playing = false
-        }
-      }
+      await this.player.playFile(downloadFile)
     }
 
     // playingThisTrack now means whether the track played through to the end
@@ -905,13 +895,11 @@ class GrouplikeListingElement extends Form {
   //
   // August 15th, 2018
 
-  constructor(recordStore) {
+  constructor(app) {
     super()
 
-    this.recordStore = recordStore
-
     this.grouplike = null
-    this.recordStore = recordStore
+    this.app = app
 
     this.form = this.getNewForm()
     this.addInput(this.form)
@@ -989,7 +977,7 @@ class GrouplikeListingElement extends Form {
     } else if (telc.isCharacter(keyBuf, 'G')) {
       this.form.selectAndShow(this.grouplike.items[this.grouplike.items.length - 1])
     } else if (keyBuf[0] === 12 && this.grouplike.isTheQueue) { // ctrl-L
-      this.form.selectAndShow(this.recordStore.app.playingTrack)
+      this.form.selectAndShow(this.app.playingTrack)
     } else {
       return super.keyPressed(keyBuf)
     }
@@ -1031,7 +1019,7 @@ class GrouplikeListingElement extends Form {
       if (!this.grouplike.isTheQueue) {
         const ownElement = new BasicGrouplikeItemElement(`This group: ${this.grouplike.name || '(Unnamed group)'}`)
         ownElement.item = this.grouplike
-        ownElement.recordStore = this.recordStore
+        ownElement.app = this.app
         ownElement.isGroup = true
         ownElement.on('pressed', () => {
           ownElement.emit('menu', ownElement)
@@ -1042,7 +1030,7 @@ class GrouplikeListingElement extends Form {
 
       // Add the elements for all the actual items within this playlist.
       for (const item of this.grouplike.items) {
-        const itemElement = new InteractiveGrouplikeItemElement(item, this.recordStore)
+        const itemElement = new InteractiveGrouplikeItemElement(item, this.app)
         this.addEventListeners(itemElement)
         form.addInput(itemElement)
       }
@@ -1430,10 +1418,10 @@ class InlineListPickerElement extends FocusElement {
 }
 
 class InteractiveGrouplikeItemElement extends BasicGrouplikeItemElement {
-  constructor(item, recordStore) {
+  constructor(item, app) {
     super(item.name)
     this.item = item
-    this.recordStore = recordStore
+    this.app = app
   }
 
   drawTo(writable) {
@@ -1493,7 +1481,7 @@ class InteractiveGrouplikeItemElement extends BasicGrouplikeItemElement {
     const braille = '⠈⠐⠠⠄⠂⠁'
     const brailleChar = braille[Math.floor(Date.now() / 250) % 6]
 
-    const record = this.recordStore.getRecord(this.item)
+    const record = this.app.recordStore.getRecord(this.item)
 
     if (this.isMarked) {
       writable.write('M')
@@ -1505,7 +1493,7 @@ class InteractiveGrouplikeItemElement extends BasicGrouplikeItemElement {
       writable.write('G')
     } else if (record.downloading) {
       writable.write(braille[Math.floor(Date.now() / 250) % 6])
-    } else if (record.playing) {
+    } else if (this.app.playingTrack === this.item) {
       writable.write('\u25B6')
     } else {
       writable.write(' ')
@@ -1515,7 +1503,7 @@ class InteractiveGrouplikeItemElement extends BasicGrouplikeItemElement {
   }
 
   get isMarked() {
-    return this.recordStore.app.editMode && this.recordStore.app.markGrouplike.items.includes(this.item)
+    return this.app.editMode && this.app.markGrouplike.items.includes(this.item)
   }
 
   get isGroup() {