From 3d4ea22e730073ff6d344b2335cdfcf84f630b4c Mon Sep 17 00:00:00 2001 From: Vladimir Date: Tue, 27 Oct 2026 19:07:14 +0100 Subject: [PATCH] notifications: refresh relative times on the lock screen, in NotificationsTab and in history (#3965) port 2.0 --- quickshell/Modules/DDash/NotificationsTab.qml | 5 +++++ .../Center/HistoryNotificationCard.qml | 2 +- quickshell/Services/NotificationService.qml | 21 +++++++++++++------ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/quickshell/Modules/DDash/NotificationsTab.qml b/quickshell/Modules/DDash/NotificationsTab.qml index 7d67f79e1..940d2abff 100644 --- a/quickshell/Modules/DDash/NotificationsTab.qml +++ b/quickshell/Modules/DDash/NotificationsTab.qml @@ -94,6 +94,11 @@ FocusScope { LayoutMirroring.enabled: I18n.isRtl LayoutMirroring.childrenInherit: true + Ref { + service: NotificationService + active: root.live + } + onLiveChanged: { if (!live) { keyboard.reset(); diff --git a/quickshell/Modules/Notifications/Center/HistoryNotificationCard.qml b/quickshell/Modules/Notifications/Center/HistoryNotificationCard.qml index acd0fe8f6..2b0297daf 100644 --- a/quickshell/Modules/Notifications/Center/HistoryNotificationCard.qml +++ b/quickshell/Modules/Notifications/Center/HistoryNotificationCard.qml @@ -38,7 +38,7 @@ Notifications.NotificationCard { onDismissRequested: NotificationService.removeFromHistory(historyItem.id) function formatHistoryTime(timestamp) { - NotificationService.timeUpdateTick; + NotificationService.relativeTimeNow; NotificationService.clockFormatChanged; const now = new Date(); const date = new Date(timestamp); diff --git a/quickshell/Services/NotificationService.qml b/quickshell/Services/NotificationService.qml index 6c11a1226..a25c70126 100644 --- a/quickshell/Services/NotificationService.qml +++ b/quickshell/Services/NotificationService.qml @@ -610,12 +610,22 @@ Singleton { SystemClock { id: minuteClock precision: SystemClock.Minutes - enabled: root.overlayOpen || SettingsData.hasTimedNotificationRules + enabled: root.relativeTimesShown || SettingsData.hasTimedNotificationRules } - // Current time in ms for rule-expiry bindings. Reads 0 while the clock is - // off, which is safe: the clock is off exactly when no rule carries an - // expiry, so no binding can depend on the value moving. + // Views that show relative times without calling onOverlayOpen(), such + // as NotificationsTab, hold a Ref while visible. + property int refCount: 0 + + readonly property bool relativeTimesShown: overlayOpen || IdleService.isShellLocked || refCount > 0 + + // Relative-time bindings read this to refresh every minute while + // relativeTimesShown. It stays null otherwise, so clock ticks for timed + // rules do not re-evaluate them. + readonly property var relativeTimeNow: relativeTimesShown ? minuteClock.date : null + + // Current time in ms for rule-expiry bindings. Reads 0 while no rule + // carries an expiry, so no binding can depend on the value moving. readonly property double notificationRuleNowMs: SettingsData.hasTimedNotificationRules ? minuteClock.date.getTime() : 0 // Formatted remaining time for a rule's expiresAt, driven by the ticking @@ -915,8 +925,7 @@ Singleton { readonly property date time: new Date() readonly property string timeStr: { - if (root.overlayOpen) - minuteClock.date; + root.relativeTimeNow; root.clockFormatChanged; const now = new Date();