From ea90fb97e5a3353e45ed44d5f1b4ec0905449aed Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sat, 20 Sep 2025 17:39:27 +1000 Subject: notifs: persist images --- services/Notifs.qml | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'services') diff --git a/services/Notifs.qml b/services/Notifs.qml index 645e1ed..1de3805 100644 --- a/services/Notifs.qml +++ b/services/Notifs.qml @@ -4,6 +4,7 @@ pragma ComponentBehavior: Bound import qs.components.misc import qs.config import qs.utils +import Caelestia import Quickshell import Quickshell.Io import Quickshell.Services.Notifications @@ -169,6 +170,50 @@ Singleton { } } + readonly property LazyLoader dummyImageLoader: LazyLoader { + active: false + + PanelWindow { + implicitWidth: Config.notifs.sizes.image + implicitHeight: Config.notifs.sizes.image + color: "transparent" + mask: Region {} + + Image { + anchors.fill: parent + source: Qt.resolvedUrl(notif.image) + fillMode: Image.PreserveAspectCrop + cache: false + asynchronous: true + opacity: 0 + + onStatusChanged: { + if (status !== Image.Ready) + return; + + const cacheKey = notif.appName + notif.summary + notif.id; + let h1 = 0xdeadbeef, h2 = 0x41c6ce57, ch; + for (let i = 0; i < cacheKey.length; i++) { + ch = cacheKey.charCodeAt(i); + h1 = Math.imul(h1 ^ ch, 2654435761); + h2 = Math.imul(h2 ^ ch, 1597334677); + } + h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507); + h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909); + h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507); + h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909); + const hash = (h2 >>> 0).toString(16).padStart(8, 0) + (h1 >>> 0).toString(16).padStart(8, 0); + + const cache = `${Paths.notifimagecache}/${hash}.png`; + CUtils.saveItem(this, Qt.resolvedUrl(cache), () => { + notif.image = cache; + notif.dummyImageLoader.active = false; + }); + } + } + } + } + readonly property Connections conn: Connections { target: notif.notification @@ -194,6 +239,8 @@ Singleton { function onImageChanged(): void { notif.image = notif.notification.image; + if (notif.notification?.image) + notif.dummyImageLoader.active = true; } function onExpireTimeoutChanged(): void { @@ -254,6 +301,8 @@ Singleton { appIcon = notification.appIcon; appName = notification.appName; image = notification.image; + if (notification?.image) + dummyImageLoader.active = true; expireTimeout = notification.expireTimeout; urgency = notification.urgency; resident = notification.resident; -- cgit v1.2.3-freya