From 7238efb7abb8e2ecde0cc0ff0e7b782d05f44e8f Mon Sep 17 00:00:00 2001 From: andretshurotshka Date: Thu, 12 Sep 2019 05:05:01 +0500 Subject: [PATCH] [lib] Improve Notification API --- lib/dom.js | 75 +++++++++++++++++++++---------------------- lib/serviceworkers.js | 7 ++++ 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/lib/dom.js b/lib/dom.js index 5844637ecaa..b754b969e8c 100644 --- a/lib/dom.js +++ b/lib/dom.js @@ -3994,56 +3994,55 @@ type NotificationPermission = 'default' | 'denied' | 'granted'; type NotificationDirection = 'auto' | 'ltr' | 'rtl'; type VibratePattern = number | Array; type NotificationAction = { - action: string, - title: string, - icon?: string, - ... + action: string, + title: string, + icon?: string, + ... }; type NotificationOptions = { - dir?: NotificationDirection, - lang?: string, - body?: string, - tag?: string, - image?: string, - icon?: string, - badge?: string, - sound?: string, - vibrate?: VibratePattern, - timestamp?: number, - renotify?: boolean, - silent?: boolean, - requireInteraction?: boolean, - data?: ?any, - actions?: Array, - ... + dir?: NotificationDirection, + lang?: string, + body?: string, + tag?: string, + image?: string, + icon?: string, + badge?: string, + sound?: string, + vibrate?: VibratePattern, + timestamp?: number, + renotify?: boolean, + silent?: boolean, + requireInteraction?: boolean, + data?: any, + actions?: NotificationAction[], + ... }; declare class Notification extends EventTarget { constructor(title: string, options?: NotificationOptions): void; - static permission: NotificationPermission; + static +permission: NotificationPermission; + static +maxActions: number; static requestPermission( callback?: (perm: NotificationPermission) => mixed ): Promise; - static maxActions: number; onclick: ?(evt: Event) => mixed; onclose: ?(evt: Event) => mixed; onerror: ?(evt: Event) => mixed; onshow: ?(evt: Event) => mixed; - title: string; - dir: NotificationDirection; - lang: string; - body: string; - tag: string; - image?: string; - icon?: string; - badge?: string; - vibrate?: Array; - timestamp: number; - renotify: boolean; - silent: boolean; - requireInteraction: boolean; - data: any; - actions: Array; - + +title: string; + +dir: NotificationDirection; + +lang: string; + +body: string; + +tag: string; + +image?: string; + +icon?: string; + +badge?: string; + +vibrate?: $ReadOnlyArray; + +timestamp: number; + +renotify: boolean; + +silent: boolean; + +requireInteraction: boolean; + +data: any; + +actions: $ReadOnlyArray; close(): void; } diff --git a/lib/serviceworkers.js b/lib/serviceworkers.js index bfb0a950aff..801443fca27 100644 --- a/lib/serviceworkers.js +++ b/lib/serviceworkers.js @@ -117,6 +117,11 @@ declare class PushManager { type ServiceWorkerUpdateViaCache = 'imports' | 'all' | 'none'; +type GetNotificationOptions = { + tag?: string + ... +} + declare class ServiceWorkerRegistration extends EventTarget { +installing: ?ServiceWorker, +waiting: ?ServiceWorker, @@ -128,6 +133,8 @@ declare class ServiceWorkerRegistration extends EventTarget { update(): Promise, unregister(): Promise, + showNotification(title: string, options?: NotificationOptions): Promise, + getNotifications(filter?: GetNotificationOptions): Promise, onupdatefound?: EventHandler, }