From 319a10b9a106e768ea2d3fb6d7134817911208ce Mon Sep 17 00:00:00 2001
From: Matt Strapp <matt@mattstrapp.net>
Date: Wed, 13 Sep 2023 16:04:12 -0500
Subject: Add basic PWA support

TODO: draw the rest of the owl
---
 app/src/routes/+layout.svelte | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

(limited to 'app/src/routes/+layout.svelte')

diff --git a/app/src/routes/+layout.svelte b/app/src/routes/+layout.svelte
index 3d5c07f..93a41b1 100644
--- a/app/src/routes/+layout.svelte
+++ b/app/src/routes/+layout.svelte
@@ -1,4 +1,8 @@
 <script lang="ts">
+	import { registerSW } from 'virtual:pwa-register'
+	import { pwaInfo } from 'virtual:pwa-info'; 
+	import { onMount } from 'svelte'
+
 	import '../app.postcss';
 	import { AppShell, AppBar } from '@skeletonlabs/skeleton';
 
@@ -6,8 +10,31 @@
 	import { computePosition, autoUpdate, flip, shift, offset, arrow } from '@floating-ui/dom';
 	import { storePopup } from '@skeletonlabs/skeleton';
 	storePopup.set({ computePosition, autoUpdate, flip, shift, offset, arrow });
+
+	onMount(async () => {
+    if (pwaInfo) {
+      registerSW({
+        immediate: true,
+        onRegistered(r) {
+          console.log(`SW Registered: ${r}`)
+        },
+        onRegisterError(error) {
+          console.log('SW registration error', error)
+        },
+		onOfflineReady() {
+			console.log('SW Offline Ready')
+		}
+      })
+    }
+  })
+  	
+	$: webManifestLink = pwaInfo ? pwaInfo.webManifest.linkTag : '' 
 </script>
 
+<svelte:head> 
+ 	{@html webManifestLink} 
+</svelte:head>
+
 <!-- App Shell -->
 <AppShell>
 	<svelte:fragment slot="header">
-- 
cgit v1.2.3

