@@ -3,11 +3,10 @@ import "@mui/material-pigment-css/styles.css";
33import Toolbar from "@mui/material/Toolbar" ;
44import Container from "@mui/material-pigment-css/Container" ;
55import type { User } from "@prisma/client" ;
6- import { ManifestLink } from "@remix-pwa/manifest" ;
7- import { installPWAGlobals } from "@remix-pwa/sw/install-pwa-globals" ;
86import { Fragment , type PropsWithChildren } from "react" ;
97import { Links , Meta , Outlet , Scripts , ScrollRestoration } from "react-router" ;
10- import { UAParser } from "ua-parser-js" ;
8+ import { pwaInfo } from "virtual:pwa-info" ;
9+ import { useRegisterSW } from "virtual:pwa-register/react" ;
1110import type { Route } from "./+types/root" ;
1211import { AlertProvider } from "./components/Alert" ;
1312import Navigation from "./components/Navigation" ;
@@ -27,11 +26,9 @@ export const handle: Handle<typeof loader> = {
2726} ;
2827
2928const prefetchedLinks = new Set < string > ( ) ;
30- function handlePrefetchLinksOnSafari ( head : HTMLHeadElement ) {
31- const parser = new UAParser ( ) ;
32- if ( ! parser . getBrowser ( ) . is ( "safari" ) ) return ;
33-
34- const links = head . querySelectorAll < HTMLLinkElement > ( `link[rel=prefetch]` ) ;
29+ function handlePrefetchLinks ( ) {
30+ const links =
31+ document . head . querySelectorAll < HTMLLinkElement > ( `link[rel=prefetch]` ) ;
3532 for ( const link of links ) {
3633 if ( prefetchedLinks . has ( link . href ) ) continue ;
3734 prefetchedLinks . add ( link . href ) ;
@@ -40,22 +37,28 @@ function handlePrefetchLinksOnSafari(head: HTMLHeadElement) {
4037}
4138
4239export function Layout ( { children } : PropsWithChildren ) {
43- installPWAGlobals ( ) ;
4440 const title = useTitle ( ) ;
4541 return (
4642 < html lang = "ja" >
47- < head
48- ref = { ( head ) => {
49- if ( head ) handlePrefetchLinksOnSafari ( head ) ;
50- } }
51- >
43+ < head >
5244 < meta charSet = "utf-8" />
5345 < meta name = "viewport" content = "width=device-width, initial-scale=1" />
46+ < meta name = "theme-color" content = "#1976d2" />
47+ < link rel = "manifest" href = { pwaInfo ?. webManifest . href } />
48+ { /* TODO: add icons
49+ <link rel="icon" href="/favicon.ico" />
50+ <link
51+ rel="apple-touch-icon"
52+ href="/apple-touch-icon.png"
53+ sizes="180x180"
54+ />
55+ <link rel="mask-icon" href="/mask-icon.svg" color="#FFFFFF" />
56+ */ }
5457 < meta name = "emotion-insertion-point" content = "" />
55- < ManifestLink href = "/manifest.webmanifest" />
5658 < Meta />
5759 < Links />
58- < title > { title } </ title >
60+ < title > { title ?? "Comiacapay" } </ title >
61+ < meta name = "description" content = "同人即売会用のレジアプリ" />
5962 </ head >
6063 < body >
6164 { children }
@@ -70,7 +73,12 @@ function AppLayout({
7073 children,
7174 user,
7275} : PropsWithChildren < { user : User | undefined } > ) {
73- installPWAGlobals ( ) ;
76+ useRegisterSW ( {
77+ onRegisteredSW ( ) {
78+ handlePrefetchLinks ( ) ;
79+ } ,
80+ } ) ;
81+
7482 const ButtomComponent = useHandleValue ( "ButtomComponent" , Fragment ) ;
7583 const maxWidth = useHandleValue ( "containerMaxWidth" , "lg" ) ;
7684
0 commit comments