notifs: persist images
This commit is contained in:
parent
e2ca5a4e8f
commit
ea90fb97e5
2 changed files with 50 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ pragma ComponentBehavior: Bound
|
||||||
import qs.components.misc
|
import qs.components.misc
|
||||||
import qs.config
|
import qs.config
|
||||||
import qs.utils
|
import qs.utils
|
||||||
|
import Caelestia
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
import Quickshell.Services.Notifications
|
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 {
|
readonly property Connections conn: Connections {
|
||||||
target: notif.notification
|
target: notif.notification
|
||||||
|
|
||||||
|
|
@ -194,6 +239,8 @@ Singleton {
|
||||||
|
|
||||||
function onImageChanged(): void {
|
function onImageChanged(): void {
|
||||||
notif.image = notif.notification.image;
|
notif.image = notif.notification.image;
|
||||||
|
if (notif.notification?.image)
|
||||||
|
notif.dummyImageLoader.active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onExpireTimeoutChanged(): void {
|
function onExpireTimeoutChanged(): void {
|
||||||
|
|
@ -254,6 +301,8 @@ Singleton {
|
||||||
appIcon = notification.appIcon;
|
appIcon = notification.appIcon;
|
||||||
appName = notification.appName;
|
appName = notification.appName;
|
||||||
image = notification.image;
|
image = notification.image;
|
||||||
|
if (notification?.image)
|
||||||
|
dummyImageLoader.active = true;
|
||||||
expireTimeout = notification.expireTimeout;
|
expireTimeout = notification.expireTimeout;
|
||||||
urgency = notification.urgency;
|
urgency = notification.urgency;
|
||||||
resident = notification.resident;
|
resident = notification.resident;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ Singleton {
|
||||||
readonly property string config: `${Quickshell.env("XDG_CONFIG_HOME") || `${home}/.config`}/caelestia`
|
readonly property string config: `${Quickshell.env("XDG_CONFIG_HOME") || `${home}/.config`}/caelestia`
|
||||||
|
|
||||||
readonly property string imagecache: `${cache}/imagecache`
|
readonly property string imagecache: `${cache}/imagecache`
|
||||||
|
readonly property string notifimagecache: `${imagecache}/notifs`
|
||||||
readonly property string wallsdir: Quickshell.env("CAELESTIA_WALLPAPERS_DIR") || absolutePath(Config.paths.wallpaperDir)
|
readonly property string wallsdir: Quickshell.env("CAELESTIA_WALLPAPERS_DIR") || absolutePath(Config.paths.wallpaperDir)
|
||||||
readonly property string recsdir: Quickshell.env("CAELESTIA_RECORDINGS_DIR") || `${videos}/Recordings`
|
readonly property string recsdir: Quickshell.env("CAELESTIA_RECORDINGS_DIR") || `${videos}/Recordings`
|
||||||
readonly property string libdir: Quickshell.env("CAELESTIA_LIB_DIR") || "/usr/lib/caelestia"
|
readonly property string libdir: Quickshell.env("CAELESTIA_LIB_DIR") || "/usr/lib/caelestia"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue