mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 02:59:35 +00:00
feat: integrate Pi backend and Pi Web
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
|
||||
export function PwaRegistration() {
|
||||
useEffect(() => {
|
||||
if (process.env.NODE_ENV !== "production" || !("serviceWorker" in navigator)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const register = () => {
|
||||
const appVersion = process.env.NEXT_PUBLIC_APP_VERSION ?? "dev";
|
||||
const scriptUrl = `/sw.js?v=${encodeURIComponent(appVersion)}`;
|
||||
|
||||
void navigator.serviceWorker.register(scriptUrl, {
|
||||
scope: "/",
|
||||
updateViaCache: "none",
|
||||
}).catch((error: unknown) => {
|
||||
console.error("Failed to register the Pi Web service worker:", error);
|
||||
});
|
||||
};
|
||||
|
||||
if (document.readyState === "complete") {
|
||||
register();
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener("load", register, { once: true });
|
||||
return () => window.removeEventListener("load", register);
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user