Browse Source

add desktop notification

Hongcai Deng 9 years ago
parent
commit
4efaa80f54
1 changed files with 12 additions and 0 deletions
  1. 12 0
      public/js/app.js

+ 12 - 0
public/js/app.js

@@ -30,6 +30,18 @@ $(function(){
   });
 
   socket.on('mail', function(mail) {
+    if(('Notification' in window)) {
+      if(Notification.permission === 'granted') {
+        new Notification('New mail from ' + mail.headers.from);
+      }
+      else if(Notification.permission !== 'denied') {
+        Notification.requestPermission(function(permission) {
+          if(permission === 'granted') {
+            new Notification('New mail from ' + mail.headers.from);
+          }
+        })
+      }
+    }
     $tr = $('<tr>').data('mail', mail);
     $tr
       .append($('<td>').text(mail.headers.from))