diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-08-04 22:45:15 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-08-04 22:45:15 +1000 |
| commit | c5381c5194adf97c240acb98eb4c4c950633b325 (patch) | |
| tree | 52b18eb1771ec6708c86f11d786684f03b8a7c48 /components/images/CachingImage.qml | |
| parent | dashboard: display correct temp units (diff) | |
| download | caelestia-shell-c5381c5194adf97c240acb98eb4c4c950633b325.tar.gz caelestia-shell-c5381c5194adf97c240acb98eb4c4c950633b325.tar.bz2 caelestia-shell-c5381c5194adf97c240acb98eb4c4c950633b325.zip | |
internal: refactor widgets folder
Split into subdirs and rename to components
Diffstat (limited to 'components/images/CachingImage.qml')
| -rw-r--r-- | components/images/CachingImage.qml | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/components/images/CachingImage.qml b/components/images/CachingImage.qml new file mode 100644 index 0000000..1d42238 --- /dev/null +++ b/components/images/CachingImage.qml @@ -0,0 +1,41 @@ +import qs.utils +import Quickshell.Io +import QtQuick + +Image { + id: root + + property string path + property string hash + readonly property string cachePath: `${Paths.stringify(Paths.imagecache)}/${hash}@${width}x${height}.png` + + asynchronous: true + fillMode: Image.PreserveAspectCrop + sourceSize.width: width + sourceSize.height: height + + onPathChanged: shaProc.exec(["sha256sum", Paths.strip(path)]) + + 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 + + stdout: StdioCollector { + onStreamFinished: root.hash = text.split(" ")[0] + } + } +} |