« get me outta code hell

Fix a crash, I think?? - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorliam4 <towerofnix@gmail.com>2017-06-21 21:53:29 +0000
committerliam4 <towerofnix@gmail.com>2017-06-21 21:53:29 +0000
commitaf4749b962a7c5c488f52ae2b6f2ff0fe3d920a0 (patch)
tree2d223469e4d04af7abafd3acd8801ae31517fd2a /src
parent0f6be3c9f221aeed36970fc488c812ee1dadd97f (diff)
Fix a crash, I think??
Diffstat (limited to 'src')
-rw-r--r--src/loop-play.js12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/loop-play.js b/src/loop-play.js
index e43cb31..597b58d 100644
--- a/src/loop-play.js
+++ b/src/loop-play.js
@@ -33,10 +33,10 @@ class DownloadController extends EventEmitter {
   async downloadNextHelper() {
     this.isDownloading = true
 
-    let wasDestroyed = false
+    const destroyedObj = {wasDestroyed: false}
 
     this._destroyDownload = () => {
-      wasDestroyed = true
+      destroyedObj.wasDestroyed = true
     }
 
     // We need to actually pick something to download; we'll use the picker
@@ -79,13 +79,13 @@ class DownloadController extends EventEmitter {
     if (supportedFormats.includes(format)) {
       this.playFile = fromFile
     } else {
-      this.playFile = await this.convert(picked, fromFile)
+      this.playFile = await this.convert(picked, fromFile, destroyedObj)
     }
 
     // If this download was destroyed, we quit now; we don't want to emit that
     // the download was finished if the finished download was the destroyed
     // one!
-    if (wasDestroyed) {
+    if (destroyedObj.wasDestroyed) {
       return
     }
 
@@ -131,7 +131,7 @@ class DownloadController extends EventEmitter {
     return formats
   }
 
-  async convert(picked, fromFile) {
+  async convert(picked, fromFile, destroyedObj) {
     // The "to" file is simply an MP3 file. We give this MP3 file a specific
     // name - the title of the track we got earlier, sanitized to be file-safe
     // - so that when `play` outputs the name of the song, it's obvious to the
@@ -179,7 +179,7 @@ class DownloadController extends EventEmitter {
       // Usually we'll log a warning message saying that the convertion failed,
       // but if this download was destroyed, it's expected for the avconv
       // process to fail; so in that case we don't bother warning the user.
-      if (!wasDestroyed) {
+      if (!destroyedObj.wasDestroyed) {
         console.warn("Failed to convert " + title)
         console.warn("Selecting a new track")