mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
MediaCard: now uses ImageCacheService (orientation fix) + increased thumbnails size to 384x384 + image cache auto cleanup after 30days.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user