From e061d27621a6ed029dc21a0cd8360a7f251ef7e2 Mon Sep 17 00:00:00 2001 From: ririxi Date: Thu, 8 Feb 2024 01:44:50 +0100 Subject: [PATCH] fix(popupLyrics): increase setTimeout time (#2808) --- Extensions/popupLyrics.js | 33 +++++++++++++++++++-------------- jsHelper/expFeatures.js | 2 +- jsHelper/homeConfig.js | 2 +- jsHelper/sidebarConfig.js | 2 +- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Extensions/popupLyrics.js b/Extensions/popupLyrics.js index 421656b74b..4b4cd2ad67 100644 --- a/Extensions/popupLyrics.js +++ b/Extensions/popupLyrics.js @@ -14,7 +14,7 @@ if (!navigator.serviceWorker) { onmessage = event => { if (event.data === "popup-lyric-request-update") { console.warn("popup-lyric-request-update"); - num = setInterval(() => postMessage("popup-lyric-update-ui"), 8); + num = setInterval(() => postMessage("popup-lyric-update-ui"), 16.66); } else if (event.data === "popup-lyric-stop-update") { clearInterval(num); num = null; @@ -693,12 +693,15 @@ function PopupLyrics() { } let workerIsRunning = null; + let timeout = null; async function tick(options) { if (!lyricVideoIsOpen) { return; } + if (timeout) clearTimeout(timeout); + const audio = { currentTime: (Player.getProgress() - Number(options.delay)) / 1000, duration: Player.getDuration() / 1000 @@ -719,22 +722,24 @@ function PopupLyrics() { } else if (!audio.duration || lyrics.length === 0) { drawText(lyricCtx, audio.currentSrc ? "Loading" : "Waiting"); } - if (lyrics?.length) { - if (document.hidden) { - if (!workerIsRunning) { - worker.postMessage("popup-lyric-request-update"); - workerIsRunning = true; - } - } else { - if (workerIsRunning) { - worker.postMessage("popup-lyric-stop-update"); - workerIsRunning = false; - } - requestAnimationFrame(() => tick(options)); + if (!lyrics?.length) { + timeout = setTimeout(tick, 1000, options); + return; + } + + if (document.hidden) { + if (!workerIsRunning) { + worker.postMessage("popup-lyric-request-update"); + workerIsRunning = true; } } else { - setTimeout(tick, 80, options); + if (workerIsRunning) { + worker.postMessage("popup-lyric-stop-update"); + workerIsRunning = false; + } + + requestAnimationFrame(() => tick(options)); } } diff --git a/jsHelper/expFeatures.js b/jsHelper/expFeatures.js index 89ea1caac8..dbe730e225 100644 --- a/jsHelper/expFeatures.js +++ b/jsHelper/expFeatures.js @@ -269,7 +269,7 @@ ${Spicetify.SVGIcons.search} setOverrides(Spicetify.createInternalMap?.(featureMap)); })(); - await new Promise(Spicetify.Events.webpackLoaded.on); + await new Promise(res => Spicetify.Events.webpackLoaded.on(res)); new Spicetify.Menu.Item( "Experimental features", diff --git a/jsHelper/homeConfig.js b/jsHelper/homeConfig.js index e69157aee1..a2a56477f2 100644 --- a/jsHelper/homeConfig.js +++ b/jsHelper/homeConfig.js @@ -163,7 +163,7 @@ SpicetifyHomeConfig = {}; } } - await new Promise(Spicetify.Events.webpackLoaded.on); + await new Promise(res => Spicetify.Events.webpackLoaded.on(res)); const menu = new Spicetify.Menu.Item("Home config", true, self => { self.isEnabled = !self.isEnabled; diff --git a/jsHelper/sidebarConfig.js b/jsHelper/sidebarConfig.js index a973020ab7..637ca78772 100644 --- a/jsHelper/sidebarConfig.js +++ b/jsHelper/sidebarConfig.js @@ -169,7 +169,7 @@ color: var(--spice-button-disabled); } (async () => { - await new Promise(Spicetify.Events.webpackLoaded.on); + await new Promise(res => Spicetify.Events.webpackLoaded.on(res)); new Spicetify.Menu.Item( "Sidebar config", true,