Add service worker and harden the web app manifest for Android 14+ / iOS 17+

Android (Samsung S23, One UI 6) refuses 'Install app' / standalone mode
when the origin is not secure or the app has no service worker. The ported
Next.js app shipped neither: only a manifest existed, and no sw.js at all.

- public/sw.js: navigation network-first with an offline fallback,
  cache-first for static assets, /api and /files bypassed, versioned
  cache with skipWaiting + clients.claim.
- public/offline.html: offline shell.
- src/components/PwaBoot.tsx: registers the worker, wires
  beforeinstallprompt into an in-app install button, and shows a
  share-sheet hint on iOS/Samsung Internet where the event never fires.
- ui-manifest.json: add id, display_override, prefer_related_applications,
  launch_handler, handle_links, a maskable icon for Android 14 and
  screenshots for the install preview.
- layout.tsx: viewport-fit=cover, interactive-widget, maximumScale 5
  (never user-scalable=no), appleWebApp metadata, format detection off,
  and drop manually duplicated meta tags that Next already emits.

Verified: manifest passes 8/8 installability checks, sw.js and offline.html
serve with correct content types, tsc clean, npm run build passes.
This commit is contained in:
Bkk1234 committed 2026-10-23 22:40:58 +07:00
1 parent 3519f92669
commit 092f551b7d
7 files changed
+405 -11

No files matched your search

+25 -5
View File
@@ -1,5 +1,6 @@
import type { Metadata, Viewport } from "next";
import IconSprite from "@/components/IconSprite";
import PwaBoot from "@/components/PwaBoot";
import SiteBoot from "@/components/SiteBoot";
import SiteFooter from "@/components/SiteFooter";
import SiteHeader from "@/components/SiteHeader";
@@ -19,12 +20,31 @@ export const metadata: Metadata = {
},
description:
"ศูนย์รวมข้อมูลตารางเดินรถ จุดจอด และเส้นทางในจังหวัดอ่างทองและจังหวัดใกล้เคียง",
applicationName: "Atroute",
manifest: "/ui-manifest.json",
icons: { icon: "/image/icons/minibus-512x512.png" },
icons: {
icon: [
{ url: "/image/icons/minibus-512x512.png", sizes: "512x512", type: "image/png" },
{ url: "/image/icons/minibus-192x192.png", sizes: "192x192", type: "image/png" },
],
apple: [{ url: "/image/icons/minibus-192x192.png", sizes: "192x192", type: "image/png" }],
},
appleWebApp: {
capable: true,
title: "Atroute",
statusBarStyle: "default",
},
formatDetection: { telephone: false, address: false, email: false },
};
export const viewport: Viewport = {
themeColor: "#7a4cc0",
width: "device-width",
initialScale: 1,
// ห้าม maximumScale:1 / userScalable:false — ปิดการซูมจะไม่ผ่าน WCAG 1.4.4
maximumScale: 5,
viewportFit: "cover",
interactiveWidget: "resizes-content",
};
export default function RootLayout({ children }: { children: React.ReactNode }) {
@@ -38,10 +58,9 @@ export default function RootLayout({ children }: { children: React.ReactNode })
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;500;600;700;800&family=Prompt:wght@400;500;600;700&display=swap"
/>
<meta name="theme-color" content="#7a4cc0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<link rel="apple-touch-icon" href="/image/icons/minibus-192x192.png" />
{/* theme-color / apple-touch-icon / apple-mobile-web-app-* / mobile-web-app-capable
ถูก emit อัตโนมัติจาก metadata.appleWebApp + metadata.icons + viewport.themeColor
— อย่าใส่ซ้ำที่นี่ (จะได้ meta ซ้ำ 2 ชุด) */}
<script src="/vendor/leaflet/leaflet.js" defer />
</head>
<body className="main-theme-page">
@@ -50,6 +69,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
<div id="view">{children}</div>
<SiteFooter />
<SiteBoot />
<PwaBoot />
</body>
</html>
);