diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-20 17:39:27 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-20 17:39:27 +1000 |
| commit | ea90fb97e5a3353e45ed44d5f1b4ec0905449aed (patch) | |
| tree | b46b04fe0eaf05025ac18ba397f5eee723cdcbae /services/Notifs.qml | |
| parent | sidebar/notifs: fix group sorting (diff) | |
| download | caelestia-shell-ea90fb97e5a3353e45ed44d5f1b4ec0905449aed.tar.gz caelestia-shell-ea90fb97e5a3353e45ed44d5f1b4ec0905449aed.tar.bz2 caelestia-shell-ea90fb97e5a3353e45ed44d5f1b4ec0905449aed.zip | |
notifs: persist images
Diffstat (limited to 'services/Notifs.qml')
| -rw-r--r-- | services/Notifs.qml | 49 |
1 files changed, 49 insertions, 0 deletions
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; |