Skip to content

Commit

Permalink
Fix service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
tonimelisma committed Mar 20, 2021
1 parent c940d59 commit ea28f94
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
29 changes: 15 additions & 14 deletions 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(
"<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' } })
}
})
})()
);
}
});
4 changes: 4 additions & 0 deletions cmd/fastgallery/main.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ea28f94

Please sign in to comment.