Skip to content

Commit

Permalink
fix(popupLyrics): increase setTimeout time (#2808)
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri authored Feb 8, 2024
1 parent 905ab5a commit e061d27
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
33 changes: 19 additions & 14 deletions Extensions/popupLyrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion jsHelper/expFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion jsHelper/homeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion jsHelper/sidebarConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e061d27

Please sign in to comment.