From c60418b1f45340c2c46817162cbec763856018b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joost=20Z=C3=B6llner?= Date: Fri, 28 Sep 2018 09:47:14 +0200 Subject: [PATCH] refactor(service-worker): Rework notification click handler (#25860) - Add missing image and timestamp properties - Remove focus from click handler PR Close #25860 --- packages/service-worker/worker/src/driver.ts | 24 +++++--------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/packages/service-worker/worker/src/driver.ts b/packages/service-worker/worker/src/driver.ts index 4837f1244a..c65e9bfbb4 100644 --- a/packages/service-worker/worker/src/driver.ts +++ b/packages/service-worker/worker/src/driver.ts @@ -34,8 +34,8 @@ const NOTIFICATION_OPTION_NAMES = [ 'vibrate', 'data' ]; const NOTIFICATION_CLICK_OPTION_NAMES = [ - 'actions', 'badge', 'title', 'body', 'dir', 'icon', 'lang', 'renotify', 'requireInteraction', - 'tag', 'vibrate', 'data' + 'actions', 'badge', 'title', 'body', 'dir', 'icon', 'image', 'lang', 'renotify', + 'requireInteraction', 'tag', 'timestamp', 'vibrate', 'data' ]; interface LatestEntry { @@ -309,15 +309,15 @@ export class Driver implements Debuggable, UpdateSource { await this.scope.registration.showNotification(desc['title'] !, options); } - private async handleClick(notification: any, action?: string): Promise { - (notification as Notification).close(); + private async handleClick(notification: Notification, action?: string): Promise { + notification.close(); - const desc = notification as{[key: string]: string | undefined}; + const desc = notification as any; let options: {[key: string]: string | undefined} = {}; NOTIFICATION_CLICK_OPTION_NAMES.filter(name => desc.hasOwnProperty(name)) .forEach(name => options[name] = desc[name]); - await this.broadcastAndFocus({ + await this.broadcast({ type: 'NOTIFICATION_CLICK', data: {action, notification: options}, }); @@ -1007,18 +1007,6 @@ export class Driver implements Debuggable, UpdateSource { }, Promise.resolve()); } - async broadcastAndFocus(msg: Object): Promise { - const clients = await this.scope.clients.matchAll(); - clients.forEach((client: any) => { - if ('focus' in client) { - if (!client.focused) { - client.focus(); - } - } - client.postMessage(msg); - }); - } - async broadcast(msg: Object): Promise { const clients = await this.scope.clients.matchAll(); clients.forEach(client => { client.postMessage(msg); });