init
This commit is contained in:
23
frontend/plugins/pwa.client.ts
Normal file
23
frontend/plugins/pwa.client.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
export default defineNuxtPlugin(async () => {
|
||||
const { setInstallPromptEvent, isNativeApp } = usePush();
|
||||
|
||||
if (isNativeApp()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ("serviceWorker" in navigator) {
|
||||
await navigator.serviceWorker.register("/sw.js");
|
||||
}
|
||||
|
||||
window.addEventListener("beforeinstallprompt", (event) => {
|
||||
event.preventDefault();
|
||||
setInstallPromptEvent(event as Event & {
|
||||
prompt: () => Promise<void>;
|
||||
userChoice: Promise<{ outcome: "accepted" | "dismissed"; platform: string }>;
|
||||
});
|
||||
});
|
||||
|
||||
window.addEventListener("appinstalled", () => {
|
||||
setInstallPromptEvent(null);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user