Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(local-notification): Throw unavailable if Notification API not supported #285

Merged
merged 5 commits into from
Mar 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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