mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-05-12 11:30:20 +08:00
- Mounted static files directory to serve PWA assets like manifest.json and ServiceWorker scripts. - Updated `auth.html` and `keys_status.html` templates: - Added `<link>` for manifest and icons to support Progressive Web App (PWA) features. - Added meta tags for theme color and Apple web app capabilities. - Integrated ServiceWorker registration script for offline capabilities.
44 lines
942 B
JavaScript
44 lines
942 B
JavaScript
const CACHE_NAME = 'gbalance-cache-v1';
|
|
const urlsToCache = [
|
|
'/',
|
|
'/static/manifest.json',
|
|
'/static/icons/icon-192x192.png'
|
|
];
|
|
|
|
self.addEventListener('install', event => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME)
|
|
.then(cache => {
|
|
console.log('Opened cache');
|
|
return cache.addAll(urlsToCache);
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('fetch', event => {
|
|
event.respondWith(
|
|
caches.match(event.request)
|
|
.then(response => {
|
|
if (response) {
|
|
return response;
|
|
}
|
|
return fetch(event.request);
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('activate', event => {
|
|
const cacheWhitelist = [CACHE_NAME];
|
|
event.waitUntil(
|
|
caches.keys().then(cacheNames => {
|
|
return Promise.all(
|
|
cacheNames.map(cacheName => {
|
|
if (cacheWhitelist.indexOf(cacheName) === -1) {
|
|
return caches.delete(cacheName);
|
|
}
|
|
})
|
|
);
|
|
})
|
|
);
|
|
});
|