also looking at this
feat(notifications): make the banner answerable — clicks, buttons, and a crash
#74
8 files
+942
-17
| @@ -577,11 +577,14 @@ | ||
| 577 | 577 | // ------------------------------------------------------------------------- |
| 578 | 578 | window.craft.notifications = { |
| 579 | 579 | show: function (opts) { |
| 580 | // Convenience wrapper around schedule with no triggerAt. | |
| 581 | 580 | const o = Object.assign({}, opts || {}) |
| 582 | 581 | if (typeof o.title !== 'string' || o.title.length === 0) { |
| 583 | 582 | return Promise.reject(new Error('notification title is required')) |
| 584 | 583 | } |
| 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 | |
| 585 | 588 | return _send('notification', 'schedule', _stringify(o)) |
| 586 | 589 | }, |
| 587 | 590 | schedule: function (opts) { return _send('notification', 'schedule', _stringify(opts || {})) }, |
| @@ -590,6 +593,14 @@ | ||
| 590 | 593 | setBadge: function (n) { return _send('notification', 'setBadge', _stringify({ count: Number(n) || 0 })) }, |
| 591 | 594 | clearBadge: function () { return _send('notification', 'clearBadge') }, |
| 592 | 595 | 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'), | |
| 593 | 604 | } |
| 594 | 605 | |
| 595 | 606 | // ------------------------------------------------------------------------- |