Skip to content

Commit 5944d06

Browse files
authored
fix(popupLyrics): update view in system tray mode (#3330)
1 parent a678cfd commit 5944d06

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

Extensions/popupLyrics.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ if (!navigator.serviceWorker) {
1818
num = setInterval(() => postMessage("popup-lyric-update-ui"), 16.66);
1919
} else if (event.data === "popup-lyric-stop-update") {
2020
clearInterval(num);
21+
postMessage("popup-lyric-update-ui");
2122
num = null;
2223
}
2324
};
@@ -42,6 +43,21 @@ function PopupLyrics() {
4243
}
4344
};
4445

46+
let workerIsRunning = null;
47+
document.addEventListener("visibilitychange", (e) => {
48+
if (e.target.hidden) {
49+
if (!workerIsRunning) {
50+
worker.postMessage("popup-lyric-request-update");
51+
workerIsRunning = true;
52+
}
53+
} else {
54+
if (workerIsRunning) {
55+
worker.postMessage("popup-lyric-stop-update");
56+
workerIsRunning = false;
57+
}
58+
}
59+
});
60+
4561
const LyricUtils = {
4662
normalize(s, emptySymbol = true) {
4763
const result = s
@@ -457,7 +473,6 @@ function PopupLyrics() {
457473

458474
try {
459475
const data = await service.call(info);
460-
console.log(data);
461476
sharedData = data;
462477
CACHE[info.uri] = sharedData;
463478

@@ -765,7 +780,6 @@ function PopupLyrics() {
765780
ctx.restore();
766781
}
767782

768-
let workerIsRunning = null;
769783
let timeout = null;
770784

771785
async function tick(options) {
@@ -801,17 +815,7 @@ function PopupLyrics() {
801815
return;
802816
}
803817

804-
if (document.hidden) {
805-
if (!workerIsRunning) {
806-
worker.postMessage("popup-lyric-request-update");
807-
workerIsRunning = true;
808-
}
809-
} else {
810-
if (workerIsRunning) {
811-
worker.postMessage("popup-lyric-stop-update");
812-
workerIsRunning = false;
813-
}
814-
818+
if (!document.hidden) {
815819
requestAnimationFrame(() => tick(options));
816820
}
817821
}
@@ -910,7 +914,6 @@ button.btn:disabled {
910914
}
911915
#popup-config-container input {
912916
width: 100%;
913-
margin-top: 10px;
914917
padding: 0 5px;
915918
height: 32px;
916919
border: 0;

0 commit comments

Comments
 (0)