package state
const (
CDNPath = "https://cdn.sonr.id"
)
var serviceWorkerHandle = templ.NewOnceHandle()
script RegisterServiceWorker() {
if ("serviceWorker" in navigator) {
window.addEventListener("load", function() {
navigator.serviceWorker
.register("/sw.js")
.then(function (registration) {
console.log("Service Worker registered with scope:", registration.scope);
})
.catch(function (error) {
console.log("Service Worker registration failed:", error);
});
});
}
}
templ ImportScripts() {
}
templ indexFile(cfg string) {
@importScripts()
Sonr DWN
Loading...
@ServiceWorkerHandle.Once() {
@initializeServiceWorker(cfg)
}
}
script initializeServiceWorker(config string) {
const serviceWorker = new ServiceWorker(JSON.parse(config));
async function demo() {
try {
// Insert a new account
const accountId = await serviceWorker.insertAccount({
name: 'John Doe',
address: '0x1234567890123456789012345678901234567890',
balance: 100,
});
console.log('Account created:', accountId);
// Get the account
const account = await serviceWorker.getAccount(accountId);
console.log('Account:', account);
}
catch (error) {
console.error('Error:', error);
}
}
}