repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

notifications: activeToasts model with DND/critical/transient lifecycle + dismissToasts

5526ad6f36c31bf1d35435ce2675752ba53c0a24

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Changed files (2)

+74 / −2 text lines

Diff layout

quickshell/nuguland/Notifications.qml

Modified

+70 / −2 text lines

1313 property var nativeNotifications: ({
1414 })
1515 property var expandedGroups: []
16 property var activeToasts: []
17 property var toastById: ({})
18 readonly property int defaultToastTimeoutMs: 5000
1619 property var pointerTrace: []
1720 property var lastAction: ({
1821 })
111114 "body": record.body || "",
112115 "time": Number(record.time || Date.now()),
113116 "urgency": urgencyName(record.urgency || "normal"),
117 "expireTimeout": Number(record.expireTimeout !== undefined ? record.expireTimeout : -1),
118 "transient": !!record.transient,
114119 "actions": actions,
115120 "popup": !(dnd || popupInhibition),
116121 "closed": false,
119124 };
120125 }
127 function toastEligible(row, dndOn) {
128 if (row.urgency === "critical")
129 return true;
130 return !dndOn;
131 }
133 function toastTimeoutMs(row) {
134 if (row.urgency === "critical" || Number(row.expireTimeout) === 0)
135 return 0;
136 const et = Number(row.expireTimeout);
137 return et > 0 ? Math.round(et * 1000) : defaultToastTimeoutMs;
138 }
122140 function mergeRow(list, row) {
123141 const next = (list || []).slice();
124142 for (let i = 0; i < next.length; i++) {
162180 rlist = mergeRow(rlist, {"id": "9", "summary": "x", "closed": false, "read": true});
163181 rlist = mergeRow(rlist, {"id": "9", "summary": "y", "closed": false, "read": false});
164182 expect(rlist[0].read === true, "replace-by-id should preserve original read flag");
183 expect(toastEligible({"urgency": "normal"}, false) === true, "normal toasts when DND off");
184 expect(toastEligible({"urgency": "normal"}, true) === false, "normal suppressed under DND");
185 expect(toastEligible({"urgency": "critical"}, true) === true, "critical bypasses DND");
186 expect(toastTimeoutMs({"urgency": "critical", "expireTimeout": 5}) === 0, "critical is sticky");
187 expect(toastTimeoutMs({"urgency": "normal", "expireTimeout": 0}) === 0, "expireTimeout 0 is sticky");
188 expect(toastTimeoutMs({"urgency": "normal", "expireTimeout": -1}) === defaultToastTimeoutMs, "default timeout");
165189 return {
166190 "pass": failures.length === 0,
167191 "failures": failures
188212 "body": notification.body,
189213 "time": Date.now(),
190214 "urgency": notification.urgency,
215 "expireTimeout": notification.expireTimeout,
216 "transient": notification.transient,
191217 "actions": notification.actions || []
192218 });
193 ingest(row);
219 if (!row.transient)
220 ingest(row);
221 if (toastEligible(row, dnd)) {
222 const map = Object.assign({}, toastById);
223 map[row.id] = row;
224 toastById = map;
225 activeToasts = activeToasts.filter((x) => x !== row.id).concat([row.id]);
226 }
194227 lastAction = {
195228 "kind": "native-notification",
196229 "id": id,
247280 });
248281 }
283 function activeToastRows() {
284 const rows = [];
285 for (let t = 0; t < activeToasts.length; t++) {
286 const stored = toastById[activeToasts[t]];
287 if (!stored)
288 continue;
289 const row = liveRow(stored);
290 if (!row.closed)
291 rows.push(Object.assign({}, row, {
292 "actionRows": actionRows(row),
293 "timeoutMs": toastTimeoutMs(row)
294 }));
295 }
296 return rows;
297 }
299 function dismissToast(id) {
300 activeToasts = activeToasts.filter((x) => x !== String(id));
301 const map = Object.assign({}, toastById);
302 delete map[String(id)];
303 toastById = map;
304 return stateJson();
305 }
307 function dismissToasts() {
308 activeToasts = [];
309 toastById = ({});
310 return stateJson();
311 }
250313 function groups() {
251314 const byApp = ({
252315 });
378441 "discardAll": true,
379442 "removalLifecycleLock": removalLifecycleLock,
380443 "pointerTrace": pointerTrace,
381 "lastAction": lastAction
444 "lastAction": lastAction,
445 "activeToasts": activeToastRows()
382446 };
383447 }
406470 if (nativeActionRoute && nativeNotification && nativeNotification.dismiss)
407471 nativeNotification.dismiss();
473 activeToasts = activeToasts.filter((x) => x !== String(row.id));
474 const tmap = Object.assign({}, toastById);
475 delete tmap[String(row.id)];
476 toastById = tmap;
409477 }
411479 function runAction(notificationId, actionId) {

quickshell/nuguland/shell.qml

Modified

+4 / −0 text lines

528528 return JSON.stringify(notifications.selfTest());
529529 }
531 function notificationsDismissToasts() : string {
532 return notifications.dismissToasts();
533 }
531535 function trayWidgetState(attention: bool, active: bool) : string {
532536 return tray.widgetState(attention, active);
533537 }