summaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2026-03-12 21:49:55 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2026-03-12 21:49:55 +1100
commit30c36e356d4a478cdf4f06fbad48306fa9b99b35 (patch)
treefaa100c857da0b1a0a7c8db1f30de952cdc5e30e /services
parentextras: fix typo (diff)
downloadcaelestia-shell-30c36e356d4a478cdf4f06fbad48306fa9b99b35.tar.gz
caelestia-shell-30c36e356d4a478cdf4f06fbad48306fa9b99b35.tar.bz2
caelestia-shell-30c36e356d4a478cdf4f06fbad48306fa9b99b35.zip
notifs: use adaptive timer for timeStr instead of reactive binding
Replace the per-second reactive binding with an imperative timer that adapts its interval based on notification age: 5s for <1min, 30s for <10min, 60s for <1h, 5min for <1d, 1h for older.
Diffstat (limited to 'services')
-rw-r--r--services/Notifs.qml38
1 files changed, 27 insertions, 11 deletions
diff --git a/services/Notifs.qml b/services/Notifs.qml
index 2ebc32d..aa440fe 100644
--- a/services/Notifs.qml
+++ b/services/Notifs.qml
@@ -146,21 +146,37 @@ Singleton {
property var locks: new Set()
property date time: new Date()
- readonly property string timeStr: {
- const diff = Time.date.getTime() - time.getTime();
+ property string timeStr: qsTr("now")
+
+ function updateTimeStr(): void {
+ const diff = Date.now() - time.getTime();
const m = Math.floor(diff / 60000);
- if (m < 1)
- return qsTr("now");
+ if (m < 1) {
+ timeStr = qsTr("now");
+ timeStrTimer.interval = 5000;
+ } else {
+ const h = Math.floor(m / 60);
+ const d = Math.floor(h / 24);
- const h = Math.floor(m / 60);
- const d = Math.floor(h / 24);
+ if (d > 0) {
+ timeStr = `${d}d`;
+ timeStrTimer.interval = 3600000;
+ } else if (h > 0) {
+ timeStr = `${h}h`;
+ timeStrTimer.interval = 300000;
+ } else {
+ timeStr = `${m}m`;
+ timeStrTimer.interval = m < 10 ? 30000 : 60000;
+ }
+ }
+ }
- if (d > 0)
- return `${d}d`;
- if (h > 0)
- return `${h}h`;
- return `${m}m`;
+ readonly property Timer timeStrTimer: Timer {
+ running: !notif.closed
+ repeat: true
+ interval: 5000
+ onTriggered: notif.updateTimeStr()
}
property Notification notification