Notification: move lastSeenTs to cache/noctalia/notifications-state.json

This commit is contained in:
lysec
2025-10-21 14:50:27 +02:00
parent 96cb0a5199
commit 4aa32dbdb3
5 changed files with 63 additions and 19 deletions
+51 -1
View File
@@ -16,6 +16,10 @@ Singleton {
property int maxVisible: 5
property int maxHistory: 100
property string historyFile: Quickshell.env("NOCTALIA_NOTIF_HISTORY_FILE") || (Settings.cacheDir + "notifications.json")
property string stateFile: Settings.cacheDir + "notifications-state.json"
// State
property real lastSeenTs: 0
// Models
property ListModel activeList: ListModel {}
@@ -264,7 +268,7 @@ Singleton {
saveHistory()
}
// Persistence
// Persistence - History
FileView {
id: historyFileView
path: historyFile
@@ -281,6 +285,23 @@ Singleton {
}
}
// Persistence - State (lastSeenTs, etc.)
FileView {
id: stateFileView
path: stateFile
printErrors: false
onLoaded: loadState()
onLoadFailed: error => {
if (error === 2)
writeAdapter()
}
JsonAdapter {
id: stateAdapter
property real lastSeenTs: 0
}
}
Timer {
id: saveTimer
interval: 200
@@ -337,6 +358,35 @@ Singleton {
}
}
function loadState() {
try {
root.lastSeenTs = stateAdapter.lastSeenTs || 0
// Migration: if state file is empty but settings has lastSeenTs, migrate it
if (root.lastSeenTs === 0 && Settings.data.notifications && Settings.data.notifications.lastSeenTs) {
root.lastSeenTs = Settings.data.notifications.lastSeenTs
saveState()
Logger.i("Notifications", "Migrated lastSeenTs from settings to state file")
}
} catch (e) {
Logger.e("Notifications", "Load state failed:", e)
}
}
function saveState() {
try {
stateAdapter.lastSeenTs = root.lastSeenTs
stateFileView.writeAdapter()
} catch (e) {
Logger.e("Notifications", "Save state failed:", e)
}
}
function updateLastSeenTs() {
root.lastSeenTs = Time.timestamp * 1000
saveState()
}
function getAppName(name) {
if (!name || name.trim() === "")
return "Unknown"