Fix BG Cover Art being Stuck on First Render

This commit is contained in:
2025-06-01 00:20:00 +10:00
parent 22f7c4eec7
commit 4bd9cf71b0
2 changed files with 92 additions and 51 deletions
+6
View File
@@ -38,6 +38,12 @@ Allows users to copy song lyrics by selecting them directly in the interface.
### Building All Plugins ### Building All Plugins
```bash ```bash
# Git Clone the Repo
git clone https://github.com/meowarex/neptune-projects-fork
# Change Folder to the Repo
cd neptune-projects-fork
# Install dependencies # Install dependencies
pnpm install pnpm install
+40 -5
View File
@@ -60,6 +60,7 @@ async function HttpGet(url: string): Promise<string | null> {
var isCleanView = false; var isCleanView = false;
var appliedStyle: HTMLStyleElement | null = null; var appliedStyle: HTMLStyleElement | null = null;
var currentTrackSrc: string | null = null; // Track current album art to prevent unnecessary updates
const toggleCleanButton = function(callback: () => void, icon: string, customIndex: number = 2): void { const toggleCleanButton = function(callback: () => void, icon: string, customIndex: number = 2): void {
setTimeout(() => { setTimeout(() => {
@@ -89,21 +90,48 @@ const toggleCleanButton = function(callback: () => void, icon: string, customInd
}; };
function observeTrackTitle(): void { function observeTrackTitle(): void {
// Observe track title changes
const trackTitleElement = document.querySelector('[class^="_trackTitleContainer"]'); const trackTitleElement = document.querySelector('[class^="_trackTitleContainer"]');
if (trackTitleElement) { if (trackTitleElement) {
const observer = new MutationObserver(() => { const titleObserver = new MutationObserver(() => {
setTimeout(() => { setTimeout(() => {
onTrackChanged(); onTrackChanged();
}, 300); }, 300);
}); });
observer.observe(trackTitleElement, { titleObserver.observe(trackTitleElement, {
childList: true, childList: true,
subtree: true subtree: true
}); });
unloads.add(() => observer.disconnect()); unloads.add(() => titleObserver.disconnect());
} }
// Also observe the album image container for changes
const albumImageContainer = document.querySelector('figure[class*="_albumImage"]');
if (albumImageContainer) {
const imageObserver = new MutationObserver(() => {
setTimeout(() => {
onTrackChanged();
}, 100); // Slightly longer delay for image loading
});
imageObserver.observe(albumImageContainer, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['src', 'poster']
});
unloads.add(() => imageObserver.disconnect());
}
// Set up a periodic check as fallback
const periodicCheck = setInterval(() => {
onTrackChanged();
}, 100); // Check every 3 seconds
unloads.add(() => clearInterval(periodicCheck));
} }
const onTrackChanged = function (method: number = 0): void { const onTrackChanged = function (method: number = 0): void {
@@ -132,14 +160,19 @@ const onTrackChanged = function (method: number = 0): void {
} }
} else { } else {
cleanUpDynamicArt(); cleanUpDynamicArt();
console.log("Couldn't get album art"); trace.msg.log("Couldn't get album art");
return; return;
} }
} }
// Only update if the image source has actually changed
if (albumImageSrc && albumImageSrc !== currentTrackSrc) {
currentTrackSrc = albumImageSrc;
trace.msg.log(`Track changed, updating background: ${albumImageSrc}`);
// Setting background to the *="nowPlayingContainer" element // Setting background to the *="nowPlayingContainer" element
const nowPlayingContainerElement = document.querySelector('[class*="_nowPlayingContainer"]') as HTMLElement; const nowPlayingContainerElement = document.querySelector('[class*="_nowPlayingContainer"]') as HTMLElement;
if (nowPlayingContainerElement && albumImageSrc) { if (nowPlayingContainerElement) {
// Remove existing corner images if they exist // Remove existing corner images if they exist
const existingImages = nowPlayingContainerElement.querySelectorAll('.corner-image'); const existingImages = nowPlayingContainerElement.querySelectorAll('.corner-image');
existingImages.forEach(img => img.remove()); existingImages.forEach(img => img.remove());
@@ -189,6 +222,7 @@ const onTrackChanged = function (method: number = 0): void {
document.head.appendChild(styleSheet); document.head.appendChild(styleSheet);
} }
} }
}
}; };
const cleanUpDynamicArt = function (): void { const cleanUpDynamicArt = function (): void {
@@ -196,6 +230,7 @@ const cleanUpDynamicArt = function (): void {
Array.from(cornerImages).forEach((element) => { Array.from(cornerImages).forEach((element) => {
element.remove(); element.remove();
}); });
currentTrackSrc = null; // Reset current track source
}; };
// STYLES FOR THE LYRICS - Added Top-level async since Luna plugins are modules <3 // STYLES FOR THE LYRICS - Added Top-level async since Luna plugins are modules <3