From 9c4821b4b4c298eeaec6c108f435de4cb5fefc16 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sun, 4 May 2025 14:19:38 +1000 Subject: feat: cache wallpapers Reduces wallpaper load time massively --- widgets/CachingImage.qml | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 widgets/CachingImage.qml (limited to 'widgets/CachingImage.qml') diff --git a/widgets/CachingImage.qml b/widgets/CachingImage.qml new file mode 100644 index 0000000..cff5676 --- /dev/null +++ b/widgets/CachingImage.qml @@ -0,0 +1,45 @@ +import "root:/services" +import Quickshell.Io +import QtQuick + +Image { + id: root + + required property string path + property string thumbnail: path + + source: `file://${thumbnail}` + asynchronous: true + fillMode: Image.PreserveAspectCrop + + onPathChanged: shaProc.running = true + onWidthChanged: shaProc.running = true + onHeightChanged: shaProc.running = true + onStatusChanged: { + if (status === Image.Error) + waitProc.running = true; + } + + Process { + id: shaProc + + command: ["sha1sum", root.path] + stdout: SplitParser { + onRead: data => root.thumbnail = Thumbnailer.go(data.split(" ")[0], root.path, root.width, root.height) + } + } + + Process { + id: waitProc + + command: ["inotifywait", "-q", "-e", "close_write", "--format", "%w%f", "-m", root.thumbnail.slice(0, root.thumbnail.lastIndexOf("/"))] + stdout: SplitParser { + onRead: file => { + if (file === root.thumbnail) { + root.source = file; + waitProc.running = false; + } + } + } + } +} -- cgit v1.2.3-freya