mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-11 07:52:50 -05:00
fix: Notification timestamp tracking
This commit is contained in:
@@ -35,6 +35,21 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Global timer to update all notification timestamps
|
||||||
|
Timer {
|
||||||
|
id: timeUpdateTimer
|
||||||
|
interval: 30000 // Update every 30 seconds
|
||||||
|
repeat: true
|
||||||
|
running: root.allWrappers.length > 0
|
||||||
|
triggeredOnStart: false
|
||||||
|
onTriggered: {
|
||||||
|
root.timeUpdateTick = !root.timeUpdateTick
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
property bool timeUpdateTick: false
|
||||||
|
property bool clockFormatChanged: false
|
||||||
|
|
||||||
// Android 16-style grouped notifications
|
// Android 16-style grouped notifications
|
||||||
readonly property var groupedNotifications: getGroupedNotifications()
|
readonly property var groupedNotifications: getGroupedNotifications()
|
||||||
readonly property var groupedPopups: getGroupedPopups()
|
readonly property var groupedPopups: getGroupedPopups()
|
||||||
@@ -98,18 +113,54 @@ Singleton {
|
|||||||
wrapper.popup = false
|
wrapper.popup = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
readonly property date time: new Date()
|
readonly property date time: new Date()
|
||||||
readonly property string timeStr: {
|
readonly property string timeStr: {
|
||||||
|
root.timeUpdateTick
|
||||||
|
root.clockFormatChanged
|
||||||
|
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const diff = now.getTime() - time.getTime()
|
const diff = now.getTime() - time.getTime()
|
||||||
const m = Math.floor(diff / 60000)
|
const minutes = Math.floor(diff / 60000)
|
||||||
const h = Math.floor(m / 60)
|
const hours = Math.floor(minutes / 60)
|
||||||
|
|
||||||
if (h < 1 && m < 1)
|
if (hours < 1) {
|
||||||
return "now"
|
if (minutes < 1)
|
||||||
if (h < 1)
|
return "now"
|
||||||
return `${m}m`
|
return `${minutes}m ago`
|
||||||
return `${h}h`
|
}
|
||||||
|
|
||||||
|
const nowDate = new Date(now.getFullYear(), now.getMonth(), now.getDate())
|
||||||
|
const timeDate = new Date(time.getFullYear(), time.getMonth(), time.getDate())
|
||||||
|
const daysDiff = Math.floor((nowDate - timeDate) / (1000 * 60 * 60 * 24))
|
||||||
|
|
||||||
|
if (daysDiff === 0) {
|
||||||
|
return formatTime(time)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (daysDiff === 1) {
|
||||||
|
return `yesterday, ${formatTime(time)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${daysDiff} days ago`
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTime(date) {
|
||||||
|
let use24Hour = true
|
||||||
|
try {
|
||||||
|
if (typeof SettingsData !== "undefined" && SettingsData.use24HourClock !== undefined) {
|
||||||
|
use24Hour = SettingsData.use24HourClock
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
use24Hour = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (use24Hour) {
|
||||||
|
return date.toLocaleTimeString(Qt.locale(), "HH:mm")
|
||||||
|
} else {
|
||||||
|
return date.toLocaleTimeString(Qt.locale(), "h:mm AP")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
required property Notification notification
|
required property Notification notification
|
||||||
@@ -455,4 +506,12 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Watch for clock format changes to update notification timestamps
|
||||||
|
Connections {
|
||||||
|
target: typeof SettingsData !== "undefined" ? SettingsData : null
|
||||||
|
function onUse24HourClockChanged() {
|
||||||
|
root.clockFormatChanged = !root.clockFormatChanged
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user