diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-18 23:39:23 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-18 23:39:23 +1000 |
| commit | ef5936d0ab58b79d55d79da0c77627f09676691d (patch) | |
| tree | 04a21d49d00d912b23a1665dc5ac1fc4492c6aee /services/Notifs.qml | |
| parent | sidebar: add notifs (diff) | |
| download | caelestia-shell-ef5936d0ab58b79d55d79da0c77627f09676691d.tar.gz caelestia-shell-ef5936d0ab58b79d55d79da0c77627f09676691d.tar.bz2 caelestia-shell-ef5936d0ab58b79d55d79da0c77627f09676691d.zip | |
notifs: persistent notifs + better sidebar notifs
Diffstat (limited to 'services/Notifs.qml')
| -rw-r--r-- | services/Notifs.qml | 86 |
1 files changed, 71 insertions, 15 deletions
diff --git a/services/Notifs.qml b/services/Notifs.qml index 823840c..b651442 100644 --- a/services/Notifs.qml +++ b/services/Notifs.qml @@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound import qs.components.misc import qs.config +import qs.utils import Quickshell import Quickshell.Io import Quickshell.Services.Notifications @@ -15,6 +16,24 @@ Singleton { readonly property list<Notif> popups: list.filter(n => n.popup) property alias dnd: props.dnd + property bool loaded + + onListChanged: { + if (!loaded) + return; + + storage.setText(JSON.stringify(list.filter(n => !n.closed).map(n => ({ + id: n.id, + summary: n.summary, + body: n.body, + appIcon: n.appIcon, + appName: n.appName, + image: n.image, + expireTimeout: n.expireTimeout, + urgency: n.urgency + })))); + } + PersistentProperties { id: props @@ -32,6 +51,7 @@ Singleton { bodyImagesSupported: true bodyMarkupSupported: true imageSupported: true + persistenceSupported: true onNotification: notif => { notif.tracked = true; @@ -43,6 +63,18 @@ Singleton { } } + FileView { + id: storage + + path: `${Paths.state}/notifs.json` + onLoaded: { + const data = JSON.parse(text()); + for (const notif of data) + root.list.push(notifComp.createObject(root, notif)); + root.loaded = true; + } + } + CustomShortcut { name: "clearNotifs" description: "Clear all notifications" @@ -81,7 +113,10 @@ Singleton { id: notif property bool popup - readonly property date time: new Date() + property bool closed + property var locks: new Set() + + property date time: new Date() readonly property string timeStr: { const diff = Time.date.getTime() - time.getTime(); const m = Math.floor(diff / 60000); @@ -94,18 +129,20 @@ Singleton { return `${h}h`; } - required property Notification notification - readonly property string summary: notification.summary - readonly property string body: notification.body - readonly property string appIcon: notification.appIcon - readonly property string appName: notification.appName - readonly property string image: notification.image - readonly property int urgency: notification.urgency - readonly property list<NotificationAction> actions: notification.actions + property Notification notification + property string id: notification?.id ?? "" + property string summary: notification?.summary ?? "" + property string body: notification?.body ?? "" + property string appIcon: notification?.appIcon ?? "" + property string appName: notification?.appName ?? "" + property string image: notification?.image ?? "" + property real expireTimeout: notification?.expireTimeout ?? Config.notifs.defaultExpireTimeout + property int urgency: notification?.urgency ?? NotificationUrgency.Normal + readonly property list<NotificationAction> actions: notification?.actions ?? [] readonly property Timer timer: Timer { running: true - interval: notif.notification.expireTimeout > 0 ? notif.notification.expireTimeout : Config.notifs.defaultExpireTimeout + interval: notif.expireTimeout > 0 ? notif.expireTimeout : Config.notifs.defaultExpireTimeout onTriggered: { if (Config.notifs.expire) notif.popup = false; @@ -113,14 +150,33 @@ Singleton { } readonly property Connections conn: Connections { - target: notif.notification.Retainable + target: notif.notification + + function onClosed(): void { + notif.close(); + } + } - function onDropped(): void { - root.list.splice(root.list.indexOf(notif), 1); + function lock(item: Item): void { + locks.add(item); + } + + function unlock(item: Item): void { + locks.delete(item); + + if (closed && locks.size === 0 && root.list.includes(this)) { + root.list.splice(root.list.indexOf(this), 1); + notification?.dismiss(); + destroy(); } + } - function onAboutToDestroy(): void { - notif.destroy(); + function close(): void { + closed = true; + if (locks.size === 0 && root.list.includes(this)) { + root.list.splice(root.list.indexOf(this), 1); + notification?.dismiss(); + destroy(); } } } |