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.
This commit is contained in:
parent
b4514a7820
commit
30c36e356d
1 changed files with 27 additions and 11 deletions
|
|
@ -146,21 +146,37 @@ Singleton {
|
||||||
property var locks: new Set()
|
property var locks: new Set()
|
||||||
|
|
||||||
property date time: new Date()
|
property date time: new Date()
|
||||||
readonly property string timeStr: {
|
property string timeStr: qsTr("now")
|
||||||
const diff = Time.date.getTime() - time.getTime();
|
|
||||||
|
function updateTimeStr(): void {
|
||||||
|
const diff = Date.now() - time.getTime();
|
||||||
const m = Math.floor(diff / 60000);
|
const m = Math.floor(diff / 60000);
|
||||||
|
|
||||||
if (m < 1)
|
if (m < 1) {
|
||||||
return qsTr("now");
|
timeStr = qsTr("now");
|
||||||
|
timeStrTimer.interval = 5000;
|
||||||
|
} else {
|
||||||
const h = Math.floor(m / 60);
|
const h = Math.floor(m / 60);
|
||||||
const d = Math.floor(h / 24);
|
const d = Math.floor(h / 24);
|
||||||
|
|
||||||
if (d > 0)
|
if (d > 0) {
|
||||||
return `${d}d`;
|
timeStr = `${d}d`;
|
||||||
if (h > 0)
|
timeStrTimer.interval = 3600000;
|
||||||
return `${h}h`;
|
} else if (h > 0) {
|
||||||
return `${m}m`;
|
timeStr = `${h}h`;
|
||||||
|
timeStrTimer.interval = 300000;
|
||||||
|
} else {
|
||||||
|
timeStr = `${m}m`;
|
||||||
|
timeStrTimer.interval = m < 10 ? 30000 : 60000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly property Timer timeStrTimer: Timer {
|
||||||
|
running: !notif.closed
|
||||||
|
repeat: true
|
||||||
|
interval: 5000
|
||||||
|
onTriggered: notif.updateTimeStr()
|
||||||
}
|
}
|
||||||
|
|
||||||
property Notification notification
|
property Notification notification
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue