From 9c4821b4b4c298eeaec6c108f435de4cb5fefc16 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sun, 4 May 2025 14:19:38 +1000 Subject: feat: cache wallpapers Reduces wallpaper load time massively --- services/Thumbnailer.qml | 45 +++++++++++++++++++++++++++++++++++++++++++++ services/Wallpapers.qml | 4 ++-- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 services/Thumbnailer.qml (limited to 'services') diff --git a/services/Thumbnailer.qml b/services/Thumbnailer.qml new file mode 100644 index 0000000..1e22940 --- /dev/null +++ b/services/Thumbnailer.qml @@ -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 +`] + } +} diff --git a/services/Wallpapers.qml b/services/Wallpapers.qml index 833e808..bd6528d 100644 --- a/services/Wallpapers.qml +++ b/services/Wallpapers.qml @@ -9,7 +9,7 @@ import Qt.labs.platform Singleton { 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 list @@ -28,7 +28,7 @@ Singleton { Process { 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 { splitMarker: "" onRead: data => { -- cgit v1.2.3-freya