diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-06-13 23:31:47 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-06-13 23:31:47 +1000 |
| commit | 5da1b64da09e4c12bf850750cd1cf18b5bab3210 (patch) | |
| tree | 4e79285022869d5e30b37e616e10919a187a6c29 /widgets/CachingImage.qml | |
| parent | dashboard: not full rounding for face (diff) | |
| download | caelestia-shell-5da1b64da09e4c12bf850750cd1cf18b5bab3210.tar.gz caelestia-shell-5da1b64da09e4c12bf850750cd1cf18b5bab3210.tar.bz2 caelestia-shell-5da1b64da09e4c12bf850750cd1cf18b5bab3210.zip | |
internal: better caching impl
WARNING: causes blocking when caching image on first load
Diffstat (limited to 'widgets/CachingImage.qml')
| -rw-r--r-- | widgets/CachingImage.qml | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/widgets/CachingImage.qml b/widgets/CachingImage.qml index cd164b4..3382615 100644 --- a/widgets/CachingImage.qml +++ b/widgets/CachingImage.qml @@ -1,14 +1,50 @@ import "root:/services" +import "root:/utils" +import Quickshell.Io import QtQuick Image { id: root property string path - property bool loadOriginal - readonly property Thumbnailer.Thumbnail thumbnail: Thumbnailer.go(this) + property string hash + readonly property string cachePath: `${Paths.imagecache}/${hash}@${width}x${height}.png`.slice(7) - source: thumbnail.path ? `file://${thumbnail.path}` : "" asynchronous: true + cache: false fillMode: Image.PreserveAspectCrop + sourceSize.width: width + sourceSize.height: height + + onPathChanged: { + shaProc.signal(9); + shaProc.path = path.replace("file://", ""); + shaProc.running = true; + } + + onCachePathChanged: { + if (hash) + source = cachePath; + } + + onStatusChanged: { + if (source == cachePath && status === Image.Error) + source = path; + else if (source == path && status === Image.Ready) { + Paths.mkdir(Paths.imagecache); + const grabPath = cachePath; + grabToImage(res => res.saveToFile(grabPath)); + } + } + + Process { + id: shaProc + + property string path + + command: ["sha256sum", path] + stdout: SplitParser { + onRead: data => root.hash = data.split(" ")[0] + } + } } |