- One slate/blue palette across the app, dashboard, account/login pages (data colours stay orange = warm, blue = cool on the dashboard) - Slim sticky top bar with location chip, gear (settings) and ? (learn); 4-tab nav (Now, Station, Map, Alerts) with a thumb-reach bottom bar on phones - Hero sky gradient by condition/time with rain, storm, snow and star effects (respects reduced motion); keeps the searched city and badges when temps come from your station - One-line summary, 'Next 2 hours' bars and rain countdown from 15-minute precipitation, rain/cold-aware 'Bring' chips; yesterday + 'vs usual' context from the station - Scrubbable hourly chart (temp, rain chance, wind), 7-day range bars, AQI gauge, details tiles instead of drawers, taller radar with location marker + alert polygons - Skeleton loading instead of a full-screen spinner, sticky section headers, safe areas - Server: minutely_15 precipitation, public /api/station/summary Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
125 lines
3.3 KiB
JavaScript
125 lines
3.3 KiB
JavaScript
'use strict';
|
|
|
|
self.addEventListener('message', event => {
|
|
if (event.data === 'skipWaiting') self.skipWaiting();
|
|
});
|
|
|
|
const CACHE = 'weather-v9';
|
|
|
|
// App shell cached on install for offline resilience.
|
|
const PRECACHE = [
|
|
'/',
|
|
'/app.js',
|
|
'/style.css',
|
|
'/station-live.css',
|
|
'/station-live.js',
|
|
'/app-ui.css',
|
|
'/app-ui.js',
|
|
'/manifest.json',
|
|
'/icons/icon.svg'
|
|
];
|
|
|
|
self.addEventListener('install', event => {
|
|
event.waitUntil(
|
|
caches.open(CACHE)
|
|
.then(cache => cache.addAll(PRECACHE))
|
|
.then(() => self.skipWaiting())
|
|
);
|
|
});
|
|
|
|
self.addEventListener('activate', event => {
|
|
event.waitUntil(
|
|
caches.keys()
|
|
.then(keys => Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k))))
|
|
.then(() => self.clients.claim())
|
|
);
|
|
});
|
|
|
|
self.addEventListener('push', event => {
|
|
if (!event.data) return;
|
|
let payload;
|
|
try { payload = event.data.json(); } catch { payload = { title: 'NeCloud Weather', body: event.data.text() }; }
|
|
event.waitUntil(
|
|
self.registration.showNotification(payload.title || 'NeCloud Weather', {
|
|
body: payload.body || '',
|
|
icon: '/icons/icon-192.png',
|
|
badge: '/icons/icon-192.png',
|
|
tag: payload.tag || 'weather-alert',
|
|
data: { url: payload.url || '/' },
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('notificationclick', event => {
|
|
event.notification.close();
|
|
const url = event.notification.data?.url || '/';
|
|
event.waitUntil(
|
|
clients.matchAll({ type: 'window', includeUncontrolled: true }).then(wins => {
|
|
for (const w of wins) {
|
|
if (w.url.startsWith(self.registration.scope) && 'focus' in w) {
|
|
w.navigate(url);
|
|
return w.focus();
|
|
}
|
|
}
|
|
return clients.openWindow(url);
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('fetch', event => {
|
|
const { request } = event;
|
|
const url = new URL(request.url);
|
|
|
|
// Never intercept API/tile traffic.
|
|
if (
|
|
request.method !== 'GET' ||
|
|
url.pathname.startsWith('/api/') ||
|
|
url.hostname.includes('rainviewer') ||
|
|
url.hostname.includes('openstreetmap') ||
|
|
url.hostname.includes('cartodb') ||
|
|
url.hostname.includes('basemaps')
|
|
) {
|
|
return;
|
|
}
|
|
|
|
const isShell =
|
|
request.mode === 'navigate' ||
|
|
request.destination === 'document' ||
|
|
request.destination === 'script' ||
|
|
request.destination === 'style';
|
|
|
|
if (isShell) {
|
|
// Network-first keeps app updates fresh; cache as fallback.
|
|
event.respondWith(
|
|
fetch(request)
|
|
.then(response => {
|
|
if (response.ok) {
|
|
const clone = response.clone();
|
|
caches.open(CACHE).then(cache => cache.put(request, clone));
|
|
}
|
|
return response;
|
|
})
|
|
.catch(() => caches.match(request).then(cached => cached || caches.match('/')))
|
|
);
|
|
return;
|
|
}
|
|
|
|
// Cache-first for static assets.
|
|
event.respondWith(
|
|
caches.match(request).then(cached => {
|
|
if (cached) return cached;
|
|
return fetch(request).then(response => {
|
|
if (response.ok && (
|
|
url.origin === self.location.origin ||
|
|
url.hostname.includes('googleapis') ||
|
|
url.hostname.includes('gstatic') ||
|
|
url.hostname.includes('unpkg.com')
|
|
)) {
|
|
const clone = response.clone();
|
|
caches.open(CACHE).then(cache => cache.put(request, clone));
|
|
}
|
|
return response;
|
|
});
|
|
})
|
|
);
|
|
}); |