forked from glowing-bear/glowing-bear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use service workers for notifications
If Service Workers are available use them to display notifications instead of the old way of creating notifications directly. This has the side effect that it works nicely on chrome on android which the old method does not. This also paves the way to set up GCM for push notification in the future which can give us push notifications without having the app running. This patch can be improved in the future to get existing notifications and change the message instead of just adding more and more notifications. See: ServiceWorkerRegistration.getNotifications() and ServiceWorkerRegistration.update() from https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
- Loading branch information
Showing
2 changed files
with
77 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// File needs to be stored in the root of the app. | ||
|
||
this.addEventListener('install', function(event) { | ||
event.waitUntil( | ||
caches.open('v1').then(function(cache) { | ||
return cache.addAll([ | ||
'assets/img/glowing_bear_128x128.png', | ||
]); | ||
}) | ||
); | ||
}); | ||
|
||
this.addEventListener('push', function(event) { | ||
// TODO, support GCM here | ||
var title = 'Push message'; | ||
event.waitUntil( | ||
self.registration.showNotification(title, { | ||
body: 'The Message', | ||
icon: 'assets/img/favicon.png', | ||
tag: 'my-tag' | ||
})); | ||
}); |