Skip to content

Commit

Permalink
Service Worker
Browse files Browse the repository at this point in the history
  • Loading branch information
datajohnson committed May 30, 2024
1 parent 30e0c91 commit b7eeece
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
6 changes: 6 additions & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"markdown-it": "^14.0.0",
"moment": "^2.29.4",
"pinia": "^2.1.7",
"register-service-worker": "^1.7.2",
"vue": "^3.4.8",
"vue-router": "^4.2.5",
"vuetify": "^3.5.4"
Expand Down
2 changes: 2 additions & 0 deletions web/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { registerPlugins } from "./plugins";
import { Auth0Plugin } from "@auth0/auth0-vue";
import { Router } from "vue-router";

import "@/registerServiceWorker";

const pinia = createPinia();

import App from "./App.vue";
Expand Down
26 changes: 26 additions & 0 deletions web/src/registerServiceWorker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { register } from "register-service-worker";

register("/serviceWorker.js", {
registrationOptions: { scope: "./" },
ready(registration) {
console.log("Service worker is active.");
},
registered(registration) {
console.log("Service worker has been registered.");
},
cached(registration) {
console.log("Content has been cached for offline use.");
},
updatefound(registration) {
console.log("New content is downloading.");
},
updated(registration) {
console.log("New content is available; please refresh.");
},
offline() {
console.log("No internet connection found. App is running in offline mode.");
},
error(error) {
console.error("Error during service worker registration:", error);
},
});
19 changes: 19 additions & 0 deletions web/src/serviceWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable no-undef, no-restricted-globals */

// This is the code piece that GenerateSW mode can't provide for us.
// This code listens for the user's confirmation to update the app.
self.addEventListener('message', event => {
console.log(event);
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
});

console.log("Loading serviceWorker.js")

//workbox.clientsClaim();

// The precaching code provided by Workbox.
self.__precacheManifest = [].concat(self.__precacheManifest || []);
workbox.precaching.suppressWarnings();
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
2 changes: 1 addition & 1 deletion web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"@models": ["../api/src/data/models"]
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "src/serviceWorker.js"],
"references": [{ "path": "./tsconfig.node.json" }]
}

0 comments on commit b7eeece

Please sign in to comment.