diff --git a/website/src/app.html b/website/src/app.html index effe0d0d..2e06f55b 100644 --- a/website/src/app.html +++ b/website/src/app.html @@ -3,6 +3,7 @@ + %sveltekit.head% diff --git a/website/src/routes/header.svelte b/website/src/routes/header.svelte index a0c05d77..7f563ba5 100644 --- a/website/src/routes/header.svelte +++ b/website/src/routes/header.svelte @@ -6,7 +6,7 @@
- authme-logo + authme-logo

Authme

diff --git a/website/src/service-worker/index.ts b/website/src/service-worker/index.ts new file mode 100644 index 00000000..39c15ee0 --- /dev/null +++ b/website/src/service-worker/index.ts @@ -0,0 +1,82 @@ +/// +// @ts-nocheck +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()) +}) + +self.addEventListener("fetch", (event) => { + // ignore POST requests etc + if (event.request.method !== "GET") return + + async function respond() { + const url = new URL(event.request.url) + const cache = await caches.open(CACHE) + + // `build`/`files` can always be served from the cache + if (ASSETS.includes(url.pathname)) { + const response = await cache.match(url.pathname) + + if (response) { + return response + } + } + + // for everything else, try the network first, but + // fall back to the cache if we're offline + try { + const response = await fetch(event.request) + + // if we're offline, fetch can return a value that is not a Response + // instead of throwing - and we can't pass this non-Response to respondWith + if (!(response instanceof Response)) { + throw new Error("invalid response from fetch") + } + + console.log(response) + if (response.status === 200 && response.url.startsWith("http")) { + cache.put(event.request, response.clone()) + } + + return response + } catch (err) { + const response = await cache.match(event.request) + + if (response) { + return response + } + + // if there's no cache, then just error out + // as there is nothing we can do to respond to this request + throw err + } + } + + event.respondWith(respond()) +}) diff --git a/website/static/favicon.png b/website/static/favicon.png index b8cfea56..505c640c 100644 Binary files a/website/static/favicon.png and b/website/static/favicon.png differ diff --git a/website/static/icon.png b/website/static/icon.png index 21c0240a..505c640c 100644 Binary files a/website/static/icon.png and b/website/static/icon.png differ diff --git a/website/static/manifest.json b/website/static/manifest.json new file mode 100644 index 00000000..5ee682f5 --- /dev/null +++ b/website/static/manifest.json @@ -0,0 +1,40 @@ +{ + "$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/web-manifest.json", + "name": "Authme", + "short_name": "Authme", + "description": "Simple cross-platform two-factor (2FA) authenticator app for desktop.", + "start_url": "/", + "display": "standalone", + "background_color": "#000000", + "theme_color": "#000000", + "orientation": "portrait-primary", + "lang": "en-US", + "categories": ["utilities"], + "dir": "ltr", + "icons": [ + { + "src": "maskable_icon_x512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "maskable_icon_x512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "any" + }, + { + "src": "maskable_icon_x192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "maskable_icon_x192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "any" + } + ] +} diff --git a/website/static/maskable_icon_x192.png b/website/static/maskable_icon_x192.png new file mode 100644 index 00000000..0bc158b8 Binary files /dev/null and b/website/static/maskable_icon_x192.png differ diff --git a/website/static/maskable_icon_x512.png b/website/static/maskable_icon_x512.png new file mode 100644 index 00000000..fc2da1a9 Binary files /dev/null and b/website/static/maskable_icon_x512.png differ