added installed as pwa checking

This commit is contained in:
Mamalizz
2025-03-06 23:48:50 +03:30
parent 191256b5be
commit a8e8da2e10
+11 -1
View File
@@ -7,9 +7,19 @@ export default defineNuxtPlugin(() => {
if ("serviceWorker" in navigator) {
wb = new Workbox("/sw.js");
const isStandalone = window.matchMedia(
"(display-mode: standalone)"
).matches;
const isIOSPWA = (window.navigator as any).standalone;
const isInstalledAsPWA = isStandalone || isIOSPWA;
// Listen for messages from the service worker
navigator.serviceWorker.addEventListener("message", (event) => {
if (event.data && event.data.type === "VERSION_CHECK") {
if (
event.data &&
event.data.type === "VERSION_CHECK" &&
isInstalledAsPWA
) {
checkForUpdate(event.data.version);
}
});