mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-26 22:42:50 -05:00
cachingimage: dont depend on sha256sum
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user