github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/static_source/admin/public/sw.js (about)

     1  import {cleanupOutdatedCaches, precacheAndRoute} from 'workbox-precaching'
     2  
     3  precacheAndRoute(self.__WB_MANIFEST || [])
     4  
     5  cleanupOutdatedCaches()
     6  
     7  // Install and activate service worker
     8  self.addEventListener('install', () => self.skipWaiting());
     9  
    10  // self.addEventListener('activate', () => self.clients.claim())
    11  self.addEventListener('activate', (event) => {
    12    self.skipWaiting()
    13    self.clients.claim();
    14  });
    15  
    16  // Receive push notifications
    17  self.addEventListener('push', function (e) {
    18    if (!(
    19      self.Notification &&
    20      self.Notification.permission === 'granted'
    21    )) {
    22      console.log('notifications aren\'t supported or permission not granted!')
    23      return;
    24    }
    25  
    26    if (e.data) {
    27      try {
    28        let message = e.data.json();
    29        self.registration.showNotification(message.title, {
    30          body: message.body,
    31          icon: message.icon,
    32          actions: message.actions
    33        });
    34      } catch (e) {
    35        console.warn(e.data)
    36      }
    37    }
    38  });