@jon49/sw 0.14.1 → 0.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,7 +20,7 @@ navigator.serviceWorker.addEventListener('controllerchange', function () {
20
20
  /// worker.postMessage("skipWaiting")
21
21
  /// }
22
22
  /// })
23
- export function notifier(fn: (state: "" | "waiting", worker: ServiceWorker) => void) {
23
+ function notifier(fn: (state: "" | "waiting", worker: ServiceWorker) => void) {
24
24
  let newWorker: ServiceWorker | undefined | null
25
25
 
26
26
  if ('serviceWorker' in navigator) {
@@ -49,3 +49,18 @@ export function notifier(fn: (state: "" | "waiting", worker: ServiceWorker) => v
49
49
  }
50
50
  }
51
51
 
52
+ notifier(notifyUserAboutNewVersion)
53
+
54
+ function notifyUserAboutNewVersion(state = "", worker: ServiceWorker) {
55
+ let nav = document.getElementById("sw-message")
56
+ nav?.insertAdjacentHTML("afterbegin", `<div class=inline><a traits=skip-waiting href="#">Click here to update your app.</a></div>`)
57
+ // @ts-ignore
58
+ window.app = window.app || {}
59
+ // @ts-ignore
60
+ window.app.sw = worker
61
+ if (state === "waiting") return
62
+ // Publish custom event for "user-messages" to display a toast.
63
+ document.dispatchEvent(new CustomEvent("user-messages", {
64
+ detail: { html: `A new version of the app is available. <a traits=skip-waiting href="#">Click to update the app.</a>` }
65
+ }))
66
+ }
@@ -51,11 +51,11 @@ export function useResponse(_: Request, res: any, __: any) : void {
51
51
  response: new Response(res.body, {
52
52
  status: res.status || 200,
53
53
  headers: {
54
- "content-type": res.type || "text/plain; charset=utf-8",
55
- ...res.headers,
54
+ "Content-Type": res.type || "text/plain; charset=utf-8",
56
55
  }
57
56
  })
58
57
  })
58
+ return
59
59
  }
60
60
 
61
61
  if (res.status) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jon49/sw",
3
- "version": "0.14.1",
3
+ "version": "0.14.3",
4
4
  "description": "Packages for MVC service workers.",
5
5
  "type": "module",
6
6
  "files": [