From: Darren Date: Thu, 8 May 2014 15:45:57 +0000 (+0100) Subject: Notification timeouts #502 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=98bc1a84b554193e119e3e19c82d19ca9d0329e5;p=KiwiIRC.git Notification timeouts #502 --- diff --git a/client/src/applets/settings.js b/client/src/applets/settings.js index f041ab1..aa5896d 100644 --- a/client/src/applets/settings.js +++ b/client/src/applets/settings.js @@ -122,7 +122,13 @@ }, enableNoticiations: function(event){ - window.webkitNotifications.requestPermission(); + event.preventDefault(); + + if ('webkitNotifications' in window) { + window.webkitNotifications.requestPermission(); + } else if ('Notification' in window) { + Notification.requestPermission(); + } } }); diff --git a/client/src/views/application.js b/client/src/views/application.js index b4522bc..6564cd6 100644 --- a/client/src/views/application.js +++ b/client/src/views/application.js @@ -326,17 +326,30 @@ _kiwi.view.Application = Backbone.View.extend({ showNotification: function(title, message) { - var icon = this.model.get('base_path') + '/assets/img/ico.png'; - - // Check if we have notification support - if (!window.webkitNotifications) - return; + var icon = this.model.get('base_path') + '/assets/img/ico.png', + notification; if (this.has_focus) return; - if (webkitNotifications.checkPermission() === 0){ - window.webkitNotifications.createNotification(icon, title, message).show(); + // Different versions of Chrome/firefox have different implimentations + if ('Notification' in window && Notification.permission && Notification.permission === 'granted') { + notification = new Notification(title, {icon: icon, body: message}); + + } else if ('webkitNotifications' in window && webkitNotifications.checkPermission() === 0) { + notification = window.webkitNotifications.createNotification(icon, title, message); + + } else if ('mozNotification' in navigator) { + notification = navigator.mozNotification.createNotification(title, message, icon); } + + if (!notification) { + // Couldn't find any notification support + return; + } + + setTimeout(function() { + (notification.cancel || notification.close).call(notification); + }, 5000); } });