diff --git a/cmd/fastgallery/assets/serviceWorker.js b/cmd/fastgallery/assets/serviceWorker.js index 0c56f64..908892b 100644 --- a/cmd/fastgallery/assets/serviceWorker.js +++ b/cmd/fastgallery/assets/serviceWorker.js @@ -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( - "

No network connection

Retrying...", - { - 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("

No network connection

Retrying...", + { status: 200, headers: { 'Content-type': 'text/html' } }) } - }) + })() + ); } }); \ No newline at end of file diff --git a/cmd/fastgallery/main.go b/cmd/fastgallery/main.go index 7832f7c..7720541 100644 --- a/cmd/fastgallery/main.go +++ b/cmd/fastgallery/main.go @@ -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 {