fix(Turntable): correctly control the rotation of the turntable

This commit is contained in:
Grason Chan 2021-07-04 12:40:40 +08:00
parent 9c1e5dc7d4
commit 5cb616a78c

View File

@ -1,5 +1,4 @@
window.addEventListener("load", () => {
(function rotateTurntable() {
window.addEventListener("load", rotateTurntable = () => {
if (!Spicetify.Player.origin || !document.querySelector("#fad-art-image")) {
setTimeout(rotateTurntable, 250);
return;
@ -7,24 +6,29 @@ window.addEventListener("load", () => {
const fullAppDisplay = document.querySelector("#full-app-display");
function handleRotate() {
let playState;
function handleRotate(fromEvent) {
const fadArt = document.querySelector("#fad-art-image");
Spicetify.Player.isPlaying()
? fadArt.style.animationPlayState = "running"
: fadArt.style.animationPlayState = "paused";
if (!fromEvent && Spicetify.Player.isPlaying() || fromEvent && !playState) {
fadArt.style.animationPlayState = "running";
return playState = true;
} else {
fadArt.style.animationPlayState = "paused";
return playState = false;
}
}
handleRotate();
Spicetify.Player.addEventListener("onplaypause", () => setTimeout(handleRotate));
Spicetify.Player.addEventListener("onplaypause", () => handleRotate(true));
fullAppDisplay.addEventListener("contextmenu", () => {
const configSwitchBtns = document.querySelectorAll("#popup-config-container button.switch");
for (const configSwitch of configSwitchBtns) {
configSwitch.addEventListener("click", handleRotate);
configSwitch.addEventListener("click", () => handleRotate());
}
});
})();
});