nosignal-shell/components/images/CachingImage.qml
2 * r + 2 * t c5381c5194 internal: refactor widgets folder
Split into subdirs and rename to components
2025-08-04 22:45:15 +10:00

41 lines
982 B
QML

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]
}
}
}