Add extra message to +error.svelte to handle, and clarify 'OFFLINE' error.

This commit is contained in:
2026-05-14 19:43:22 +01:00
parent 25b64edabd
commit 1105a9f7c5
6 changed files with 111 additions and 120 deletions

View File

@@ -251,7 +251,7 @@
@media (min-width: 620px) { @media (min-width: 620px) {
.cancel-row td, .cancel-row td,
.delay-row td { .delay-row td {
font-size: 1.20rem; font-size: 1.2rem;
} }
} }

View File

@@ -7,7 +7,7 @@ export interface Preferences {
const STORAGE_KEY = 'ob_pref'; const STORAGE_KEY = 'ob_pref';
const DEFAULT_PREFS: Preferences = { const DEFAULT_PREFS: Preferences = {
locationEnabled: false, locationEnabled: false
}; };
function loadPrefs(): Preferences { function loadPrefs(): Preferences {

View File

@@ -12,6 +12,7 @@
<img class="err-img" src={noResult} alt="" role="presentation" width="200" height="200" /> <img class="err-img" src={noResult} alt="" role="presentation" width="200" height="200" />
{:else if page.status == 499} {:else if page.status == 499}
<!-- Change to a GSM-R X Sign?? --> <!-- Change to a GSM-R X Sign?? -->
<span>OFFLINE!</span>
<img class="err-img" src={stopErr} alt="" role="presentation" width="150" height="210" /> <img class="err-img" src={stopErr} alt="" role="presentation" width="150" height="210" />
{:else} {:else}
<!-- STOP Error image --> <!-- STOP Error image -->

View File

@@ -22,11 +22,11 @@
if (browser && 'serviceWorker' in navigator) { if (browser && 'serviceWorker' in navigator) {
try { try {
const registration = await navigator.serviceWorker.register('/service-worker.js', { const registration = await navigator.serviceWorker.register('/service-worker.js', {
type: 'module', type: 'module'
}); });
console.info('OwlBoard Service Worker registered', registration.scope); console.info('OwlBoard Service Worker registered', registration.scope);
} catch (error) { } catch (error) {
console.error('Service Worker installation failed: ', error) console.error('Service Worker installation failed: ', error);
} }
} }
}); });

View File

@@ -8,18 +8,13 @@ const sw = self as unknown as ServiceWorkerGlobalScope;
const CACHE_NAME = `owlboard-cache-${version}`; const CACHE_NAME = `owlboard-cache-${version}`;
const ASSETS = [ const ASSETS = [
...build, ...build,
...files.filter(file => ...files.filter((file) => !file.endsWith('manifest.json') && !file.startsWith('/icons/')),
!file.endsWith('manifest.json') && '/'
!file.startsWith('/icons/')
),
'/',
]; ];
sw.addEventListener('install', (event) => { sw.addEventListener('install', (event) => {
sw.skipWaiting(); sw.skipWaiting();
event.waitUntil( event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS)));
caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS))
);
}); });
sw.addEventListener('activate', (event) => { sw.addEventListener('activate', (event) => {
@@ -49,9 +44,7 @@ sw.addEventListener('fetch', (event) => {
// 1. Static Assets (Cache-First) // 1. Static Assets (Cache-First)
if (ASSETS.includes(url.pathname) || url.pathname.startsWith('/_app/')) { if (ASSETS.includes(url.pathname) || url.pathname.startsWith('/_app/')) {
event.respondWith( event.respondWith(caches.match(request).then((res) => res || fetch(request)));
caches.match(request).then((res) => res || fetch(request))
);
return; return;
} }
@@ -61,18 +54,15 @@ sw.addEventListener('fetch', (event) => {
fetch(request).catch(() => { fetch(request).catch(() => {
const errorObject: ApiEnvelope.Envelope = { const errorObject: ApiEnvelope.Envelope = {
e: { e: {
code: "NETWORK_DISCONNECTED", code: 'NETWORK_DISCONNECTED',
msg: "Cannot connect to the OwlBoard server" msg: 'Cannot connect to the OwlBoard server'
}, },
t: Math.floor(Date.now() / 1000) t: Math.floor(Date.now() / 1000)
}; };
return new Response( return new Response(JSON.stringify(errorObject), {
JSON.stringify(errorObject),
{
status: 503, status: 503,
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
} });
);
}) })
); );
return; return;