From 5ecaa9daca3473fde62aa1f272316a20cb35ae5e Mon Sep 17 00:00:00 2001 From: Nicholas Matlaga Date: Thu, 5 Oct 2017 11:45:01 -0400 Subject: [PATCH] fix Notification not being available crash --- .../static/webclient/js/webclient_gui.js | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/evennia/web/webclient/static/webclient/js/webclient_gui.js b/evennia/web/webclient/static/webclient/js/webclient_gui.js index 7f499253f9..c1af719f72 100644 --- a/evennia/web/webclient/static/webclient/js/webclient_gui.js +++ b/evennia/web/webclient/static/webclient/js/webclient_gui.js @@ -369,28 +369,29 @@ function onNewLine(text, originator) { unread++; favico.badge(unread); document.title = "(" + unread + ") " + originalTitle; + if ("Notification" in window){ + if (("notification_popup" in options) && (options["notification_popup"])) { + Notification.requestPermission().then(function(result) { + if(result === "granted") { + var title = originalTitle === "" ? "Evennia" : originalTitle; + var options = { + body: text.replace(/(<([^>]+)>)/ig,""), + icon: "/static/website/images/evennia_logo.png" + } - if (("notification_popup" in options) && (options["notification_popup"])) { - Notification.requestPermission().then(function(result) { - if(result === "granted") { - var title = originalTitle === "" ? "Evennia" : originalTitle; - var options = { - body: text.replace(/(<([^>]+)>)/ig,""), - icon: "/static/website/images/evennia_logo.png" + var n = new Notification(title, options); + n.onclick = function(e) { + e.preventDefault(); + window.focus(); + this.close(); + } } - - var n = new Notification(title, options); - n.onclick = function(e) { - e.preventDefault(); - window.focus(); - this.close(); - } - } - }); - } - if (("notification_sound" in options) && (options["notification_sound"])) { - var audio = new Audio("/static/webclient/media/notification.wav"); - audio.play(); + }); + } + if (("notification_sound" in options) && (options["notification_sound"])) { + var audio = new Audio("/static/webclient/media/notification.wav"); + audio.play(); + } } } } @@ -427,7 +428,9 @@ function doStartDragDialog(event) { // Event when client finishes loading $(document).ready(function() { - Notification.requestPermission(); + if ("Notification" in window) { + Notification.requestPermission(); + } favico = new Favico({ animation: 'none'