Notification timeouts #502
authorDarren <darren@darrenwhitlen.com>
Thu, 8 May 2014 15:45:57 +0000 (16:45 +0100)
committerDarren <darren@darrenwhitlen.com>
Thu, 8 May 2014 15:45:57 +0000 (16:45 +0100)
client/src/applets/settings.js
client/src/views/application.js

index f041ab196506c6ba4efe2fcbed8ceb52707540e2..aa5896d22d319520d69f49a8c006b01e2d021acc 100644 (file)
         },\r
 \r
         enableNoticiations: function(event){\r
-            window.webkitNotifications.requestPermission();\r
+            event.preventDefault();\r
+\r
+            if ('webkitNotifications' in window) {\r
+                window.webkitNotifications.requestPermission();\r
+            } else if ('Notification' in window) {\r
+                Notification.requestPermission();\r
+            }\r
         }\r
 \r
     });\r
index b4522bc9df653c6b431d06f4e9ac535897620f19..6564cd64c4491c83d71c76d333a7785b4700eb42 100644 (file)
@@ -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);
     }
 });