From 1c7fa956dc4aa7815f927e87dd2dbc3d008a1320 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 4 May 2015 11:14:03 +1000 Subject: [PATCH] Improve Notification probing --- .../lib/desktop-notifications.js.es6 | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/desktop-notifications.js.es6 b/app/assets/javascripts/discourse/lib/desktop-notifications.js.es6 index dc20601f417..8dfedc2a14c 100644 --- a/app/assets/javascripts/discourse/lib/desktop-notifications.js.es6 +++ b/app/assets/javascripts/discourse/lib/desktop-notifications.js.es6 @@ -30,21 +30,20 @@ function init(messageBus) { - try { - if (!Notification) { - Em.Logger.info('Discourse desktop notifications are disabled - not supported by browser'); - return; - } - } catch (e) { - Em.Logger.info('Discourse desktop notifications are disabled - not defined'); + if (!("Notification" in window)) { + Em.Logger.info('Discourse desktop notifications are disabled - not supported by browser'); return; } - if (Notification.permission === "granted") { - havePermission = true; - } else if (Notification.permission === "denied") { - havePermission = false; - return; + try { + if (Notification.permission === "granted") { + havePermission = true; + } else if (Notification.permission === "denied") { + havePermission = false; + return; + } + } catch (e) { + Em.Logger.warn('Unexpected error, Notification is defined on window but not a responding correctly ' + e); } liveEnabled = true;