@@ -18,6 +18,7 @@ if (!navigator.serviceWorker) {
18
18
num = setInterval ( ( ) => postMessage ( "popup-lyric-update-ui" ) , 16.66 ) ;
19
19
} else if ( event . data === "popup-lyric-stop-update" ) {
20
20
clearInterval ( num ) ;
21
+ postMessage ( "popup-lyric-update-ui" ) ;
21
22
num = null ;
22
23
}
23
24
} ;
@@ -42,6 +43,21 @@ function PopupLyrics() {
42
43
}
43
44
} ;
44
45
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
+
45
61
const LyricUtils = {
46
62
normalize ( s , emptySymbol = true ) {
47
63
const result = s
@@ -457,7 +473,6 @@ function PopupLyrics() {
457
473
458
474
try {
459
475
const data = await service . call ( info ) ;
460
- console . log ( data ) ;
461
476
sharedData = data ;
462
477
CACHE [ info . uri ] = sharedData ;
463
478
@@ -765,7 +780,6 @@ function PopupLyrics() {
765
780
ctx . restore ( ) ;
766
781
}
767
782
768
- let workerIsRunning = null ;
769
783
let timeout = null ;
770
784
771
785
async function tick ( options ) {
@@ -801,17 +815,7 @@ function PopupLyrics() {
801
815
return ;
802
816
}
803
817
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 ) {
815
819
requestAnimationFrame ( ( ) => tick ( options ) ) ;
816
820
}
817
821
}
@@ -910,7 +914,6 @@ button.btn:disabled {
910
914
}
911
915
#popup-config-container input {
912
916
width: 100%;
913
- margin-top: 10px;
914
917
padding: 0 5px;
915
918
height: 32px;
916
919
border: 0;
0 commit comments