From 3ce3fe19b11e30fd98d7eee06d56b90ae33b228d Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 13 Sep 2025 14:56:55 +0200 Subject: ... --- .../quickshell/Services/NotificationManager.qml | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'accounts/gkleen@sif/shell/quickshell/Services') diff --git a/accounts/gkleen@sif/shell/quickshell/Services/NotificationManager.qml b/accounts/gkleen@sif/shell/quickshell/Services/NotificationManager.qml index 778cdc2a..2199ccdf 100644 --- a/accounts/gkleen@sif/shell/quickshell/Services/NotificationManager.qml +++ b/accounts/gkleen@sif/shell/quickshell/Services/NotificationManager.qml @@ -56,6 +56,8 @@ Singleton { { "test": { "appName": "Element" }, "group-by": [ "summary" ] } ]; + property var history: [] + Component { id: expirationTimer @@ -74,6 +76,45 @@ Singleton { } } + Component { + id: notificationLock + + RetainableLock {} + } + + readonly property SystemClock clock: SystemClock { + precision: SystemClock.Minutes + } + + function formatTime(time) { + const now = root.clock.date; + const diff = now - time; + const minutes = Math.ceil(diff / 60000); + const hours = Math.floor(minutes / 60); + + if (hours < 1) { + if (minutes < 1) + return "now"; + if (minutes == 1) + return "1 minute"; + return `${minutes} minutes`; + } + + const nowDate = new Date(now.getFullYear(), now.getMonth(), now.getDate()) + const timeDate = new Date(time.getFullYear(), time.getMonth(), time.getDate()) + const days = Math.floor((nowDate - timeDate) / (1000 * 86400)) + + const timeStr = time.toLocaleTimeString(Qt.locale(), "HH:mm"); + + if (days === 0) + return timeStr; + if (days === 1) + return `yesterday ${timeStr}`; + + const dateStr = time.toLocaleTimeString(Qt.locale(), "YYYY-MM-DD"); + return `${dateStr} ${timeStr}`; + } + NotificationServer { id: server @@ -92,7 +133,17 @@ Singleton { Object.defineProperty(notification, "expirationTimer", { configurable: true, enumerable: true, writable: true }); notification.expirationTimer = expirationTimer.createObject(notification, { parent: notification, expirationTime: timeout }); } + Object.defineProperty(notification, "receivedTime", { configurable: true, enumerable: true, writable: true }); + notification.receivedTime = root.clock.date; + notification.closed.connect((reason) => server.onNotificationClosed(notification, reason)); notification.tracked = true; } + + function onNotificationClosed(notification, reason) { + root.history.push({ + lock: notificationLock.createObject(root, { locked: true, object: notification }), + notification: notification + }); + } } } -- cgit v1.2.3