From 51ca9a76860733f473d50f2d67887e15e6423ab3 Mon Sep 17 00:00:00 2001 From: bbedward Date: Thu, 1 Jan 2026 11:47:26 -0500 Subject: [PATCH] cachingimage: dont depend on sha256sum --- quickshell/Modules/DankDash/WallpaperTab.qml | 8 +-- quickshell/Widgets/CachingImage.qml | 57 +++++++++----------- 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/quickshell/Modules/DankDash/WallpaperTab.qml b/quickshell/Modules/DankDash/WallpaperTab.qml index acbd6011..ce54ce51 100644 --- a/quickshell/Modules/DankDash/WallpaperTab.qml +++ b/quickshell/Modules/DankDash/WallpaperTab.qml @@ -401,7 +401,7 @@ Item { currentIndex = clampedIndex; positionViewAtIndex(clampedIndex, GridView.Contain); } - enableAnimation = true; + Qt.callLater(() => { enableAnimation = true; }); } Connections { @@ -465,12 +465,6 @@ Item { } } - BusyIndicator { - anchors.centerIn: parent - running: thumbnailImage.status === Image.Loading - visible: running - } - StateLayer { anchors.fill: parent cornerRadius: parent.radius diff --git a/quickshell/Widgets/CachingImage.qml b/quickshell/Widgets/CachingImage.qml index 3c41fc44..bc73e4e3 100644 --- a/quickshell/Widgets/CachingImage.qml +++ b/quickshell/Widgets/CachingImage.qml @@ -1,13 +1,24 @@ import QtQuick -import Quickshell.Io import qs.Common Image { id: root property string imagePath: "" - property string imageHash: "" property int maxCacheSize: 512 + + function djb2Hash(str) { + if (!str) + return ""; + let hash = 5381; + for (let i = 0; i < str.length; i++) { + hash = ((hash << 5) + hash) + str.charCodeAt(i); + hash = hash & 0x7FFFFFFF; + } + return hash.toString(16).padStart(8, '0'); + } + + readonly property string imageHash: imagePath ? djb2Hash(imagePath) : "" readonly property string cachePath: imageHash ? `${Paths.stringify(Paths.imagecache)}/${imageHash}@${maxCacheSize}x${maxCacheSize}.png` : "" asynchronous: true @@ -15,43 +26,27 @@ Image { sourceSize.width: maxCacheSize sourceSize.height: maxCacheSize smooth: true + onImagePathChanged: { if (!imagePath) { - source = "" - imageHash = "" - return + source = ""; + return; } - hashProcess.command = ["sha256sum", Paths.strip(imagePath)] - hashProcess.running = true + Paths.mkdir(Paths.imagecache); + source = cachePath || imagePath; } - onCachePathChanged: { - if (!imageHash || !cachePath) - return - Paths.mkdir(Paths.imagecache) - source = cachePath - } onStatusChanged: { if (source == cachePath && status === Image.Error) { - source = imagePath - return + source = imagePath; + return; } - if (source != imagePath || status !== Image.Ready || !imageHash || !cachePath) - return - - Paths.mkdir(Paths.imagecache) - const grabPath = cachePath - if (visible && width > 0 && height > 0 && Window.window && Window.window.visible) - grabToImage(res => { - return res.saveToFile(grabPath) - }) - } - - Process { - id: hashProcess - - stdout: StdioCollector { - onStreamFinished: root.imageHash = text.split(" ")[0] + if (source != imagePath || status !== Image.Ready || !cachePath) + return; + Paths.mkdir(Paths.imagecache); + const grabPath = cachePath; + if (visible && width > 0 && height > 0 && Window.window?.visible) { + grabToImage(res => res.saveToFile(grabPath)); } } }