Skip to content

Commit

Permalink
fix(local-notification): Throw unavailable if Notification API not su…
Browse files Browse the repository at this point in the history
…pported (#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 <jcesarmobile@gmail.com>
  • Loading branch information
theproducer and jcesarmobile authored Mar 3, 2021
1 parent 168d692 commit a90a88b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions local-notifications/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export class LocalNotificationsWeb
}

async schedule(options: ScheduleOptions): Promise<ScheduleResult> {
if (!('Notification' in window)) {
throw this.unavailable('Notifications not supported in this browser.');
}

for (const notification of options.notifications) {
this.sendNotification(notification);
}
Expand Down Expand Up @@ -67,6 +71,10 @@ export class LocalNotificationsWeb
}

async requestPermissions(): Promise<PermissionStatus> {
if (!('Notification' in window)) {
throw this.unavailable('Notifications not supported in this browser.');
}

const display = this.transformNotificationPermission(
await Notification.requestPermission(),
);
Expand All @@ -75,6 +83,10 @@ export class LocalNotificationsWeb
}

async checkPermissions(): Promise<PermissionStatus> {
if (!('Notification' in window)) {
throw this.unavailable('Notifications not supported in this browser.');
}

const display = this.transformNotificationPermission(
Notification.permission,
);
Expand Down

0 comments on commit a90a88b

Please sign in to comment.