diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2025-09-13 14:56:55 +0200 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2025-09-13 14:56:55 +0200 |
| commit | 3ce3fe19b11e30fd98d7eee06d56b90ae33b228d (patch) | |
| tree | 572e904f871cd05410c21b33ddf9e0ae7e1c5c90 /accounts/gkleen@sif/shell/quickshell/Services | |
| parent | 666464567055a2e4ba9f6bb310e901cdc27977f7 (diff) | |
| download | nixos-3ce3fe19b11e30fd98d7eee06d56b90ae33b228d.tar nixos-3ce3fe19b11e30fd98d7eee06d56b90ae33b228d.tar.gz nixos-3ce3fe19b11e30fd98d7eee06d56b90ae33b228d.tar.bz2 nixos-3ce3fe19b11e30fd98d7eee06d56b90ae33b228d.tar.xz nixos-3ce3fe19b11e30fd98d7eee06d56b90ae33b228d.zip | |
...
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/Services')
| -rw-r--r-- | accounts/gkleen@sif/shell/quickshell/Services/NotificationManager.qml | 51 |
1 files changed, 51 insertions, 0 deletions
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 { | |||
| 56 | { "test": { "appName": "Element" }, "group-by": [ "summary" ] } | 56 | { "test": { "appName": "Element" }, "group-by": [ "summary" ] } |
| 57 | ]; | 57 | ]; |
| 58 | 58 | ||
| 59 | property var history: [] | ||
| 60 | |||
| 59 | Component { | 61 | Component { |
| 60 | id: expirationTimer | 62 | id: expirationTimer |
| 61 | 63 | ||
| @@ -74,6 +76,45 @@ Singleton { | |||
| 74 | } | 76 | } |
| 75 | } | 77 | } |
| 76 | 78 | ||
| 79 | Component { | ||
| 80 | id: notificationLock | ||
| 81 | |||
| 82 | RetainableLock {} | ||
| 83 | } | ||
| 84 | |||
| 85 | readonly property SystemClock clock: SystemClock { | ||
| 86 | precision: SystemClock.Minutes | ||
| 87 | } | ||
| 88 | |||
| 89 | function formatTime(time) { | ||
| 90 | const now = root.clock.date; | ||
| 91 | const diff = now - time; | ||
| 92 | const minutes = Math.ceil(diff / 60000); | ||
| 93 | const hours = Math.floor(minutes / 60); | ||
| 94 | |||
| 95 | if (hours < 1) { | ||
| 96 | if (minutes < 1) | ||
| 97 | return "now"; | ||
| 98 | if (minutes == 1) | ||
| 99 | return "1 minute"; | ||
| 100 | return `${minutes} minutes`; | ||
| 101 | } | ||
| 102 | |||
| 103 | const nowDate = new Date(now.getFullYear(), now.getMonth(), now.getDate()) | ||
| 104 | const timeDate = new Date(time.getFullYear(), time.getMonth(), time.getDate()) | ||
| 105 | const days = Math.floor((nowDate - timeDate) / (1000 * 86400)) | ||
| 106 | |||
| 107 | const timeStr = time.toLocaleTimeString(Qt.locale(), "HH:mm"); | ||
| 108 | |||
| 109 | if (days === 0) | ||
| 110 | return timeStr; | ||
| 111 | if (days === 1) | ||
| 112 | return `yesterday ${timeStr}`; | ||
| 113 | |||
| 114 | const dateStr = time.toLocaleTimeString(Qt.locale(), "YYYY-MM-DD"); | ||
| 115 | return `${dateStr} ${timeStr}`; | ||
| 116 | } | ||
| 117 | |||
| 77 | NotificationServer { | 118 | NotificationServer { |
| 78 | id: server | 119 | id: server |
| 79 | 120 | ||
| @@ -92,7 +133,17 @@ Singleton { | |||
| 92 | Object.defineProperty(notification, "expirationTimer", { configurable: true, enumerable: true, writable: true }); | 133 | Object.defineProperty(notification, "expirationTimer", { configurable: true, enumerable: true, writable: true }); |
| 93 | notification.expirationTimer = expirationTimer.createObject(notification, { parent: notification, expirationTime: timeout }); | 134 | notification.expirationTimer = expirationTimer.createObject(notification, { parent: notification, expirationTime: timeout }); |
| 94 | } | 135 | } |
| 136 | Object.defineProperty(notification, "receivedTime", { configurable: true, enumerable: true, writable: true }); | ||
| 137 | notification.receivedTime = root.clock.date; | ||
| 138 | notification.closed.connect((reason) => server.onNotificationClosed(notification, reason)); | ||
| 95 | notification.tracked = true; | 139 | notification.tracked = true; |
| 96 | } | 140 | } |
| 141 | |||
| 142 | function onNotificationClosed(notification, reason) { | ||
| 143 | root.history.push({ | ||
| 144 | lock: notificationLock.createObject(root, { locked: true, object: notification }), | ||
| 145 | notification: notification | ||
| 146 | }); | ||
| 147 | } | ||
| 97 | } | 148 | } |
| 98 | } | 149 | } |
