mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
Notification: move lastSeenTs to cache/noctalia/notifications-state.json
This commit is contained in:
@@ -179,17 +179,16 @@
|
||||
"network": {
|
||||
"wifiEnabled": true
|
||||
},
|
||||
"notifications": {
|
||||
"doNotDisturb": false,
|
||||
"monitors": [],
|
||||
"location": "top_right",
|
||||
"alwaysOnTop": false,
|
||||
"lastSeenTs": 0,
|
||||
"respectExpireTimeout": false,
|
||||
"lowUrgencyDuration": 3,
|
||||
"normalUrgencyDuration": 8,
|
||||
"criticalUrgencyDuration": 15
|
||||
},
|
||||
"notifications": {
|
||||
"doNotDisturb": false,
|
||||
"monitors": [],
|
||||
"location": "top_right",
|
||||
"alwaysOnTop": false,
|
||||
"respectExpireTimeout": false,
|
||||
"lowUrgencyDuration": 3,
|
||||
"normalUrgencyDuration": 8,
|
||||
"criticalUrgencyDuration": 15
|
||||
},
|
||||
"osd": {
|
||||
"enabled": true,
|
||||
"location": "top_right",
|
||||
|
||||
@@ -313,7 +313,6 @@ Singleton {
|
||||
property list<string> monitors: []
|
||||
property string location: "top_right"
|
||||
property bool alwaysOnTop: false
|
||||
property real lastSeenTs: 0
|
||||
property bool respectExpireTimeout: false
|
||||
property int lowUrgencyDuration: 3
|
||||
property int normalUrgencyDuration: 8
|
||||
|
||||
@@ -31,12 +31,8 @@ NIconButton {
|
||||
readonly property bool showUnreadBadge: (widgetSettings.showUnreadBadge !== undefined) ? widgetSettings.showUnreadBadge : widgetMetadata.showUnreadBadge
|
||||
readonly property bool hideWhenZero: (widgetSettings.hideWhenZero !== undefined) ? widgetSettings.hideWhenZero : widgetMetadata.hideWhenZero
|
||||
|
||||
function lastSeenTs() {
|
||||
return Settings.data.notifications?.lastSeenTs || 0
|
||||
}
|
||||
|
||||
function computeUnreadCount() {
|
||||
var since = lastSeenTs()
|
||||
var since = NotificationService.lastSeenTs
|
||||
var count = 0
|
||||
var model = NotificationService.historyList
|
||||
for (var i = 0; i < model.count; i++) {
|
||||
|
||||
@@ -17,7 +17,7 @@ NPanel {
|
||||
panelKeyboardFocus: true
|
||||
|
||||
onOpened: function () {
|
||||
Settings.data.notifications.lastSeenTs = Time.timestamp * 1000
|
||||
NotificationService.updateLastSeenTs()
|
||||
}
|
||||
|
||||
panelContent: Rectangle {
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user