Built motion from commit 10af8726.|2.6.34
[motion2.git] / public / notification.js
1 (function() {
2   'use strict';
3
4   var notifications = [];
5
6   self.addEventListener('install', function(e) {
7     e.waitUntil(self.skipWaiting()); // Activate worker immediately
8   });
9
10   self.addEventListener('activate', function(e) {
11     e.waitUntil(self.clients.claim()); // Become available to all pages
12   });
13
14   self.addEventListener('notificationclick', function(e) {
15     var notification = e.notification;
16     var action = e.action;
17
18     switch (action) {
19       case 'accept':
20       case 'reject':
21         notification.close();
22         // Focus tab if open
23         e.waitUntil(clients.matchAll({
24           includeUncontrolled: true,
25           type: 'window'
26         }).then(function(clients) {
27           for (var i = 0; i < clients.length; i++) {
28             clients[i].postMessage({
29               action: action,
30               id: notification.data.id
31             });
32           }
33         }));
34         break;
35
36
37       default:
38     }
39   });
40 })();