From 88416fcd5424de88c8b1b8e9928f3c14b0c5e9f4 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Tue, 14 Aug 2018 14:14:08 -0400 Subject: [PATCH] Check browser has notification capability --- assets/js/services/notifications.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/js/services/notifications.js b/assets/js/services/notifications.js index 75376cf..bec9df9 100644 --- a/assets/js/services/notifications.js +++ b/assets/js/services/notifications.js @@ -1,6 +1,8 @@ class Notifications { constructor() { - Notification.requestPermission(); + if (this.notifications_available) { + Notification.requestPermission(); + } } notifyTurn(player) { @@ -11,10 +13,14 @@ class Notifications { } notify(options) { - if (!document.hasFocus()) { + if (this.notifications_available && !document.hasFocus()) { new Notification("Chess", options); } } + + get notifications_available() { + window.Notification != undefined; + } } export default Notifications;