deckhearth/public/sw.js
Randall Stillwell 0a03f0ed14 🚀 Convert to mobile-first PWA with purple theme
- Add PWA configuration (manifest.json, service worker)
- Implement light/dark theme system with purple accents
- Replace desktop navbar with mobile-first bottom navigation
- Redesign auth forms with mobile-optimized UI
- Update Dashboard with gradient cards and touch-friendly actions
- Add safe area support for iOS devices
- Implement theme context with system preference detection
- Optimize touch targets and mobile interactions
- Add offline functionality through service worker
2025-07-22 18:52:39 -05:00

87 lines
No EOL
2 KiB
JavaScript

const CACHE_NAME = 'tcg-vault-v1';
const urlsToCache = [
'/',
'/static/js/bundle.js',
'/static/css/main.css',
'/manifest.json',
'/favicon.ico',
'/logo192.png',
'/logo512.png'
];
// Install event
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME)
.then((cache) => cache.addAll(urlsToCache))
.catch((error) => {
console.error('Failed to cache resources:', error);
})
);
});
// Fetch event
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request)
.then((response) => {
// Return cached version or fetch from network
return response || fetch(event.request);
})
.catch((error) => {
console.error('Fetch failed:', error);
// Return offline page if available
return caches.match('/');
})
);
});
// Activate event
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((cacheNames) => {
return Promise.all(
cacheNames.map((cacheName) => {
if (cacheName !== CACHE_NAME) {
return caches.delete(cacheName);
}
})
);
})
);
});
// Background sync for offline actions
self.addEventListener('sync', (event) => {
if (event.tag === 'background-sync') {
event.waitUntil(
// Handle offline actions when back online
console.log('Background sync triggered')
);
}
});
// Push notifications (for future use)
self.addEventListener('push', (event) => {
if (event.data) {
const data = event.data.json();
const options = {
body: data.body,
icon: '/logo192.png',
badge: '/favicon.ico',
vibrate: [200, 100, 200]
};
event.waitUntil(
self.registration.showNotification(data.title, options)
);
}
});
// Notification click
self.addEventListener('notificationclick', (event) => {
event.notification.close();
event.waitUntil(
clients.openWindow('/')
);
});