-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
31 lines (25 loc) · 1.03 KB
/
sw.js
File metadata and controls
31 lines (25 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// sw.js
console.log('Service Worker carregado.');
// Evento 'push' é disparado quando o servidor envia uma notificação
self.addEventListener('push', event => {
console.log('[Service Worker] Push Recebido.');
// O backend envia os dados da notificação como texto JSON
const data = event.data.json();
console.log('[Service Worker] Dados do Push:', data);
const title = data.title || 'Gym Rats';
const options = {
body: data.body,
icon: 'assets/logo.ico', // Caminho para o seu ícone
badge: 'assets/logo.ico', // Ícone para Android
vibrate: [200, 100, 200] // Padrão de vibração
};
// Exibe a notificação
event.waitUntil(self.registration.showNotification(title, options));
});
// Opcional: clique na notificação abre o site
self.addEventListener('notificationclick', event => {
event.notification.close();
event.waitUntil(
clients.openWindow('https://equipegymrats.github.io/inicio/reminders.html') // Substitua pelo link do seu site
);
});