Skip to content

Commit

Permalink
Add a service worker to help installability
Browse files Browse the repository at this point in the history
  • Loading branch information
ccouzens committed Apr 23, 2024
1 parent f76e345 commit d217f3c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions build-and-release.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cp \
public/icon-monochrome.svg \
public/icon.svg \
public/manifest.json \
public/sw.js \
build/

VERSION="$(git rev-parse HEAD)"
Expand Down
5 changes: 5 additions & 0 deletions public/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
addEventListener("fetch", (event) => {
const url = new URL(event.request.url);
console.log("fetch requested", url);
event.respondWith(fetch(url));
});
9 changes: 9 additions & 0 deletions src/game.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { initialiseApp } from "./game/app";

initialiseApp(window).catch((reason) => console.error(reason));

if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("sw.js").then(
(r) => console.log("Service worker registered", r),
(e) => console.log("Service worker failed to register", e),
);
} else {
console.log("Service worker not supported");
}

0 comments on commit d217f3c

Please sign in to comment.