feat: cache wallpapers
Reduces wallpaper load time massively
This commit is contained in:
parent
00d3c1a472
commit
9c4821b4b4
4 changed files with 95 additions and 9 deletions
|
|
@ -25,22 +25,18 @@ StyledRect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Image {
|
CachingImage {
|
||||||
id: image
|
id: image
|
||||||
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
y: Appearance.padding.normal
|
y: Appearance.padding.normal
|
||||||
|
|
||||||
visible: false
|
visible: false
|
||||||
source: `file://${root.modelData.path}`
|
path: root.modelData.path
|
||||||
asynchronous: true
|
|
||||||
fillMode: Image.PreserveAspectCrop
|
|
||||||
smooth: !root.PathView.view.moving
|
smooth: !root.PathView.view.moving
|
||||||
|
|
||||||
width: LauncherConfig.sizes.wallpaperWidth
|
width: LauncherConfig.sizes.wallpaperWidth
|
||||||
height: width / 16 * 9
|
height: width / 16 * 9
|
||||||
sourceSize.width: width
|
|
||||||
sourceSize.height: height
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|
@ -70,7 +66,7 @@ StyledRect {
|
||||||
|
|
||||||
renderType: Text.QtRendering
|
renderType: Text.QtRendering
|
||||||
text: root.modelData.name
|
text: root.modelData.name
|
||||||
font.pointSize: Appearance.font.size.small
|
font.pointSize: Appearance.font.size.normal
|
||||||
}
|
}
|
||||||
|
|
||||||
Behavior on scale {
|
Behavior on scale {
|
||||||
|
|
|
||||||
45
services/Thumbnailer.qml
Normal file
45
services/Thumbnailer.qml
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
pragma Singleton
|
||||||
|
|
||||||
|
import Quickshell
|
||||||
|
import Quickshell.Io
|
||||||
|
import QtQuick
|
||||||
|
import Qt.labs.platform
|
||||||
|
|
||||||
|
Singleton {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
readonly property string thumbDir: `${StandardPaths.standardLocations(StandardPaths.GenericCacheLocation)[0]}/caelestia/thumbnails`.slice(7)
|
||||||
|
|
||||||
|
function go(sha: string, path: string, width: int, height: int): string {
|
||||||
|
if (!sha || !path || !width || !height)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
const thumbPath = `${thumbDir}/${sha}@${width}x${height}-exact.png`;
|
||||||
|
|
||||||
|
thumbProc.path = path;
|
||||||
|
thumbProc.thumbPath = thumbPath;
|
||||||
|
thumbProc.width = width;
|
||||||
|
thumbProc.height = height;
|
||||||
|
thumbProc.startDetached();
|
||||||
|
|
||||||
|
return thumbPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: thumbProc
|
||||||
|
|
||||||
|
property string path
|
||||||
|
property string thumbPath
|
||||||
|
property int width
|
||||||
|
property int height
|
||||||
|
|
||||||
|
command: ["fish", "-c", `
|
||||||
|
if ! test -f ${thumbPath}
|
||||||
|
set -l size (identify -ping -format '%w\n%h' ${path})
|
||||||
|
if test $size[1] -gt ${width} -o $size[2] -gt ${height}
|
||||||
|
magick ${path} -thumbnail ${width}x${height}^ -background none -gravity center -extent ${width}x${height} -unsharp 0x.5 ${thumbPath}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
`]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,7 +9,7 @@ import Qt.labs.platform
|
||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
readonly property string path: `${StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0]}/Wallpapers`
|
readonly property string path: `${StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0]}/Wallpapers`.slice(7)
|
||||||
|
|
||||||
property list<Wallpaper> list
|
property list<Wallpaper> list
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ Singleton {
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
running: true
|
running: true
|
||||||
command: ["fd", ".", root.path.slice(7), "-t", "f", "-e", "jpg", "-e", "jpeg", "-e", "png", "-e", "svg"]
|
command: ["fd", ".", root.path, "-t", "f", "-e", "jpg", "-e", "jpeg", "-e", "png", "-e", "svg"]
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
splitMarker: ""
|
splitMarker: ""
|
||||||
onRead: data => {
|
onRead: data => {
|
||||||
|
|
|
||||||
45
widgets/CachingImage.qml
Normal file
45
widgets/CachingImage.qml
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue