Skip to content

Commit

Permalink
refactor: notification services controller - silently handle push not…
Browse files Browse the repository at this point in the history
…ifications (#4536)

## Explanation

Even if extensions permit push notifications, browsers can still block
push notifications. This change allows push notifications to silently
fail, and allow notifications to still be created.

## References


## Changelog

### `@metamask/notification-services-controller`

- **ADDED**: catch statements to log and silently fail push notification
actions.

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
  • Loading branch information
Prithpal-Sooriya committed Jul 18, 2024
1 parent db8774c commit b7fa70e
Showing 1 changed file with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,28 +284,40 @@ export default class NotificationServicesController extends BaseController<
if (!this.#isPushIntegrated) {
return;
}
await this.messagingSystem.call(
'NotificationServicesPushController:enablePushNotifications',
UUIDs,
);
try {
await this.messagingSystem.call(
'NotificationServicesPushController:enablePushNotifications',
UUIDs,
);
} catch (e) {
log.error('Silently failed to enable push notifications', e);
}
},
disablePushNotifications: async (UUIDs: string[]) => {
if (!this.#isPushIntegrated) {
return;
}
await this.messagingSystem.call(
'NotificationServicesPushController:disablePushNotifications',
UUIDs,
);
try {
await this.messagingSystem.call(
'NotificationServicesPushController:disablePushNotifications',
UUIDs,
);
} catch (e) {
log.error('Silently failed to disable push notifications', e);
}
},
updatePushNotifications: async (UUIDs: string[]) => {
if (!this.#isPushIntegrated) {
return;
}
await this.messagingSystem.call(
'NotificationServicesPushController:updateTriggerPushNotifications',
UUIDs,
);
try {
await this.messagingSystem.call(
'NotificationServicesPushController:updateTriggerPushNotifications',
UUIDs,
);
} catch (e) {
log.error('Silently failed to update push notifications', e);
}
},
subscribe: () => {
if (!this.#isPushIntegrated) {
Expand Down

0 comments on commit b7fa70e

Please sign in to comment.