notification cooldown

This commit is contained in:
Zacharias-Brohn
2026-02-25 17:08:04 +01:00
parent 419214f4bd
commit eafb176d6e
3 changed files with 40 additions and 7 deletions
+26 -1
View File
@@ -23,6 +23,29 @@ Singleton {
readonly property list<Notif> popups: list.filter(n => n.popup)
property alias server: server
readonly property var appCooldownMap: new Map()
function shouldThrottle(appName: string): bool {
if ( props.dnd )
return false;
const key = ( appName || "unknown" ).trim().toLowerCase();
const cooldownSec = Config.notifs.appNotifCooldown;
const cooldownMs = Math.max(0, cooldownSec * 1000);
if ( cooldownMs <= 0 )
return true;
const now = Date.now();
const until = appCooldownMap.get( key ) ?? 0;
if ( now < until )
return false;
appCooldownMap.set( key, now + cooldownMs )
return true;
}
onListChanged: {
if (loaded) {
saveTimer.restart();
@@ -77,8 +100,10 @@ Singleton {
onNotification: notif => {
notif.tracked = true;
const is_popup = root.shouldThrottle(notif.appName);
const comp = notifComp.createObject(root, {
popup: !props.dnd,
popup: is_popup,
notification: notif
});
root.list = [comp, ...root.list];