From 98bc1a84b554193e119e3e19c82d19ca9d0329e5 Mon Sep 17 00:00:00 2001 From: Darren Date: Thu, 8 May 2014 16:45:57 +0100 Subject: [PATCH] Notification timeouts #502 --- client/src/applets/settings.js | 8 +++++++- client/src/views/application.js | 27 ++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) 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); } }); -- 2.25.1