ReviewOS

also looking at this

craft-native/craft

feat(notifications): make the banner answerable — clicks, buttons, and a crash

#74
Merged glennmichael123 wants to merge feat/notification-actions into main
8 files +942 -17
packages/zig/src/js/craft-bridge.jsmodified+12-1
Changes to packages/zig/src/js/craft-bridge.js
@@ -577,11 +577,14 @@
577577 // -------------------------------------------------------------------------
578578 window.craft.notifications = {
579579 show: function (opts) {
580 // Convenience wrapper around schedule with no triggerAt.
581580 const o = Object.assign({}, opts || {})
582581 if (typeof o.title !== 'string' || o.title.length === 0) {
583582 return Promise.reject(new Error('notification title is required'))
584583 }
584 // `show` means now. This routes through `schedule`, whose delay defaults
585 // to sixty seconds — so every `show()` used to arrive a minute later,
586 // which from here is indistinguishable from one that never arrived.
587 if (typeof o.delay !== 'number') o.delay = 0
585588 return _send('notification', 'schedule', _stringify(o))
586589 },
587590 schedule: function (opts) { return _send('notification', 'schedule', _stringify(opts || {})) },
@@ -590,6 +593,14 @@
590593 setBadge: function (n) { return _send('notification', 'setBadge', _stringify({ count: Number(n) || 0 })) },
591594 clearBadge: function () { return _send('notification', 'clearBadge') },
592595 requestPermission: function () { return _req('notification', 'requestPermission').then(function (r) { return (r && r.granted) === true }) },
596 // The banner was a dead end: craft posted real notifications and
597 // registered no delegate, so a click reached nothing.
598 // onClick -> { notificationId }
599 // onAction -> { notificationId, actionId }
600 // A swipe-away arrives as an action with actionId 'dismiss', so an app
601 // waiting on an answer hears that there will not be one.
602 onClick: _evt('craft:notification:click'),
603 onAction: _evt('craft:notification:action'),
593604 }
594605
595606 // -------------------------------------------------------------------------