1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-01 19:18:28 -04:00

wallpaper: optimize caching and performance of wallpaper tab

This commit is contained in:
bbedward
2026-07-06 13:52:31 -04:00
parent cc0bec2682
commit 405ea708b3
6 changed files with 62 additions and 212 deletions
+1 -46
View File
@@ -7,62 +7,17 @@ import qs.Common
Singleton {
id: root
// Filenames present on disk, so CachingImage never points an Image at a
// missing cache file (Qt logs that as a "Cannot open" warning).
property var cachedFiles: ({})
Component.onCompleted: scan()
function scan() {
Proc.runCommand("imagecache_scan", ["ls", "-1", Paths.stringify(Paths.imagecache)], function (output, exitCode) {
const map = {};
if (exitCode === 0 && output) {
const lines = output.split("\n");
for (var i = 0; i < lines.length; i++) {
const name = lines[i].trim();
if (name)
map[name] = true;
}
}
root.cachedFiles = map;
});
}
function hasCachedFile(name) {
return name ? root.cachedFiles[name] === true : false;
}
function recordCachedFile(name) {
if (name)
root.cachedFiles[name] = true;
}
function forgetCachedFile(name) {
if (name && root.cachedFiles[name] !== undefined)
delete root.cachedFiles[name];
}
function clearImageCache() {
Quickshell.execDetached(["rm", "-rf", Paths.stringify(Paths.imagecache)]);
Paths.mkdir(Paths.imagecache);
root.cachedFiles = ({});
}
function clearOldCache(ageInMinutes) {
// Rescan on delete completion since we can't know which files matched.
Proc.runCommand("imagecache_prune", ["find", Paths.stringify(Paths.imagecache), "-name", "*.png", "-mmin", `+${ageInMinutes}`, "-delete"], function (output, exitCode) {
root.scan();
});
Quickshell.execDetached(["find", Paths.stringify(Paths.imagecache), "-name", "*.png", "-mmin", `+${ageInMinutes}`, "-delete"]);
}
function clearCacheForSize(size) {
Quickshell.execDetached(["find", Paths.stringify(Paths.imagecache), "-name", `*@${size}x${size}.png`, "-delete"]);
const suffix = `@${size}x${size}.png`;
const map = {};
for (const key in root.cachedFiles)
if (!key.endsWith(suffix))
map[key] = true;
root.cachedFiles = map;
}
function getCacheSize(callback) {
+3
View File
@@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound
import Quickshell
import QtCore
import QtQuick
import qs.Services
Singleton {
@@ -19,6 +20,8 @@ Singleton {
readonly property url imagecache: `${cache}/imagecache`
Component.onCompleted: mkdir(imagecache)
function stringify(path: url): string {
return path.toString().replace(/%20/g, " ");
}