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
+13 -6
View File
@@ -205,6 +205,7 @@ Singleton {
return {
expire: notifs.expire,
defaultExpireTimeout: notifs.defaultExpireTimeout,
appNotifCooldown: notifs.appNotifCooldown,
clearThreshold: notifs.clearThreshold,
expandThreshold: notifs.expandThreshold,
actionOnClick: notifs.actionOnClick,
@@ -306,7 +307,8 @@ Singleton {
fileView.setText(JSON.stringify(config, null, 4));
} catch (e) {
Toaster.toast(qsTr("Failed to serialize config"), e.message, "settings_alert", Toast.Error);
Toaster.toast(qsTr("Failed to serialize config"), e.message,
"settings_alert", Toast.Error);
}
}
}
@@ -337,7 +339,8 @@ Singleton {
}
onLoadFailed: err => {
if (err !== FileViewError.FileNotFound)
Toaster.toast(qsTr("Failed to read config"), FileViewError.toString(err), "settings_alert", Toast.Warning);
Toaster.toast(qsTr("Failed to read config"), FileViewError.toString(err),
"settings_alert", Toast.Warning);
}
onLoaded: {
ModeScheduler.checkStartup();
@@ -346,15 +349,19 @@ Singleton {
const elapsed = timer.elapsedMs();
if (adapter.utilities.toasts.configLoaded && !root.recentlySaved) {
Toaster.toast(qsTr("Config loaded"), qsTr("Config loaded in %1ms").arg(elapsed), "rule_settings");
Toaster.toast(qsTr("Config loaded"), qsTr("Config loaded in %1ms").arg(
elapsed), "rule_settings");
} else if (adapter.utilities.toasts.configLoaded && root.recentlySaved) {
Toaster.toast(qsTr("Config saved"), qsTr("Config reloaded in %1ms").arg(elapsed), "settings_alert");
Toaster.toast(qsTr("Config saved"), qsTr("Config reloaded in %1ms").arg(
elapsed), "settings_alert");
}
} catch (e) {
Toaster.toast(qsTr("Failed to load config"), e.message, "settings_alert", Toast.Error);
Toaster.toast(qsTr("Failed to load config"), e.message, "settings_alert",
Toast.Error);
}
}
onSaveFailed: err => Toaster.toast(qsTr("Failed to save config"), FileViewError.toString(err), "settings_alert", Toast.Error)
onSaveFailed: err => Toaster.toast(qsTr("Failed to save config"),
FileViewError.toString(err), "settings_alert", Toast.Error)
JsonAdapter {
id: adapter
+1
View File
@@ -2,6 +2,7 @@ import Quickshell.Io
JsonObject {
property bool actionOnClick: false
property int appNotifCooldown: 0
property real clearThreshold: 0.3
property int defaultExpireTimeout: 5000
property int expandThreshold: 20
+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];