MediaCard: now uses ImageCacheService (orientation fix) + increased thumbnails size to 384x384 + image cache auto cleanup after 30days.

This commit is contained in:
Lemmy
2025-12-28 11:59:42 -05:00
parent 29fc260c2d
commit d9005d453d
2 changed files with 35 additions and 5 deletions
+22 -1
View File
@@ -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
+13 -4
View File
@@ -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);
}