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
```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
pnpm install
+40 -5
View File
@@ -60,6 +60,7 @@ async function HttpGet(url: string): Promise<string | null> {
var isCleanView = false;
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 {
setTimeout(() => {
@@ -89,21 +90,48 @@ const toggleCleanButton = function(callback: () => void, icon: string, customInd
};
function observeTrackTitle(): void {
// Observe track title changes
const trackTitleElement = document.querySelector('[class^="_trackTitleContainer"]');
if (trackTitleElement) {
const observer = new MutationObserver(() => {
const titleObserver = new MutationObserver(() => {
setTimeout(() => {
onTrackChanged();
}, 300);
});
observer.observe(trackTitleElement, {
titleObserver.observe(trackTitleElement, {
childList: 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 {
@@ -132,14 +160,19 @@ const onTrackChanged = function (method: number = 0): void {
}
} else {
cleanUpDynamicArt();
console.log("Couldn't get album art");
trace.msg.log("Couldn't get album art");
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
const nowPlayingContainerElement = document.querySelector('[class*="_nowPlayingContainer"]') as HTMLElement;
if (nowPlayingContainerElement && albumImageSrc) {
if (nowPlayingContainerElement) {
// Remove existing corner images if they exist
const existingImages = nowPlayingContainerElement.querySelectorAll('.corner-image');
existingImages.forEach(img => img.remove());
@@ -189,6 +222,7 @@ const onTrackChanged = function (method: number = 0): void {
document.head.appendChild(styleSheet);
}
}
}
};
const cleanUpDynamicArt = function (): void {
@@ -196,6 +230,7 @@ const cleanUpDynamicArt = function (): void {
Array.from(cornerImages).forEach((element) => {
element.remove();
});
currentTrackSrc = null; // Reset current track source
};
// STYLES FOR THE LYRICS - Added Top-level async since Luna plugins are modules <3