notification cooldown
This commit is contained in:
+26
-1
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user