also looking at this
feat(notifications): make the banner answerable — clicks, buttons, and a crash
#74
8 files
+942
-17
| @@ -814,12 +814,51 @@ export interface AppInfo { | ||
| 814 | 814 | /** |
| 815 | 815 | * Notification options |
| 816 | 816 | */ |
| 817 | /** | |
| 818 | * A button on a notification banner. | |
| 819 | * | |
| 820 | * macOS shows two directly on a banner and puts any others behind an | |
| 821 | * "Options" disclosure, so craft accepts at most four — past that they are | |
| 822 | * a menu the user has to go looking for rather than a choice they can see. | |
| 823 | * | |
| 824 | * Two spellings are accepted. `{ id, label }` is the one to use. `{ action, | |
| 825 | * title }` is what this type has said since before anything implemented it, | |
| 826 | * and it keeps working rather than being deleted out from under whoever wrote | |
| 827 | * against it — the field was published, it just never did anything. | |
| 828 | */ | |
| 829 | export type NotificationAction = | |
| 830 | | { | |
| 831 | /** Comes back as `actionId` in `craft.notifications.onAction`. */ | |
| 832 | id: string | |
| 833 | /** The text on the button. */ | |
| 834 | label: string | |
| 835 | } | |
| 836 | | { | |
| 837 | /** @deprecated Use `id`. */ | |
| 838 | action: string | |
| 839 | /** @deprecated Use `label`. */ | |
| 840 | title: string | |
| 841 | } | |
| 842 | ||
| 817 | 843 | export interface NotificationOptions { |
| 818 | 844 | /** |
| 819 | 845 | * Notification title (required) |
| 820 | 846 | */ |
| 821 | 847 | title: string |
| 822 | 848 | |
| 849 | /** | |
| 850 | * Buttons on the banner. | |
| 851 | * | |
| 852 | * Pressing one brings the app forward and fires | |
| 853 | * `craft.notifications.onAction` with `{ notificationId, actionId }` — | |
| 854 | * which is what lets a prompt be answered without switching to the app | |
| 855 | * first. | |
| 856 | * | |
| 857 | * Two buttons cannot share an `id`: the response names the button by id, | |
| 858 | * and for an Approve/Deny prompt that name is the entire answer. | |
| 859 | */ | |
| 860 | actions?: NotificationAction[] | |
| 861 | ||
| 823 | 862 | /** |
| 824 | 863 | * Notification body text |
| 825 | 864 | */ |
| @@ -839,14 +878,6 @@ export interface NotificationOptions { | ||
| 839 | 878 | */ |
| 840 | 879 | sound?: string |
| 841 | 880 | |
| 842 | /** | |
| 843 | * Action buttons (platform dependent) | |
| 844 | */ | |
| 845 | actions?: Array<{ | |
| 846 | action: string | |
| 847 | title: string | |
| 848 | }> | |
| 849 | ||
| 850 | 881 | /** |
| 851 | 882 | * Notification tag (for grouping/replacing) |
| 852 | 883 | */ |