From c68ebc39096d93867058f011b4e6313f53128819 Mon Sep 17 00:00:00 2001 From: Kit La Touche Date: Tue, 5 Nov 2024 22:22:22 -0500 Subject: Start to make this a PWA --- ui/app.html | 1 + ui/routes/(app)/+layout.svelte | 2 +- ui/routes/+layout.svelte | 2 +- ui/service-worker.js | 35 ++++++++++++++++++++++++++++++++++ ui/static/manifest.json | 43 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 ui/service-worker.js create mode 100644 ui/static/manifest.json (limited to 'ui') diff --git a/ui/app.html b/ui/app.html index 51a6780..4dc66f4 100644 --- a/ui/app.html +++ b/ui/app.html @@ -4,6 +4,7 @@ + %sveltekit.head% diff --git a/ui/routes/(app)/+layout.svelte b/ui/routes/(app)/+layout.svelte index ae3dc6a..2725c65 100644 --- a/ui/routes/(app)/+layout.svelte +++ b/ui/routes/(app)/+layout.svelte @@ -55,7 +55,7 @@ - understory + pilcrow {#if loading} diff --git a/ui/routes/+layout.svelte b/ui/routes/+layout.svelte index d786389..da5bbe0 100644 --- a/ui/routes/+layout.svelte +++ b/ui/routes/+layout.svelte @@ -28,7 +28,7 @@ logo - understory + pilcrow {#if $currentUser} diff --git a/ui/service-worker.js b/ui/service-worker.js new file mode 100644 index 0000000..e29fab3 --- /dev/null +++ b/ui/service-worker.js @@ -0,0 +1,35 @@ +/// +/// +/// +/// + +import { build, files, version } from '$service-worker'; + +// Create a unique cache name for this deployment +const CACHE = `cache-${version}`; + +const ASSETS = [ + ...build, // the app itself + ...files // everything in `static` +]; + +self.addEventListener('install', (event) => { + // Create a new cache and add all files to it + async function addFilesToCache() { + const cache = await caches.open(CACHE); + await cache.addAll(ASSETS); + } + + event.waitUntil(addFilesToCache()); +}); + +self.addEventListener('activate', (event) => { + // Remove previous cached data from disk + async function deleteOldCaches() { + for (const key of await caches.keys()) { + if (key !== CACHE) await caches.delete(key); + } + } + + event.waitUntil(deleteOldCaches()); +}); diff --git a/ui/static/manifest.json b/ui/static/manifest.json new file mode 100644 index 0000000..2d4cf39 --- /dev/null +++ b/ui/static/manifest.json @@ -0,0 +1,43 @@ +{ + "name": "Pilcrow", + "short_name": "Pilcrow", + "start_url": "index.html", + "display": "standalone", + "background_color": "#fdfdfd", + "theme_color": "#db4938", + "orientation": "portrait-primary", + "icons": [ + { + "src": "/favicon.png", + "type": "image/png", "sizes": "72x72" + }, + { + "src": "/favicon.png", + "type": "image/png", "sizes": "96x96" + }, + { + "src": "/favicon.png", + "type": "image/png","sizes": "128x128" + }, + { + "src": "/favicon.png", + "type": "image/png", "sizes": "144x144" + }, + { + "src": "/favicon.png", + "type": "image/png", "sizes": "152x152" + }, + { + "src": "/favicon.png", + "type": "image/png", "sizes": "192x192" + }, + { + "src": "/favicon.png", + "type": "image/png", "sizes": "384x384" + }, + { + "src": "/favicon.png", + "type": "image/png", "sizes": "512x512" + } + ] +} -- cgit v1.2.3