mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-30 18:47:51 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			38 lines
		
	
	
		
			975 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			975 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /* eslint-disable no-restricted-globals, no-console */
 | |
| /* globals clients */
 | |
| self.addEventListener('push', event => {
 | |
|   let notification = event.data && event.data.json();
 | |
| 
 | |
|   event.waitUntil(
 | |
|     self.registration.showNotification(notification.title, {
 | |
|       tag: notification.tag,
 | |
|       data: {
 | |
|         url: notification.url,
 | |
|       },
 | |
|     })
 | |
|   );
 | |
| });
 | |
| 
 | |
| self.addEventListener('notificationclick', event => {
 | |
|   let notification = event.notification;
 | |
| 
 | |
|   event.waitUntil(
 | |
|     clients.matchAll({ type: 'window' }).then(windowClients => {
 | |
|       let matchingWindowClients = windowClients.filter(
 | |
|         client => client.url === notification.data.url
 | |
|       );
 | |
| 
 | |
|       if (matchingWindowClients.length) {
 | |
|         let firstWindow = matchingWindowClients[0];
 | |
|         if (firstWindow && 'focus' in firstWindow) {
 | |
|           firstWindow.focus();
 | |
|           return;
 | |
|         }
 | |
|       }
 | |
|       if (clients.openWindow) {
 | |
|         clients.openWindow(notification.data.url);
 | |
|       }
 | |
|     })
 | |
|   );
 | |
| });
 | 
