Skip to content

Commit

Permalink
Merge pull request #13 from ContentsViewer/feature/pwa
Browse files Browse the repository at this point in the history
Feature/pwa
  • Loading branch information
ContentsViewer authored Apr 23, 2024
2 parents ef6e780 + 621771b commit 17e8967
Show file tree
Hide file tree
Showing 14 changed files with 1,161 additions and 433 deletions.
28 changes: 14 additions & 14 deletions app/app-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ const ThemeChanger = () => {
// }));

export function AppLayout({ children }: { children: React.ReactNode }) {
useEffect(() => {
if ("serviceWorker" in navigator) {
window.addEventListener("load", () => {
navigator.serviceWorker
.register("./sw.js")
.then(registration => {
console.log("SW registered: ", registration)
})
.catch(registrationError => {
console.log("SW registration failed: ", registrationError)
})
})
}
}, [])
// useEffect(() => {
// if ("serviceWorker" in navigator) {
// window.addEventListener("load", () => {
// navigator.serviceWorker
// .register("./sw.js")
// .then(registration => {
// console.log("SW registered: ", registration)
// })
// .catch(registrationError => {
// console.log("SW registration failed: ", registrationError)
// })
// })
// }
// }, [])
const [playerCardExpanded, setPlayerCardExpanded] = useState<boolean>(false)

return (
Expand Down
File renamed without changes.
25 changes: 25 additions & 0 deletions app/sw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { defaultCache } from "@serwist/next/worker";
import type { PrecacheEntry, SerwistGlobalConfig } from "serwist";
import { Serwist } from "serwist";

// This declares the value of `injectionPoint` to TypeScript.
// `injectionPoint` is the string that will be replaced by the
// actual precache manifest. By default, this string is set to
// `"self.__SW_MANIFEST"`.
declare global {
interface WorkerGlobalScope extends SerwistGlobalConfig {
__SW_MANIFEST: (PrecacheEntry | string)[] | undefined;
}
}

declare const self: ServiceWorkerGlobalScope;

const serwist = new Serwist({
precacheEntries: self.__SW_MANIFEST,
skipWaiting: true,
clientsClaim: true,
navigationPreload: true,
runtimeCaching: defaultCache,
});

serwist.addEventListeners();
Loading

0 comments on commit 17e8967

Please sign in to comment.