This repository has been archived on 2023-03-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
osr-discourse-src/app/assets/javascripts/discourse/initializers/badging.js.es6
T
Rafael dos Santos Silva 5a70f50032 FEATURE: Use new Badging API
Now that the spec is finished use the unprefixed API, which was also moved
from window to navigator.

Still uses feature detection so it fail gracefully when not available in
the user agent.
2020-01-10 13:41:35 -03:00

24 lines
575 B
JavaScript

// Updates the PWA badging if avaliable
export default {
name: "badging",
after: "message-bus",
initialize(container) {
if (!navigator.setAppBadge) return; // must have the Badging API
const user = container.lookup("current-user:main");
if (!user) return; // must be logged in
this.notifications =
user.unread_notifications + user.unread_private_messages;
container
.lookup("service:app-events")
.on("notifications:changed", this, "_updateBadge");
},
_updateBadge() {
navigator.setAppBadge(this.notifications);
}
};