feat: add PWA support with manifest and service worker
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 25 KiB |
+18
-1
@@ -1,6 +1,7 @@
|
||||
import type { Metadata } from "next";
|
||||
import type { Metadata, Viewport } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import "./globals.css";
|
||||
import { RegisterSW } from "./register-sw";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
@@ -15,6 +16,21 @@ const geistMono = Geist_Mono({
|
||||
export const metadata: Metadata = {
|
||||
title: "屏幕截图监控系统",
|
||||
description: "Windows更新监控系统",
|
||||
manifest: "/manifest.json",
|
||||
icons: [
|
||||
{
|
||||
rel: "icon",
|
||||
url: "/favicon.png",
|
||||
},
|
||||
{
|
||||
rel: "apple-touch-icon",
|
||||
url: "/favicon.png",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const viewport: Viewport = {
|
||||
themeColor: "#F9FAFB",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
@@ -27,6 +43,7 @@ export default function RootLayout({
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased bg-white dark:bg-gray-900 text-gray-900 dark:text-white`}
|
||||
>
|
||||
<RegisterSW />
|
||||
{children}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
|
||||
export function RegisterSW() {
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") return;
|
||||
if (!("serviceWorker" in navigator)) return;
|
||||
|
||||
const register = async () => {
|
||||
try {
|
||||
const swUrl = "/sw.js";
|
||||
await navigator.serviceWorker.register(swUrl);
|
||||
} catch (error) {
|
||||
console.error("Service worker registration failed", error);
|
||||
}
|
||||
};
|
||||
|
||||
register();
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user