workspace/projects/gamilit/apps/frontend/public/firebase-messaging-sw.js
rckrdmrd ea1879f4ad feat: Initial workspace structure with multi-level Git configuration
- Configure workspace Git repository with comprehensive .gitignore
- Add Odoo as submodule for ERP reference code
- Include documentation: SETUP.md, GIT-STRUCTURE.md
- Add gitignore templates for projects (backend, frontend, database)
- Structure supports independent repos per project/subproject level

Workspace includes:
- core/ - Reusable patterns, modules, orchestration system
- projects/ - Active projects (erp-suite, gamilit, trading-platform, etc.)
- knowledge-base/ - Reference code and patterns (includes Odoo submodule)
- devtools/ - Development tools and templates
- customers/ - Client implementations template

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-08 10:44:23 -06:00

77 lines
2.4 KiB
JavaScript

// Firebase Messaging Service Worker
// This file must be in the public directory to be served from root
// Import Firebase scripts
importScripts('https://www.gstatic.com/firebasejs/10.7.0/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/10.7.0/firebase-messaging-compat.js');
// Initialize Firebase with same config
// Note: These will need to be updated with actual values or injected at build time
const firebaseConfig = {
apiKey: '',
authDomain: '',
projectId: '',
storageBucket: '',
messagingSenderId: '',
appId: '',
};
// Only initialize if we have configuration
if (firebaseConfig.apiKey && firebaseConfig.projectId) {
firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();
// Handle background messages
messaging.onBackgroundMessage((payload) => {
console.log('[SW] Background message received:', payload);
const notificationTitle = payload.notification?.title || 'GAMILIT';
const notificationOptions = {
body: payload.notification?.body || '',
icon: '/icons/icon-192x192.png',
badge: '/icons/badge-72x72.png',
tag: payload.data?.tag || 'default',
data: payload.data,
// Vibration pattern: vibrate 200ms, pause 100ms, vibrate 200ms
vibrate: [200, 100, 200],
// Actions for interactive notifications
actions: [
{ action: 'open', title: 'Ver' },
{ action: 'dismiss', title: 'Cerrar' },
],
};
self.registration.showNotification(notificationTitle, notificationOptions);
});
// Handle notification click
self.addEventListener('notificationclick', (event) => {
console.log('[SW] Notification clicked:', event);
event.notification.close();
if (event.action === 'dismiss') {
return;
}
// Open or focus the app
const urlToOpen = event.notification.data?.action_url || '/notifications';
event.waitUntil(
clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clientList) => {
// Check if app is already open
for (const client of clientList) {
if (client.url.includes(self.location.origin) && 'focus' in client) {
client.focus();
client.navigate(urlToOpen);
return;
}
}
// If not open, open new window
if (clients.openWindow) {
return clients.openWindow(urlToOpen);
}
})
);
});
}