FIX: #13 #20 colors would stopped updating after playing a local file without cover

This commit is contained in:
Julien Maille 2021-09-09 00:22:47 +02:00
parent 28d977631f
commit b52c9f889d

View file

@ -203,6 +203,7 @@ function updateColors(colHex) {
setRootColor('sidebar', colHex) setRootColor('sidebar', colHex)
} }
let coverListenerInstalled = true
async function songchange() { async function songchange() {
// warning popup // warning popup
if (Spicetify.PlaybackControl.featureVersion < "1.1.57") if (Spicetify.PlaybackControl.featureVersion < "1.1.57")
@ -214,6 +215,9 @@ async function songchange() {
bgImage = "/images/tracklist-row-song-fallback.svg" bgImage = "/images/tracklist-row-song-fallback.svg"
mainColor = "#509bf5" mainColor = "#509bf5"
updateColors(mainColor) updateColors(mainColor)
coverListenerInstalled = false
} else if (!coverListenerInstalled) {
hookCoverChange(true)
} }
if (album_uri !== undefined && !album_uri.includes('spotify:show')) { if (album_uri !== undefined && !album_uri.includes('spotify:show')) {
@ -260,7 +264,10 @@ function pickCoverColor(img) {
updateColors(mainColor) updateColors(mainColor)
} }
function hookCoverChange(pick) {
waitForElement([".cover-art-image"], (queries) => { waitForElement([".cover-art-image"], (queries) => {
coverListenerInstalled = true
if (pick) pickCoverColor(queries[0])
queries[0].addEventListener('load', function() { queries[0].addEventListener('load', function() {
try { try {
pickCoverColor(queries[0]) pickCoverColor(queries[0])
@ -270,6 +277,9 @@ waitForElement([".cover-art-image"], (queries) => {
} }
}); });
}); });
}
hookCoverChange(false);
(function Startup() { (function Startup() {
if (!Spicetify.showNotification) { if (!Spicetify.showNotification) {