Fix service worker

pull/7/head
Toni Melisma 3 years ago
parent c940d59a25
commit ea28f9425d
No known key found for this signature in database
GPG Key ID: FFF9A7EDDEA34756

@ -1,21 +1,22 @@
self.addEventListener('install', (event) => {
console.log("Service worker installed")
self.addEventListener("install", (event) => {
console.log("Service worker installed");
});
self.addEventListener('activate', (event) => {
console.log("Service worker activated")
self.addEventListener("activate", (event) => {
console.log("Service worker activated");
});
self.addEventListener('fetch', (event) => {
try {
return fetch(event.request)
} catch (error) {
return new Response(
"<h1>No network connection</h1>Retrying...<script>setTimeout(() => { window.location.reload(1); }, 5000);</script>",
{
headers: {
'Content-type': 'text/html'
self.addEventListener("fetch", (event) => {
if (event.request.mode === "navigate") {
event.respondWith(
(async () => {
try {
return await fetch(event.request);
} catch (error) {
return new Response("<h1>No network connection</h1>Retrying...<script>setTimeout(() => { window.location.reload(1); }, 5000);</script>",
{ status: 200, headers: { 'Content-type': 'text/html' } })
}
})
})()
);
}
});

@ -637,6 +637,8 @@ func copyFile(source string, destination string) {
}
*/
// TODO document function
// TODO icons without transparent backgrounds
func isIcon(iconPath string) bool {
re := regexp.MustCompile(`^icon`)
iconPath = filepath.Base(iconPath)
@ -877,6 +879,8 @@ func createHTML(depth int, source directory, galleryDirectory string, dryRun boo
log.Println("couldn't parse HTML template", templatePath, ":", err.Error())
exit(1)
}
// TODO apple-touch-icon to template
// TODO simplify service worker
htmlFileHandle, err := os.Create(htmlFilePath)
if err != nil {

Loading…
Cancel
Save