1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Check browser has notification capability

This commit is contained in:
Daniel Barber 2018-08-14 14:14:08 -04:00
parent 175bb9e5c7
commit 88416fcd54
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8

View File

@ -1,7 +1,9 @@
class Notifications { class Notifications {
constructor() { constructor() {
if (this.notifications_available) {
Notification.requestPermission(); Notification.requestPermission();
} }
}
notifyTurn(player) { notifyTurn(player) {
this.notify({ this.notify({
@ -11,10 +13,14 @@ class Notifications {
} }
notify(options) { notify(options) {
if (!document.hasFocus()) { if (this.notifications_available && !document.hasFocus()) {
new Notification("Chess", options); new Notification("Chess", options);
} }
} }
get notifications_available() {
window.Notification != undefined;
}
} }
export default Notifications; export default Notifications;