repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

plan: fix transient toast rendering + verify expireTimeout units

26dff62ec62b11d9f3fdfe4976efce4477d0f948

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

- transient notifications now render as toasts via a toastById store
  (rows, not just ids) so they show without polluting history — matches spec
- add -t 3000 custom-timeout test to pin expireTimeout seconds-vs-ms
  (Context7 doc unreliable; freedesktop wire is ms)

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

Changed files (1)

quickshell/nuguland/docs/superpowers/plans/2026-06-27-notifications-redesign.md

Modified
162 162 In `Notifications.qml`, add after `expandedGroups` (~line 15):
163 163 ```qml
164 164 property var activeToasts: []
165 + property var toastById: ({})
165 166 readonly property int defaultToastTimeoutMs: 5000
168 +`activeToasts` holds ids in display order; `toastById` maps id → the toast's row snapshot. Storing the row (not just the id) is what lets **transient** notifications — which are never added to `notifications` history — still render as toasts.
168 170 Add helpers near `mergeRow`:
169 171 ```qml
186 +> **`expireTimeout` units are UNVERIFIED.** The Context7 Quickshell page claims `expireTimeout` is in *seconds* (hence `* 1000`), but that page has known errors (it also mislabels `summary` as an image), and the freedesktop wire protocol carries `expire_timeout` in *milliseconds*. Task 4 Step 2 includes a `-t 3000` test that pins this down: if a `-t 3000` toast lingers ~50 minutes instead of ~3 s, Quickshell already hands you milliseconds — drop the `* 1000` (return `et`) and re-test. Do not trust the doc; trust the `-t 3000` observation.
184 188 Extend `selfTest()` (append before its `return`):
185 189 ```qml
186 190 expect(toastEligible({"urgency": "normal"}, false) === true, "normal toasts when DND off");
209 213 ```qml
210 214 if (!row.transient)
211 215 ingest(row);
212 - if (toastEligible(row, dnd))
216 + if (toastEligible(row, dnd)) {
217 + const map = Object.assign({}, toastById);
218 + map[row.id] = row;
219 + toastById = map;
213 220 activeToasts = activeToasts.filter((x) => x !== row.id).concat([row.id]);
223 +A replace (same id) overwrites `toastById[row.id]`, so the live toast updates in place. Transient rows are skipped by `ingest` (no history) but still land in `toastById`, so they render as toasts and auto-expire — matching the spec's "transient = toast only, never persists".
216 225 - [ ] **Step 3: Add `activeToastRows` / `dismissToast` / `dismissToasts`; surface in stateJson**
218 227 ```qml
219 228 function activeToastRows() {
220 229 const rows = [];
221 - for (let t = 0; t < activeToasts.length; t++)
222 - for (let i = 0; i < notifications.length; i++)
223 - if (notifications[i].id === activeToasts[t] && !notifications[i].closed)
224 - rows.push(Object.assign({}, notifications[i], {
225 - "actionRows": actionRows(notifications[i]),
226 - "timeoutMs": toastTimeoutMs(notifications[i])
227 - }));
230 + for (let t = 0; t < activeToasts.length; t++) {
231 + const row = toastById[activeToasts[t]];
232 + if (row && !row.closed)
233 + rows.push(Object.assign({}, row, {
234 + "actionRows": actionRows(row),
235 + "timeoutMs": toastTimeoutMs(row)
236 + }));
228 238 return rows;
231 241 function dismissToast(id) {
232 242 activeToasts = activeToasts.filter((x) => x !== String(id));
243 + const map = Object.assign({}, toastById);
244 + delete map[String(id)];
245 + toastById = map;
233 246 return stateJson();
236 249 function dismissToasts() {
237 250 activeToasts = [];
251 + toastById = ({});
238 252 return stateJson();
256 +`activeToastRows()` resolves from `toastById` (not `notifications` history), so transient toasts — which never enter history — still render. A non-transient row lives in both stores; the toast copy carries the urgency/expireTimeout the renderer needs.
242 258 In `stateObject()` (~line 283) add to the returned object:
243 259 ```qml
244 260 "activeToasts": activeToastRows(),
247 -In `closeNotification` (~line 336), append at the end:
263 +In `closeNotification` (~line 336), append at the end (drop from both toast stores):
248 264 ```qml
249 265 activeToasts = activeToasts.filter((x) => x !== String(row.id));
266 + const tmap = Object.assign({}, toastById);
267 + delete tmap[String(row.id)];
268 + toastById = tmap;
252 -> Transient notifications are not added to `notifications`, so `activeToastRows()` cannot resolve them; transient toasts do not render in this iteration. Note this in the commit.
254 271 - [ ] **Step 4: Expose `notificationsDismissToasts` IPC**
256 273 In `shell.qml` `target: "nuguland"` handler, add:
269 286 qs -c nuguland ipc call nuguland notificationsState | python3 -c 'import sys,json;print("toasts",len(json.load(sys.stdin)["activeToasts"]))' # expect 1
270 287 qs -c nuguland ipc call nuguland notificationsDismissToasts >/dev/null
271 288 qs -c nuguland ipc call nuguland notificationsState | python3 -c 'import sys,json;d=json.load(sys.stdin);print("toasts",len(d["activeToasts"]),"history",d["activeCount"])' # expect toasts 0, history 1
289 +# transient: must appear as a toast but NOT enter history
290 +qs -c nuguland ipc call nuguland notificationsDismissToasts >/dev/null
291 +qs -c nuguland ipc call nuguland notificationsState | python3 -c 'import sys,json;print("history_before",json.load(sys.stdin)["activeCount"])'
292 +notify-send --hint=boolean:transient:true "Transient" "toast only, no history"
293 +qs -c nuguland ipc call nuguland notificationsState | python3 -c 'import sys,json;d=json.load(sys.stdin);print("toasts",len(d["activeToasts"]),"history",d["activeCount"])' # expect toasts 1, history unchanged
274 296 - [ ] **Step 6: Commit**
738 760 notify-send "Toast test" "single line, top-right, auto-fade"
739 761 sleep 1; niri msg action screenshot-screen --path /tmp/notif-toast.png --write-to-disk true
741 -Read `/tmp/notif-toast.png`: compact single-line toast top-right, icon + summary only. Wait >5s, screenshot again → gone. Then:
763 +Read `/tmp/notif-toast.png`: compact single-line toast top-right, icon + summary only. Wait >5s, screenshot again → gone. Then pin down the `expireTimeout` units (see the note on `toastTimeoutMs` in Task 2):
764 +```bash
765 +notify-send -t 3000 "Timed toast" "should vanish ~3s"
766 +sleep 4; niri msg action screenshot-screen --path /tmp/notif-toast-timed.png --write-to-disk true
767 +```
768 +Read it: the timed toast must be **gone** by ~4 s. If it is still present (stuck ~50 min), `expireTimeout` is already in milliseconds — change `toastTimeoutMs` to `return et;` (drop `* 1000`), restart, and repeat this step until ~3 s holds. Then:
742 769 ```bash
743 770 notify-send -u critical "Critical toast" "must stay until dismissed"
744 771 sleep 7; niri msg action screenshot-screen --path /tmp/notif-toast-crit.png --write-to-disk true