Files
nixos-dots/dots/quickshell/widgets/CachingImage.qml
zastian@mrthoddata.com 040bc459a4 quickshell lets gooo
2025-06-17 18:54:28 +01:00

51 lines
1.1 KiB
QML

import "root:/services"
import "root:/utils"
import Quickshell.Io
import QtQuick
Image {
id: root
property string path
property string hash
readonly property string cachePath: `${Paths.imagecache}/${hash}@${width}x${height}.png`.slice(7)
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: StdioCollector {
onStreamFinished: root.hash = text.split(" ")[0]
}
}
}