« get me outta code hell

Hide/fix weird bug with empty downloaderArgs - 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:
authorFlorrie <towerofnix@gmail.com>2018-06-26 22:11:35 -0300
committerFlorrie <towerofnix@gmail.com>2018-06-26 22:11:47 -0300
commit2d41fd5ce9e2c821ea4da8a6650f445dbf48d641 (patch)
treef48af3fe769b7258b9689d6df913ef2dfa20fa73 /ui.js
parent992911a021e2f2cccfbc63e554a3f34bd997cd91 (diff)
Hide/fix weird bug with empty downloaderArgs
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js60
1 files changed, 34 insertions, 26 deletions
diff --git a/ui.js b/ui.js
index 371958d..9a5b727 100644
--- a/ui.js
+++ b/ui.js
@@ -312,38 +312,46 @@ class AppElement extends FocusElement {
 
     // TODO: Check if it's an item or a group
 
-    // If, by the time the track is downloaded, we're playing something
-    // different from when the download started, assume that we just want to
-    // keep listening to whatever new thing we started.
+    playTrack: {
+      // No downloader argument? That's no good - stop here.
+      // TODO: An error icon on this item, or something???
+      if (!item.downloaderArg) {
+        break playTrack
+      }
 
-    const oldTrack = this.playingTrack
+      // If, by the time the track is downloaded, we're playing something
+      // different from when the download started, assume that we just want to
+      // keep listening to whatever new thing we started.
 
-    const downloadFile = await this.downloadGrouplikeItem(item)
+      const oldTrack = this.playingTrack
 
-    if (this.playingTrack !== oldTrack) {
-      return
-    }
+      const downloadFile = await this.downloadGrouplikeItem(item)
 
-    await this.player.kill()
-    this.recordStore.getRecord(item).playing = true
-    this.playingTrack = item
-    this.playbackInfoElement.updateTrack(item)
-    if (!this.queueListingElement.isSelected) {
-      this.queueListingElement.selectAndShow(item)
-    }
+      if (this.playingTrack !== oldTrack) {
+        return
+      }
 
-    await Promise.all([
-      writeFile(this.rootDirectory + '/current-track.txt',
-        getItemPathString(item)),
-      writeFile(this.rootDirectory + '/current-track.json',
-        JSON.stringify(item, null, 2))
-    ])
+      await this.player.kill()
+      this.recordStore.getRecord(item).playing = true
+      this.playingTrack = item
+      this.playbackInfoElement.updateTrack(item)
+      if (!this.queueListingElement.isSelected) {
+        this.queueListingElement.selectAndShow(item)
+      }
 
-    try {
-      await this.player.playFile(downloadFile)
-    } finally {
-      if (playingThisTrack || this.playingTrack !== item) {
-        this.recordStore.getRecord(item).playing = false
+      await Promise.all([
+        writeFile(this.rootDirectory + '/current-track.txt',
+          getItemPathString(item)),
+        writeFile(this.rootDirectory + '/current-track.json',
+          JSON.stringify(item, null, 2))
+      ])
+
+      try {
+        await this.player.playFile(downloadFile)
+      } finally {
+        if (playingThisTrack || this.playingTrack !== item) {
+          this.recordStore.getRecord(item).playing = false
+        }
       }
     }