diff --git a/.vscode/settings.json b/.vscode/settings.json
index ac85747..91e6151 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -17,7 +17,12 @@
"explorer.fileNesting.patterns": {
"*.tsx": "${capture}.*"
},
- "cSpell.words": ["technoshop", "Technoshop", "univoq"],
+ "cSpell.words": [
+ "startserviceworker",
+ "technoshop",
+ "Technoshop",
+ "univoq"
+ ],
"cssvar.enable": true,
"cssvar.files": ["./_fresh/*"],
"conventionalCommits.scopes": ["css", "config", "ui", "pwa"],
diff --git a/components/ProgressiveWebApp.tsx b/components/ProgressiveWebApp.tsx
new file mode 100644
index 0000000..11acdae
--- /dev/null
+++ b/components/ProgressiveWebApp.tsx
@@ -0,0 +1,5 @@
+import RegisterServiceWorker from '../islands/RegisterServiceWorker.tsx'
+
+export function ProgressiveWebApp() {
+ return
+}
diff --git a/islands/RegisterServiceWorker.tsx b/islands/RegisterServiceWorker.tsx
index 1b33b4b..04de658 100644
--- a/islands/RegisterServiceWorker.tsx
+++ b/islands/RegisterServiceWorker.tsx
@@ -1,6 +1,9 @@
-export default function RegisterServiceWorker({ href }: { href: string }) {
+export default function RegisterServiceWorker() {
if ('serviceWorker' in navigator) {
- navigator.serviceWorker.register(href)
+ import('./StartServiceWorker.tsx').then((mod) => {
+ const href = mod.default()
+ navigator.serviceWorker.register(href, { scope: '/', type: 'module' })
+ })
}
return <>>
diff --git a/islands/StartServiceWorker.tsx b/islands/StartServiceWorker.tsx
new file mode 100644
index 0000000..1788cd1
--- /dev/null
+++ b/islands/StartServiceWorker.tsx
@@ -0,0 +1,10 @@
+import { main } from '../src/serviceworker/mod.ts'
+
+const IS_SW = 'onpushsubscriptionchange' in self
+
+export default function StartServiceWorker() {
+ if (IS_SW) {
+ main()
+ }
+ return new URL(import.meta.url).pathname
+}
diff --git a/routes/_app.tsx b/routes/_app.tsx
index 1636341..7a27d7b 100644
--- a/routes/_app.tsx
+++ b/routes/_app.tsx
@@ -2,7 +2,7 @@ import { asset, Head, Partial } from '$fresh/runtime.ts'
import { type PageProps } from '$fresh/server.ts'
import { Footer } from '../components/Footer.tsx'
import { Header } from '../components/Header.tsx'
-import RegisterServiceWorker from '../islands/RegisterServiceWorker.tsx'
+import { ProgressiveWebApp } from '../components/ProgressiveWebApp.tsx'
export default function App({ Component }: PageProps) {
return (
@@ -53,7 +53,7 @@ export default function App({ Component }: PageProps) {
-
+