@@ -1643,7 +1643,7 @@ <h2 id="pkg-constants">Constants</h2>
16431643
16441644 <pre>const (
16451645 <span class="comment">// The default template used to generate app-worker.js.</span>
1646- <span id="DefaultAppWorkerJS">DefaultAppWorkerJS</span> = "// -----------------------------------------------------------------------------\n// PWA\n// -----------------------------------------------------------------------------\nconst cacheName = \"app-\" + \"{{.Version}}\";\nconst resourcesToCache = {{.ResourcesToCache}};\n\nself.addEventListener(\"install\", async (event) => {\n try {\n console.log(\"installing app worker {{.Version}}\");\n await installWorker();\n await self.skipWaiting();\n } catch (error) {\n console.error(\"error during installation:\", error);\n }\n});\n\nasync function installWorker() {\n const cache = await caches.open(cacheName);\n await cache.addAll(resourcesToCache);\n}\n\nself.addEventListener(\"activate\", async (event) => {\n try {\n await deletePreviousCaches(); // Await cache cleanup\n await self.clients.claim(); // Ensure the service worker takes control of the clients\n console.log(\"app worker {{.Version}} is activated\");\n } catch (error) {\n console.error(\"error during activation:\", error);\n }\n});\n\nasync function deletePreviousCaches() {\n const keys = await caches.keys();\n await Promise.all(\n keys.map(async (key) => {\n if (key !== cacheName) {\n try {\n console.log(\"deleting\", key, \"cache\");\n await caches.delete(key);\n } catch (err) {\n console.error(\"deleting\", key, \"cache failed:\", err);\n }\n }\n })\n );\n}\n\nself.addEventListener(\"fetch\", (event) => {\n event.respondWith(fetchWithCache(event.request));\n});\n\nasync function fetchWithCache(request) {\n const cachedResponse = await caches.match(request);\n if (cachedResponse) {\n return cachedResponse;\n }\n return await fetch(request);\n}\n\n// -----------------------------------------------------------------------------\n// Push Notifications\n// -----------------------------------------------------------------------------\nself.addEventListener(\"push\", (event) => {\n if (!event.data || !event.data.text()) {\n return;\n }\n\n const notification = JSON.parse(event.data.text());\n if (!notification) {\n return;\n }\n\n event.waitUntil(\n showNotification(self.registration, notification)\n );\n});\n\nself.addEventListener(\"message\", (event) => {\n const msg = event.data;\n if (!msg || msg.type !== \"goapp:notify\") {\n return;\n }\n\n event.waitUntil(\n showNotification(self.registration, msg.options)\n );\n});\n\nasync function showNotification(registration, notification) {\n const title = notification.title || \"\";\n let delay = notification.delay || 0;\n\n let actions = [];\n for (let i in notification.actions) {\n const action = notification.actions[i];\n actions.push({\n action: action.action,\n path: action.path,\n });\n delete action.path;\n }\n\n notification.data = notification.data || {};\n notification.data.goapp = {\n path: notification.path,\n actions: actions,\n };\n delete notification.title;\n delete notification.path;\n delete notification.delay;\n\n if (delay > 0) {\n delay = Math.floor(delay / 1e6);\n await sleep(delay);\n }\n await registration.showNotification(title, notification);\n}\n\nfunction sleep(ms) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nself.addEventListener(\"notificationclick\", (event) => {\n event.notification.close();\n\n const notification = event.notification;\n let path = notification.data.goapp.path;\n\n for (let i in notification.data.goapp.actions) {\n const action = notification.data.goapp.actions[i];\n if (action.action === event.action) {\n path = action.path;\n break;\n }\n }\n\n event.waitUntil(\n clients\n .matchAll({\n type: \"window\",\n })\n .then((clientList) => {\n for (var i = 0; i < clientList.length; i++) {\n let client = clientList[i];\n if (\"focus\" in client) {\n client.focus();\n client.postMessage({\n goapp: {\n type: \"notification\",\n path: path,\n },\n });\n return;\n }\n }\n\n if (clients.openWindow) {\n return clients.openWindow(path);\n }\n })\n );\n});"
1646+ <span id="DefaultAppWorkerJS">DefaultAppWorkerJS</span> = "// -----------------------------------------------------------------------------\n// PWA\n// -----------------------------------------------------------------------------\nconst cacheName = \"app-\" + \"{{.Version}}\";\nconst resourcesToCache = {{.ResourcesToCache}};\n\nself.addEventListener(\"install\", async (event) => {\n try {\n console.log(\"installing app worker {{.Version}}\");\n await installWorker();\n await self.skipWaiting();\n } catch (error) {\n console.error(\"error during installation:\", error);\n }\n});\n\nasync function installWorker() {\n const cache = await caches.open(cacheName);\n await cache.addAll(resourcesToCache);\n}\n\nself.addEventListener(\"activate\", async (event) => {\n try {\n await deletePreviousCaches(); // Await cache cleanup\n await self.clients.claim(); // Ensure the service worker takes control of the clients\n console.log(\"app worker {{.Version}} is activated\");\n } catch (error) {\n console.error(\"error during activation:\", error);\n }\n});\n\nasync function deletePreviousCaches() {\n const keys = await caches.keys();\n await Promise.all(\n keys.map(async (key) => {\n if (key !== cacheName) {\n try {\n console.log(\"deleting\", key, \"cache\");\n await caches.delete(key);\n } catch (err) {\n console.error(\"deleting\", key, \"cache failed:\", err);\n }\n }\n })\n );\n}\n\nself.addEventListener(\"fetch\", (event) => {\n event.respondWith(fetchWithCache(event.request));\n});\n\nasync function fetchWithCache(request) {\n const cachedResponse = await caches.match(request);\n if (cachedResponse) {\n return cachedResponse;\n }\n return await fetch(request);\n}\n\n// -----------------------------------------------------------------------------\n// Push Notifications\n// -----------------------------------------------------------------------------\nself.addEventListener(\"push\", (event) => {\n if (!event.data || !event.data.text()) {\n return;\n }\n\n const notification = JSON.parse(event.data.text());\n if (!notification) {\n return;\n }\n\n event.waitUntil(\n showNotification(self.registration, notification)\n );\n});\n\nself.addEventListener(\"message\", (event) => {\n const msg = event.data;\n if (!msg || msg.type !== \"goapp:notify\") {\n return;\n }\n\n event.waitUntil(\n showNotification(self.registration, msg.options)\n );\n});\n\nasync function showNotification(registration, notification) {\n const title = notification.title || \"\";\n\n let actions = [];\n for (let i in notification.actions) {\n const action = notification.actions[i];\n actions.push({\n action: action.action,\n path: action.path,\n });\n delete action.path;\n }\n\n notification.data = notification.data || {};\n notification.data.goapp = {\n path: notification.path,\n actions: actions,\n };\n delete notification.title;\n delete notification.path;\n\n await registration.showNotification(title, notification);\n}\n\nfunction sleep(ms) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nself.addEventListener(\"notificationclick\", (event) => {\n event.notification.close();\n\n const notification = event.notification;\n let path = notification.data.goapp.path;\n\n for (let i in notification.data.goapp.actions) {\n const action = notification.data.goapp.actions[i];\n if (action.action === event.action) {\n path = action.path;\n break;\n }\n }\n\n event.waitUntil(\n clients\n .matchAll({\n type: \"window\",\n })\n .then((clientList) => {\n for (var i = 0; i < clientList.length; i++) {\n let client = clientList[i];\n if (\"focus\" in client) {\n client.focus();\n client.postMessage({\n goapp: {\n type: \"notification\",\n path: path,\n },\n });\n return;\n }\n }\n\n if (clients.openWindow) {\n return clients.openWindow(path);\n }\n })\n );\n});"
16471647)</pre>
16481648
16491649
@@ -26221,7 +26221,7 @@ <h2 id="Navigator">type <a href="/src/github.com/maxence-charriere/go-app/v10/pk
2622126221
2622226222
2622326223
26224- <h2 id="Notification">type <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=153:2377 #L1">Notification</a>
26224+ <h2 id="Notification">type <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=145:2047 #L1">Notification</a>
2622526225 <a class="permalink" href="#Notification">¶</a>
2622626226
2622726227
@@ -26275,13 +26275,6 @@ <h2 id="Notification">type <a href="/src/github.com/maxence-charriere/go-app/v10
2627526275 <span class="comment">// See: https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API</span>
2627626276 Vibrate []<a href="/pkg/builtin/#int">int</a> `json:"vibrate,omitempty"`
2627726277
26278- <span id="Notification.Delay"></span> <span class="comment">// Delay specifies how long to wait before displaying the notification.</span>
26279- <span class="comment">//</span>
26280- <span class="comment">// The duration is serialized as a Go time.Duration and interpreted</span>
26281- <span class="comment">// client-side. Actual delivery time is best-effort and may be delayed</span>
26282- <span class="comment">// further depending on browser and system constraints.</span>
26283- Delay <a href="/pkg/time/">time</a>.<a href="/pkg/time/#Duration">Duration</a> `json:"delay,omitempty"`
26284-
2628526278<span id="Notification.Actions"></span> <span class="comment">// Actions lists the available actions displayed within the notification.</span>
2628626279 Actions []<a href="#NotificationAction">NotificationAction</a> `json:"actions,omitempty"`
2628726280}
@@ -26301,7 +26294,7 @@ <h2 id="Notification">type <a href="/src/github.com/maxence-charriere/go-app/v10
2630126294
2630226295
2630326296
26304- <h2 id="NotificationAction">type <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=2454:2882#L60 ">NotificationAction</a>
26297+ <h2 id="NotificationAction">type <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=2124:2552#L52 ">NotificationAction</a>
2630526298 <a class="permalink" href="#NotificationAction">¶</a>
2630626299
2630726300
@@ -26338,7 +26331,7 @@ <h2 id="NotificationAction">type <a href="/src/github.com/maxence-charriere/go-a
2633826331
2633926332
2634026333
26341- <h2 id="NotificationPermission">type <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=3464:3498#L93 ">NotificationPermission</a>
26334+ <h2 id="NotificationPermission">type <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=3134:3168#L85 ">NotificationPermission</a>
2634226335 <a class="permalink" href="#NotificationPermission">¶</a>
2634326336
2634426337
@@ -26379,7 +26372,7 @@ <h2 id="NotificationPermission">type <a href="/src/github.com/maxence-charriere/
2637926372
2638026373
2638126374
26382- <h2 id="NotificationService">type <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=4180:4213#L112 ">NotificationService</a>
26375+ <h2 id="NotificationService">type <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=3850:3883#L104 ">NotificationService</a>
2638326376 <a class="permalink" href="#NotificationService">¶</a>
2638426377
2638526378
@@ -26401,7 +26394,7 @@ <h2 id="NotificationService">type <a href="/src/github.com/maxence-charriere/go-
2640126394
2640226395
2640326396
26404- <h3 id="NotificationService.New">func (NotificationService) <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=5063:5111#L142 ">New</a>
26397+ <h3 id="NotificationService.New">func (NotificationService) <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=4733:4781#L134 ">New</a>
2640526398 <a class="permalink" href="#NotificationService.New">¶</a>
2640626399
2640726400
@@ -26414,7 +26407,7 @@ <h3 id="NotificationService.New">func (NotificationService) <a href="/src/github
2641426407
2641526408
2641626409
26417- <h3 id="NotificationService.Permission">func (NotificationService) <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=4283:4347#L115 ">Permission</a>
26410+ <h3 id="NotificationService.Permission">func (NotificationService) <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=3953:4017#L107 ">Permission</a>
2641826411 <a class="permalink" href="#NotificationService.Permission">¶</a>
2641926412
2642026413
@@ -26427,7 +26420,7 @@ <h3 id="NotificationService.Permission">func (NotificationService) <a href="/src
2642726420
2642826421
2642926422
26430- <h3 id="NotificationService.RequestPermission">func (NotificationService) <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=4617:4688#L125 ">RequestPermission</a>
26423+ <h3 id="NotificationService.RequestPermission">func (NotificationService) <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=4287:4358#L117 ">RequestPermission</a>
2643126424 <a class="permalink" href="#NotificationService.RequestPermission">¶</a>
2643226425
2643326426
@@ -26440,7 +26433,7 @@ <h3 id="NotificationService.RequestPermission">func (NotificationService) <a hre
2644026433
2644126434
2644226435
26443- <h3 id="NotificationService.Subscribe">func (NotificationService) <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=5390:5485#L150 ">Subscribe</a>
26436+ <h3 id="NotificationService.Subscribe">func (NotificationService) <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=5060:5155#L142 ">Subscribe</a>
2644426437 <a class="permalink" href="#NotificationService.Subscribe">¶</a>
2644526438
2644626439
@@ -26457,7 +26450,7 @@ <h3 id="NotificationService.Subscribe">func (NotificationService) <a href="/src/
2645726450
2645826451
2645926452
26460- <h2 id="NotificationSubscription">type <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=2963:3365#L76 ">NotificationSubscription</a>
26453+ <h2 id="NotificationSubscription">type <a href="/src/github.com/maxence-charriere/go-app/v10/pkg/app/notification.go?s=2633:3035#L68 ">NotificationSubscription</a>
2646126454 <a class="permalink" href="#NotificationSubscription">¶</a>
2646226455
2646326456
0 commit comments