From d9005d453d8852d7227b51b9e83904fb7963ea5a Mon Sep 17 00:00:00 2001 From: Lemmy Date: Sun, 28 Dec 2025 11:59:42 -0500 Subject: [PATCH] MediaCard: now uses ImageCacheService (orientation fix) + increased thumbnails size to 384x384 + image cache auto cleanup after 30days. --- Modules/Cards/MediaCard.qml | 23 ++++++++++++++++++++++- Services/UI/ImageCacheService.qml | 17 +++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Modules/Cards/MediaCard.qml b/Modules/Cards/MediaCard.qml index ccabd8c55..2b0a481c8 100644 --- a/Modules/Cards/MediaCard.qml +++ b/Modules/Cards/MediaCard.qml @@ -30,6 +30,7 @@ NBox { if (root.needsCava) { CavaService.registerComponent("mediacard"); } + updateCachedWallpaper(); } Component.onDestruction: { @@ -37,6 +38,7 @@ NBox { } property string wallpaper: WallpaperService.getWallpaper(screen.name) + property string cachedWallpaper: "" // External state management Connections { @@ -44,10 +46,29 @@ NBox { function onWallpaperChanged(screenName, path) { if (screenName === screen.name) { wallpaper = path; + updateCachedWallpaper(); } } } + function updateCachedWallpaper() { + if (!wallpaper) { + cachedWallpaper = ""; + return; + } + + if (!ImageCacheService.initialized) { + cachedWallpaper = wallpaper; + return; + } + + ImageCacheService.getThumbnail(wallpaper, function (cachedPath, success) { + if (!root) + return; + cachedWallpaper = success ? cachedPath : wallpaper; + }); + } + // Wrapper - rounded rect clipper Item { anchors.fill: parent @@ -72,7 +93,7 @@ NBox { id: bgImage readonly property int dim: Math.round(256 * Style.uiScaleRatio) anchors.fill: parent - source: MediaService.trackArtUrl || wallpaper + source: MediaService.trackArtUrl || root.cachedWallpaper sourceSize: Qt.size(dim, dim) fillMode: Image.PreserveAspectCrop layer.enabled: true diff --git a/Services/UI/ImageCacheService.qml b/Services/UI/ImageCacheService.qml index 9da04cdad..6e1355118 100644 --- a/Services/UI/ImageCacheService.qml +++ b/Services/UI/ImageCacheService.qml @@ -55,6 +55,7 @@ Singleton { function init() { Logger.i("ImageCache", "Service started"); createDirectories(); + cleanupOldCache(); checkMagickProcess.running = true; } @@ -65,8 +66,16 @@ Singleton { Quickshell.execDetached(["mkdir", "-p", contributorsDir]); } + function cleanupOldCache() { + const dirs = [wpThumbDir, wpLargeDir, notificationsDir, contributorsDir]; + dirs.forEach(function (dir) { + Quickshell.execDetached(["find", dir, "-type", "f", "-mtime", "+30", "-delete"]); + }); + Logger.d("ImageCache", "Cleanup triggered for files older than 30 days"); + } + // ------------------------------------------------- - // Public API: Get Thumbnail (256x256) + // Public API: Get Thumbnail (384x384) // ------------------------------------------------- function getThumbnail(sourcePath, callback) { if (!sourcePath || sourcePath === "") { @@ -82,7 +91,7 @@ Singleton { if (imageMagickAvailable) { startThumbnailProcessing(sourcePath, cachedPath, cacheKey); } else { - queueFallbackProcessing(sourcePath, cachedPath, cacheKey, 256); + queueFallbackProcessing(sourcePath, cachedPath, cacheKey, 384); } }); }); @@ -183,7 +192,7 @@ Singleton { // Cache Key Generation // ------------------------------------------------- function generateThumbnailKey(sourcePath, mtime) { - const keyString = sourcePath + "@256x256@" + (mtime || "unknown"); + const keyString = sourcePath + "@384x384@" + (mtime || "unknown"); return Checksum.sha256(keyString); } @@ -260,7 +269,7 @@ Singleton { const srcEsc = sourcePath.replace(/'/g, "'\\''"); const dstEsc = outputPath.replace(/'/g, "'\\''"); - const command = `magick -define jpeg:size=512x512 '${srcEsc}' -auto-orient -thumbnail '256x256^' -gravity center -extent 256x256 -quality 85 '${dstEsc}'`; + const command = `magick -define jpeg:size=768x768 '${srcEsc}' -auto-orient -thumbnail '384x384^' -gravity center -extent 384x384 -quality 85 '${dstEsc}'`; runProcess(command, cacheKey, outputPath, sourcePath); }