diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-05-05 19:06:32 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-05-05 19:06:32 +1000 |
| commit | 1a650b73bc75a7b617d9e0c24d680eae47218f3d (patch) | |
| tree | 33d7d5d76733bff274eda57fe7b3f93f7534f7c6 /services | |
| parent | wallpaper: limit source size (diff) | |
| download | caelestia-shell-1a650b73bc75a7b617d9e0c24d680eae47218f3d.tar.gz caelestia-shell-1a650b73bc75a7b617d9e0c24d680eae47218f3d.tar.bz2 caelestia-shell-1a650b73bc75a7b617d9e0c24d680eae47218f3d.zip | |
thumbnailer: better caching
Diffstat (limited to 'services')
| -rw-r--r-- | services/Thumbnailer.qml | 80 |
1 files changed, 55 insertions, 25 deletions
diff --git a/services/Thumbnailer.qml b/services/Thumbnailer.qml index 7f7a9a4..3bdcaf0 100644 --- a/services/Thumbnailer.qml +++ b/services/Thumbnailer.qml @@ -1,7 +1,9 @@ pragma Singleton +pragma ComponentBehavior: Bound import Quickshell import Quickshell.Io +import QtQuick import Qt.labs.platform Singleton { @@ -9,36 +11,64 @@ Singleton { readonly property string thumbDir: `${StandardPaths.standardLocations(StandardPaths.GenericCacheLocation)[0]}/caelestia/thumbnails`.slice(7) - function go(sha: string, path: string, width: int, height: int): string { - if (!sha || !path || !width || !height) - return ""; - - const thumbPath = `${thumbDir}/${sha}@${width}x${height}-exact.png`; - - thumbProc.path = path; - thumbProc.thumbPath = thumbPath; - thumbProc.width = width; - thumbProc.height = height; - thumbProc.startDetached(); - - return thumbPath; + function go(path: string, width: int, height: int): var { + return thumbComp.createObject(root, { + originalPath: path, + width: width, + height: height + }); } - Process { - id: thumbProc + component Thumbnail: QtObject { + id: obj + + required property string originalPath + required property int width + required property int height property string path - property string thumbPath - property int width - property int height - command: ["fish", "-c", ` -if ! test -f ${thumbPath} - set -l size (identify -ping -format '%w\n%h' ${path}) - if test $size[1] -gt ${width} -o $size[2] -gt ${height} - magick ${path} -thumbnail ${width}x${height}^ -background none -gravity center -extent ${width}x${height} -unsharp 0x.5 ${thumbPath} + readonly property Process shaProc: Process { + running: true + command: ["sha1sum", obj.originalPath] + stdout: SplitParser { + onRead: data => { + const sha = data.split(" ")[0]; + obj.path = `${root.thumbDir}/${sha}@${obj.width}x${obj.height}-exact.png`; + obj.thumbProc.running = true; + } + } + } + + readonly property Process thumbProc: Process { + command: ["fish", "-c", ` +if test -f ${obj.path} + exit 1 +else + set -l size (identify -ping -format '%w\n%h' ${obj.originalPath}) + if test $size[1] -gt ${obj.width} -o $size[2] -gt ${obj.height} + magick ${obj.originalPath} -${obj.width > 1024 || obj.height > 1024 ? "resize" : "thumbnail"} ${obj.width}x${obj.height}^ -background none -gravity center -extent ${obj.width}x${obj.height} -unsharp 0x.5 ${obj.path} + else + cp ${obj.originalPath} ${obj.path} end -end -`] +end`] + onExited: code => { + if (code === 0) { + const path = obj.path; + obj.path = ""; + obj.path = path; + } + } + } + + function reload(): void { + shaProc.running = true; + } + } + + Component { + id: thumbComp + + Thumbnail {} } } |