From a90a88b217f5fa2a257416050afb476dd84d8051 Mon Sep 17 00:00:00 2001 From: Joey Pender Date: Wed, 3 Mar 2021 10:42:59 -0600 Subject: [PATCH] fix(local-notification): Throw unavailable if Notification API not supported (#285) * Throw unimplemented if Notification API not supported * using unavailable instead of unimplemented * Adding Notification API checks to `schedule` and `requestPermissions` Co-authored-by: jcesarmobile --- local-notifications/src/web.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/local-notifications/src/web.ts b/local-notifications/src/web.ts index 6c9da2ec8..3dd8c2156 100644 --- a/local-notifications/src/web.ts +++ b/local-notifications/src/web.ts @@ -30,6 +30,10 @@ export class LocalNotificationsWeb } async schedule(options: ScheduleOptions): Promise { + if (!('Notification' in window)) { + throw this.unavailable('Notifications not supported in this browser.'); + } + for (const notification of options.notifications) { this.sendNotification(notification); } @@ -67,6 +71,10 @@ export class LocalNotificationsWeb } async requestPermissions(): Promise { + if (!('Notification' in window)) { + throw this.unavailable('Notifications not supported in this browser.'); + } + const display = this.transformNotificationPermission( await Notification.requestPermission(), ); @@ -75,6 +83,10 @@ export class LocalNotificationsWeb } async checkPermissions(): Promise { + if (!('Notification' in window)) { + throw this.unavailable('Notifications not supported in this browser.'); + } + const display = this.transformNotificationPermission( Notification.permission, );