- Add A-Z alphabetical filter keyboard for clients and suppliers lists (same pattern as company selection, without emoji) - Increase clients/suppliers list pagination from 10 to 20 items per page - Remove emoji from company A-Z filter button for consistency - Add 6 new callback handlers: clients_alpha_menu, clients_alpha:LETTER, clients_alpha_page:PAGE:LETTER, and supplier equivalents - Dashboard service and models updates - Telegram bot: email handlers, auth, DB operations, internal API improvements - Frontend: dashboard cards updates (CashFlow, Clienti, Furnizori, Treasury) - Frontend: SolduriCompactCard and CollapsibleCard improvements - DashboardView enhancements - start.sh and run-with-restart.sh script updates - IIS web.config and service worker updates Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
90 lines
2.4 KiB
JavaScript
90 lines
2.4 KiB
JavaScript
// Service Worker for ROA2WEB PWA
|
|
// Network-first strategy to always show fresh content
|
|
|
|
const CACHE_VERSION = 'v2';
|
|
const CACHE_NAME = `roa2web-${CACHE_VERSION}`;
|
|
|
|
// Install event - skip waiting to activate immediately
|
|
self.addEventListener('install', (event) => {
|
|
console.log('[SW] Installing service worker...');
|
|
self.skipWaiting();
|
|
});
|
|
|
|
// Activate event - clear old caches and claim clients
|
|
self.addEventListener('activate', (event) => {
|
|
console.log('[SW] Service worker activated');
|
|
event.waitUntil(
|
|
Promise.all([
|
|
// Clear all old caches
|
|
caches.keys().then(cacheNames => {
|
|
return Promise.all(
|
|
cacheNames.map(cacheName => {
|
|
if (cacheName !== CACHE_NAME) {
|
|
console.log('[SW] Deleting old cache:', cacheName);
|
|
return caches.delete(cacheName);
|
|
}
|
|
})
|
|
);
|
|
}),
|
|
// Take control of all clients immediately
|
|
clients.claim()
|
|
]).then(() => {
|
|
// Notify all clients that a new SW version is active
|
|
return clients.matchAll({ includeUncontrolled: true }).then(allClients => {
|
|
allClients.forEach(client => {
|
|
client.postMessage({ type: 'SW_UPDATED' });
|
|
});
|
|
});
|
|
})
|
|
);
|
|
});
|
|
|
|
// Message handler - allows pages to trigger SW actions
|
|
self.addEventListener('message', (event) => {
|
|
if (event.data && event.data.type === 'SKIP_WAITING') {
|
|
self.skipWaiting();
|
|
}
|
|
});
|
|
|
|
// Fetch event - ALWAYS network first, no caching for HTML/JS/CSS
|
|
self.addEventListener('fetch', (event) => {
|
|
const url = new URL(event.request.url);
|
|
|
|
// Skip non-GET requests
|
|
if (event.request.method !== 'GET') {
|
|
return;
|
|
}
|
|
|
|
// API calls - always network, no cache
|
|
if (url.pathname.includes('/api/')) {
|
|
event.respondWith(fetch(event.request));
|
|
return;
|
|
}
|
|
|
|
// index.html - bypass HTTP cache entirely to always get fresh app shell
|
|
if (
|
|
url.pathname.endsWith('index.html') ||
|
|
url.pathname === '/roa2web/' ||
|
|
url.pathname === '/roa2web'
|
|
) {
|
|
event.respondWith(
|
|
fetch(event.request, { cache: 'no-cache' })
|
|
.catch(() => caches.match(event.request))
|
|
);
|
|
return;
|
|
}
|
|
|
|
// HTML, JS, CSS - always fetch fresh from network
|
|
// This ensures PWA always loads latest version
|
|
event.respondWith(
|
|
fetch(event.request)
|
|
.then(response => {
|
|
return response;
|
|
})
|
|
.catch(() => {
|
|
// Only fallback to cache if network fails
|
|
return caches.match(event.request);
|
|
})
|
|
);
|
|
});
|