repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

notifications: independent toast countdowns via stamped expiresAt

3c353402a0a5efa39fa25d699f2554db08ed27c5

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Toast timers and drain bars restarted from full whenever any other toast
was added, removed, or a notification replaced in place, because the toast
Repeater rebuilds every delegate on each model change.

Stamp an absolute expiresAt on the toast row once, when the toast is first
accepted (replace-in-place mutates the native object without re-firing
onNotification, so it never re-stamps). The delegate's dismiss Timer and
drain animation now derive their remaining time from expiresAt, so a
rebuilt delegate resumes the countdown at its true position instead of
restarting. Each toast's expiry is independent of the others.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Changed files (2)

quickshell/nuguland/Notifications.qml

Modified
210 210 if (!row.transient)
211 211 ingest(row);
212 212 if (eligible) {
213 + const tms = toastTimeoutMs(row);
213 214 const map = Object.assign({}, toastById);
214 - map[row.id] = row;
215 + // Stamp absolute expiry ONCE. The toast Repeater rebuilds every
216 + // delegate whenever the toast set changes; deriving the timer/drain
217 + // from a stored expiresAt lets a rebuilt delegate resume at the
218 + // right position instead of restarting from full.
219 + map[row.id] = Object.assign({}, row, {
220 + "toastTimeoutMs": tms,
221 + "expiresAt": tms > 0 ? Date.now() + tms : 0
222 + });
215 223 toastById = map;
216 224 activeToasts = activeToasts.filter((x) => x !== row.id).concat([row.id]);
281 289 if (!row.closed)
282 290 rows.push(Object.assign({}, row, {
283 291 "actionRows": actionRows(row),
284 - "timeoutMs": toastTimeoutMs(row)
292 + "timeoutMs": row.toastTimeoutMs !== undefined ? row.toastTimeoutMs : toastTimeoutMs(row),
293 + "expiresAt": row.expiresAt || 0
287 296 return rows;

quickshell/nuguland/shell.qml

Modified
315 315 onDismiss: (id) => notifications.dismissToast(id)
316 316 onInvokeAction: (id, actionId) => notifications.runAction(id, actionId)
318 + // Dismiss + drain derive from the service-stamped
319 + // absolute expiresAt, not a fresh interval, so a
320 + // Repeater rebuild (any other toast added/removed)
321 + // resumes the countdown rather than restarting it.
322 + readonly property real toastTotal: toastWrap.modelData.timeoutMs || 0
323 + readonly property real toastExpiry: toastWrap.modelData.expiresAt || 0
324 + readonly property real toastRemaining: Math.max(0, toastExpiry - Date.now())
318 325 Timer {
319 - running: (toastWrap.modelData.timeoutMs || 0) > 0
320 - interval: Math.max(1, toastWrap.modelData.timeoutMs || 0)
326 + running: toastWrap.toastExpiry > 0
327 + interval: Math.max(1, toastWrap.toastRemaining)
321 328 repeat: false
322 329 onTriggered: notifications.dismissToast(String(toastWrap.modelData.id))
324 331 // auto-dismiss countdown: a thin bar drains across the
325 - // bottom edge over the toast's lifetime (sticky/critical
326 - // have timeoutMs 0 -> hidden; lowPowerMode -> static).
332 + // bottom edge over the toast's remaining lifetime
333 + // (sticky/critical have expiresAt 0 -> hidden;
334 + // lowPowerMode -> static).
327 335 Rectangle {
328 - visible: (toastWrap.modelData.timeoutMs || 0) > 0
336 + visible: toastWrap.toastExpiry > 0
329 337 anchors.left: toastCard.left
330 338 anchors.bottom: toastCard.bottom
331 339 anchors.leftMargin: 12
333 341 height: 2
334 342 radius: 1
335 343 color: nuguTheme ? nuguTheme.withAlpha(nuguTheme.ui.accent, 0.55) : "transparent"
336 - width: toastCard.width - 24
344 + width: (toastCard.width - 24) * (toastWrap.toastTotal > 0 ? toastWrap.toastRemaining / toastWrap.toastTotal : 1)
337 345 NumberAnimation on width {
338 - running: (toastWrap.modelData.timeoutMs || 0) > 0 && !(nuguTheme && nuguTheme.lowPowerMode)
339 - from: toastCard.width - 24
346 + running: toastWrap.toastExpiry > 0 && !(nuguTheme && nuguTheme.lowPowerMode)
341 - duration: Math.max(1, toastWrap.modelData.timeoutMs || 0)
348 + duration: Math.max(1, toastWrap.toastRemaining)