mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-29 16:02:51 -05:00
cachingimage: dont depend on sha256sum
This commit is contained in:
@@ -401,7 +401,7 @@ Item {
|
|||||||
currentIndex = clampedIndex;
|
currentIndex = clampedIndex;
|
||||||
positionViewAtIndex(clampedIndex, GridView.Contain);
|
positionViewAtIndex(clampedIndex, GridView.Contain);
|
||||||
}
|
}
|
||||||
enableAnimation = true;
|
Qt.callLater(() => { enableAnimation = true; });
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
@@ -465,12 +465,6 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BusyIndicator {
|
|
||||||
anchors.centerIn: parent
|
|
||||||
running: thumbnailImage.status === Image.Loading
|
|
||||||
visible: running
|
|
||||||
}
|
|
||||||
|
|
||||||
StateLayer {
|
StateLayer {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
cornerRadius: parent.radius
|
cornerRadius: parent.radius
|
||||||
|
|||||||
@@ -1,13 +1,24 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell.Io
|
|
||||||
import qs.Common
|
import qs.Common
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property string imagePath: ""
|
property string imagePath: ""
|
||||||
property string imageHash: ""
|
|
||||||
property int maxCacheSize: 512
|
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` : ""
|
readonly property string cachePath: imageHash ? `${Paths.stringify(Paths.imagecache)}/${imageHash}@${maxCacheSize}x${maxCacheSize}.png` : ""
|
||||||
|
|
||||||
asynchronous: true
|
asynchronous: true
|
||||||
@@ -15,43 +26,27 @@ Image {
|
|||||||
sourceSize.width: maxCacheSize
|
sourceSize.width: maxCacheSize
|
||||||
sourceSize.height: maxCacheSize
|
sourceSize.height: maxCacheSize
|
||||||
smooth: true
|
smooth: true
|
||||||
|
|
||||||
onImagePathChanged: {
|
onImagePathChanged: {
|
||||||
if (!imagePath) {
|
if (!imagePath) {
|
||||||
source = ""
|
source = "";
|
||||||
imageHash = ""
|
return;
|
||||||
return
|
|
||||||
}
|
}
|
||||||
hashProcess.command = ["sha256sum", Paths.strip(imagePath)]
|
Paths.mkdir(Paths.imagecache);
|
||||||
hashProcess.running = true
|
source = cachePath || imagePath;
|
||||||
}
|
}
|
||||||
onCachePathChanged: {
|
|
||||||
if (!imageHash || !cachePath)
|
|
||||||
return
|
|
||||||
|
|
||||||
Paths.mkdir(Paths.imagecache)
|
|
||||||
source = cachePath
|
|
||||||
}
|
|
||||||
onStatusChanged: {
|
onStatusChanged: {
|
||||||
if (source == cachePath && status === Image.Error) {
|
if (source == cachePath && status === Image.Error) {
|
||||||
source = imagePath
|
source = imagePath;
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
if (source != imagePath || status !== Image.Ready || !imageHash || !cachePath)
|
if (source != imagePath || status !== Image.Ready || !cachePath)
|
||||||
return
|
return;
|
||||||
|
Paths.mkdir(Paths.imagecache);
|
||||||
Paths.mkdir(Paths.imagecache)
|
const grabPath = cachePath;
|
||||||
const grabPath = cachePath
|
if (visible && width > 0 && height > 0 && Window.window?.visible) {
|
||||||
if (visible && width > 0 && height > 0 && Window.window && Window.window.visible)
|
grabToImage(res => res.saveToFile(grabPath));
|
||||||
grabToImage(res => {
|
|
||||||
return res.saveToFile(grabPath)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
Process {
|
|
||||||
id: hashProcess
|
|
||||||
|
|
||||||
stdout: StdioCollector {
|
|
||||||
onStreamFinished: root.imageHash = text.split(" ")[0]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user