From 4f60c07e0540f89654b469d134095c37e238d3e8 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 27 Aug 2025 20:32:51 +1000 Subject: plugin: create caching image manager No need for external proc --- components/images/CachingImage.qml | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) (limited to 'components/images/CachingImage.qml') diff --git a/components/images/CachingImage.qml b/components/images/CachingImage.qml index add459a..07b98b6 100644 --- a/components/images/CachingImage.qml +++ b/components/images/CachingImage.qml @@ -1,44 +1,29 @@ import qs.utils import Caelestia -import Quickshell -import Quickshell.Io import QtQuick Image { id: root - property string path - property string hash - readonly property url cachePath: `${Paths.imagecache}/${hash}@${effectiveWidth}x${effectiveHeight}.png` + property alias path: manager.path - readonly property real effectiveScale: QsWindow.window?.devicePixelRatio ?? 1 - readonly property int effectiveWidth: Math.ceil(width * effectiveScale) - readonly property int effectiveHeight: Math.ceil(height * effectiveScale) + property int sourceWidth + property int sourceHeight asynchronous: true fillMode: Image.PreserveAspectCrop - sourceSize.width: effectiveWidth - sourceSize.height: effectiveHeight - - onPathChanged: shaProc.exec(["sha256sum", Paths.strip(path)]) - - onCachePathChanged: { - if (hash) - source = cachePath; - } + sourceSize.width: sourceWidth + sourceSize.height: sourceHeight onStatusChanged: { - if (source == cachePath && status === Image.Error) - source = path; - else if (source == path && status === Image.Ready) - CUtils.saveItem(this, cachePath); + if (!manager.usingCache && status === Image.Ready) + CUtils.saveItem(this, manager.cachePath); } - Process { - id: shaProc + CachingImageManager { + id: manager - stdout: StdioCollector { - onStreamFinished: root.hash = text.split(" ")[0] - } + item: root + cacheDir: Paths.imagecache } } -- cgit v1.2.3-freya