Files
sonr/internal/files/sw.templ
T

33 lines
831 B
Templ
Raw Normal View History

2024-09-05 01:24:57 -04:00
package files
templ VaultServiceWorker(path string) {
@serviceWorkerJS(path)
}
script serviceWorkerJS(path string) {
importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.18.4/misc/wasm/wasm_exec.js')
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js')
}
templ IndexHTML() {
<html>
<head>
<title>Sonr ID</title>
<script>
navigator.serviceWorker.register('sw.js')
registerWasmHTTPListener(path)
// Skip installed stage and jump to activating stage
addEventListener('install', (event) => {
event.waitUntil(skipWaiting())
})
// Start controlling clients as soon as the SW is activated
addEventListener('activate', event => {
event.waitUntil(clients.claim())
})
</script>
</head>
</html>
}