-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Description
Which @angular/* package(s) are relevant/related to the feature request?
service-worker
Description
Currently you can use Push notification for displaying notification messages. But it is not possible to change application badge from push notification when application is not started.
You can use setAppBadge from SwPush.messages, but this only works when application is already running.
Proposed solution
Support setting application badge natively in ngsw-worker.js. New push payload would look something like this:
{
"notification": {
"actions": NotificationAction[],
....
},
"appBadge": number | undefined
}
If appBadge property is not set nothing will happened, but if it is set, then inside "push" event, self.navigator.setAppBadge should be called with value of "appBadge". Setting "appBadge" to 0, will clear badge.
Alternatives considered
Now the only way to change application badge when application is offline is to use custom service worker to handle "push" event and then import ngsw-worker.js. But I'm not sure that even this will work on WebKit, because as stated in https://webkit.org/blog/14112/badging-for-home-screen-web-apps/ and if I understand correctly, both showNotification and setAppBadge must be 'promise' from same "push" event.