diff --git a/components/system/Desktop/Wallpapers/useWallpaper.ts b/components/system/Desktop/Wallpapers/useWallpaper.ts index f29635ad..db45819a 100644 --- a/components/system/Desktop/Wallpapers/useWallpaper.ts +++ b/components/system/Desktop/Wallpapers/useWallpaper.ts @@ -42,7 +42,7 @@ import { preloadImage, } from "utils/functions"; -const slideshowFiles: string[] = []; +let slideshowFiles: Record = {}; const useWallpaper = ( desktopRef: React.RefObject @@ -288,22 +288,26 @@ const useWallpaper = ( updateFolder(PICTURES_FOLDER, SLIDESHOW_FILE); } - if (slideshowFiles.length === 0) { - slideshowFiles.push( + slideshowFiles = { + [wallpaperImage]: slideshowFiles[wallpaperImage] || [], + }; + + if (slideshowFiles[wallpaperImage].length === 0) { + slideshowFiles[wallpaperImage].push( ...[ ...new Set( JSON.parse( (await readFile(slideshowFilePath))?.toString() || "[]" ) as string[] ), - ].sort(() => Math.random() - (isAlt ? 0.5 : -0.5)) + ].sort(() => Math.random() - 0.5) ); } do { - wallpaperUrl = slideshowFiles.shift() || ""; + wallpaperUrl = slideshowFiles[wallpaperImage].shift() || ""; - const [nextWallpaper] = slideshowFiles; + const [nextWallpaper] = slideshowFiles[wallpaperImage]; if (nextWallpaper) { document.querySelector(`#${PRELOAD_ID}`)?.remove(); @@ -322,7 +326,7 @@ const useWallpaper = ( } } while ( currentWallpaperUrl === wallpaperUrl && - slideshowFiles.length > 1 + slideshowFiles[wallpaperImage].length > 1 ); newWallpaperFit = "fill";