fix: Improve Spotify widget visibility
All checks were successful
Build Docker / BuildImage (push) Successful in 2m55s
All checks were successful
Build Docker / BuildImage (push) Successful in 2m55s
This commit is contained in:
@@ -54,7 +54,7 @@ def refresh_access_token():
|
|||||||
def login():
|
def login():
|
||||||
auth_query = (
|
auth_query = (
|
||||||
f"{SPOTIFY_AUTH_URL}?response_type=code&client_id={CLIENT_ID}"
|
f"{SPOTIFY_AUTH_URL}?response_type=code&client_id={CLIENT_ID}"
|
||||||
f"&redirect_uri={url_for("spotify.callback", _external=True)}&scope={SCOPE}"
|
f"&redirect_uri={url_for('spotify.callback', _external=True)}&scope={SCOPE}"
|
||||||
)
|
)
|
||||||
return redirect(auth_query)
|
return redirect(auth_query)
|
||||||
|
|
||||||
|
|||||||
@@ -410,38 +410,41 @@ async function updateSpotifyWidget() {
|
|||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
// Check if data contains an error or message indicating nothing is playing
|
// Check if data contains an error or message indicating nothing is playing
|
||||||
if (data.error || data.message) {
|
if (data.error || data.message) {
|
||||||
widget.style.opacity = 0.5;
|
|
||||||
|
|
||||||
// If existing data
|
// If existing data
|
||||||
if (document.getElementById('spotify-song').textContent) {
|
if (document.getElementById('spotify-song').textContent) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
// Alternate text when nothing is playing
|
// Alternate text when nothing is playing
|
||||||
document.getElementById('spotify-album-art').src = '/assets/img/external/spotify.png';
|
document.getElementById('spotify-album-art').src = '/assets/img/external/spotify.png';
|
||||||
document.getElementById('spotify-song').textContent = 'Not Playing';
|
document.getElementById('spotify-song').textContent = 'Not Playing';
|
||||||
document.getElementById('spotify-artist').textContent = '';
|
document.getElementById('spotify-artist').textContent = '';
|
||||||
document.getElementById('spotify-album').textContent = '';
|
document.getElementById('spotify-album').textContent = '';
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const track = data.spotify;
|
const track = data.spotify;
|
||||||
|
var firstLoad = false;
|
||||||
|
// Check if this is the first time loading data
|
||||||
|
if (!document.getElementById('spotify-song').textContent) {
|
||||||
|
firstLoad = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
document.getElementById('spotify-album-art').src = track.album_art;
|
document.getElementById('spotify-album-art').src = track.album_art;
|
||||||
document.getElementById('spotify-song').textContent = track.song_name;
|
document.getElementById('spotify-song').textContent = track.song_name;
|
||||||
document.getElementById('spotify-artist').textContent = track.artist;
|
document.getElementById('spotify-artist').textContent = track.artist;
|
||||||
document.getElementById('spotify-album').textContent = track.album_name;
|
document.getElementById('spotify-album').textContent = track.album_name;
|
||||||
|
if (firstLoad) {
|
||||||
|
widget.style.transform = 'translateX(0)'; // slide in on first load
|
||||||
|
}
|
||||||
|
|
||||||
widget.style.opacity = track.is_playing ? 0.9 : 0.5;
|
|
||||||
return true;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to fetch Spotify data', err);
|
console.error('Failed to fetch Spotify data', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for Spotify API to have responded before initial display
|
// Wait for Spotify API to have responded before initial display
|
||||||
updateSpotifyWidget().then(success => {
|
updateSpotifyWidget();
|
||||||
if(success) updateVisibility();
|
|
||||||
});
|
|
||||||
|
|
||||||
window.addEventListener('resize', updateVisibility);
|
window.addEventListener('resize', updateVisibility);
|
||||||
setInterval(updateSpotifyWidget, 15000);
|
setInterval(updateSpotifyWidget, 15000);
|
||||||
|
|||||||
Reference in New Issue
Block a user