« get me outta code hell

fix a bunch of crashes when acting before timeData - 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-10-10 10:34:11 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-10-10 10:34:58 -0300
commit24ed3e0bf3542f8cf32ed03399dd455be4d5435f (patch)
treeb31d4e85f0611f271e67cbecf69d6194ab432e09
parentb709c931dc01e411e06b7a596b26d36921c13be4 (diff)
fix a bunch of crashes when acting before timeData
...is provided by the player
-rw-r--r--ui.js15
1 files changed, 11 insertions, 4 deletions
diff --git a/ui.js b/ui.js
index df8d914..1331344 100644
--- a/ui.js
+++ b/ui.js
@@ -1257,7 +1257,9 @@ class AppElement extends FocusElement {
       if (qp.timeData) {
         let effectiveCurSec = qp.timeData.curSecTotal
 
-        const ts = this.getTimestampAtSec(qp.playingTrack, qp.timeData.curSecTotal)
+        const ts = (qp.timeData &&
+          this.getTimestampAtSec(qp.playingTrack, qp.timeData.curSecTotal))
+
         if (ts) {
           effectiveCurSec -= ts.timestamp
         }
@@ -1280,7 +1282,9 @@ class AppElement extends FocusElement {
         return
       }
 
-      const ts = this.getTimestampAtSec(qp.playingTrack, qp.timeData.curSecTotal)
+      const ts = (qp.timeData &&
+        this.getTimestampAtSec(qp.playingTrack, qp.timeData.curSecTotal))
+
       if (ts) {
         qp.seekTo(ts.timestamp)
         return
@@ -1296,7 +1300,9 @@ class AppElement extends FocusElement {
         return
       }
 
-      const ts = this.getTimestampAtSec(qp.playingTrack, qp.timeData.curSecTotal)
+      const ts = (qp.timeData &&
+        this.getTimestampAtSec(qp.playingTrack, qp.timeData.curSecTotal))
+
       if (ts) {
         const timestampData = this.getTimestampData(qp.playingTrack)
         const playingTimestampIndex = timestampData.indexOf(ts)
@@ -1317,7 +1323,8 @@ class AppElement extends FocusElement {
         return
       }
 
-      const ts = this.getTimestampAtSec(qp.playingTrack, qp.timeData.curSecTotal)
+      const ts = (qp.timeData &&
+        this.getTimestampAtSec(qp.playingTrack, qp.timeData.curSecTotal))
 
       if (ts) {
         const timestampData = this.getTimestampData(qp.playingTrack)