Enable PWA features

This commit is contained in:
Fred Boniface 2023-06-21 14:56:12 +01:00
parent b2c74b8a8a
commit 1da58ba944
4 changed files with 93 additions and 3 deletions

View File

@ -1,9 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="icon" href="%sveltekit.assets%/images/icon.svg">
<meta name="viewport" content="width=device-width">
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">

View File

@ -1,4 +1,15 @@
<script>
import '../app.css'
</script>
<svelte:head>
<meta charset="utf-8">
<meta name="application-name" content="OwlBoard">
<meta name="author" content="Frederick Boniface">
<meta name="description" content="Live train data, PIS Codes & reference data. Built by railway staff, for railway staff.">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#00b7b7">
<link rel="icon" href="/images/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png">
<link rel="manifest" href="/manifest.json">
</svelte:head>
<slot />

49
src/service-worker.js Normal file
View File

@ -0,0 +1,49 @@
/// <reference types="@sveltejs/kit" />
import { build, files, version } from '$service-worker';
const cacheName = `ob-${version}`;
const assets = [
...build,
...files
];
self.addEventListener('install', (event) => {
async function addToCache() {
const cache = await caches.open(cacheName);
await cache.addAll(assets);
}
event.waitUntil(addToCache());
})
self.addEventListener('activate', (event) => {
async function deleteOldCache() {
for (const key of await caches.keys()) {
if (key !== cacheName) {
await caches.delete(key);
}
}
}
event.waitUntil(deleteOldCache());
})
self.addEventListener('fetch', (event) => {
if (event.request.method !== 'GET') {return}
async function respond() {
const cacheRes = await caches.match(event.request, {ignoreSearch: true});
if (cacheRes) {
return cacheRes;
}
try {
return await fetch(event.request)
} catch (err) {
return {"error": "OFFLINE", "errorMsg": "You are not online"};
}
}
event.respondWith(respond());
})

33
static/manifest.json Normal file
View File

@ -0,0 +1,33 @@
{
"name": "OwlBoard",
"short_name": "OwlBoard",
"start_url": "/",
"scope": "/",
"display": "standalone",
"background_color": "#404c55",
"description": "Live station departures, PIS Code Lookup, Reference Data, Timetable search, with enhanced data for staff.",
"categories": "travel,utilities",
"lang": "en",
"orientation": "portrait",
"theme_color": "#00b7b7",
"icons": [
{
"src": "/images/app-icons/maskable/mask-icon.svg",
"sizes": "any",
"type": "image/svg+xml",
"purpose": "maskable"
},
{
"src": "/images/app-icons/any/plain-logo.svg",
"sizes": "any",
"type": "image/svg+xml",
"purpose": "any"
},
{
"src": "/images/app-icons/any/plain-logo-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
}
]
}