Remove not neccecarly pwa sw configs and codes
This commit is contained in:
@@ -18,12 +18,6 @@ useSeoMeta({
|
|||||||
width: "device-width",
|
width: "device-width",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { $updateAvailable: updateAvailable, $handleUpdate: handleUpdate } = useNuxtApp();
|
|
||||||
|
|
||||||
const closeModal = () => {
|
|
||||||
updateAvailable.value = false;
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -32,12 +26,6 @@ const closeModal = () => {
|
|||||||
|
|
||||||
<NuxtPwaManifest />
|
<NuxtPwaManifest />
|
||||||
|
|
||||||
<UpdatePwaModal
|
|
||||||
:isShow="updateAvailable"
|
|
||||||
@update="handleUpdate"
|
|
||||||
@close="closeModal"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<NuxtLayout>
|
<NuxtLayout>
|
||||||
<NuxtPage />
|
<NuxtPage />
|
||||||
</NuxtLayout>
|
</NuxtLayout>
|
||||||
|
|||||||
+30
-31
@@ -5,54 +5,53 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "nuxt-app",
|
"name": "nuxt-app",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@formkit/auto-animate": "^0.8.2",
|
"@formkit/auto-animate": "^0.8.4",
|
||||||
"@nuxt/icon": "^1.10.3",
|
"@nuxt/icon": "^1.15.0",
|
||||||
"@nuxt/image": "^1.10.0",
|
"@nuxt/image": "^1.11.0",
|
||||||
"@nuxtjs/google-fonts": "^3.2.0",
|
"@nuxtjs/google-fonts": "^3.2.0",
|
||||||
"@nuxtjs/seo": "^3.0.3",
|
"@nuxtjs/seo": "^3.4.0",
|
||||||
"@tanstack/vue-query": "^5.62.2",
|
"@tanstack/vue-query": "^5.100.8",
|
||||||
"@tanstack/vue-query-devtools": "^5.62.3",
|
"@tanstack/vue-query-devtools": "^5.91.0",
|
||||||
"@vite-pwa/nuxt": "^0.10.6",
|
"@vite-pwa/nuxt": "^0.10.8",
|
||||||
"@vue/language-server": "^2.2.8",
|
"@vue/language-server": "^2.2.12",
|
||||||
"@vuelidate/core": "^2.0.3",
|
"@vuelidate/core": "^2.0.3",
|
||||||
"@vuelidate/validators": "^2.0.4",
|
"@vuelidate/validators": "^2.0.4",
|
||||||
"@vueuse/integrations": "^12.7.0",
|
"@vueuse/integrations": "^12.8.2",
|
||||||
"@vueuse/nuxt": "^13.3.0",
|
"@vueuse/nuxt": "^13.9.0",
|
||||||
"@vueuse/router": "^13.9.0",
|
"@vueuse/router": "^13.9.0",
|
||||||
"animate.css": "^4.1.1",
|
"animate.css": "^4.1.1",
|
||||||
"axios": "^1.8.1",
|
"axios": "^1.15.2",
|
||||||
"baseline-browser-mapping": "^2.10.22",
|
"baseline-browser-mapping": "^2.10.25",
|
||||||
"caniuse-lite": "^1.0.30001791",
|
"caniuse-lite": "^1.0.30001791",
|
||||||
"date-fns-jalali": "^4.1.0-0",
|
"date-fns-jalali": "^4.1.0-0",
|
||||||
"fast-average-color": "^9.4.0",
|
"fast-average-color": "^9.5.2",
|
||||||
"gsap": "^3.12.7",
|
"gsap": "^3.15.0",
|
||||||
"jalali-ts": "^8.0.0",
|
"jalali-ts": "^8.0.0",
|
||||||
"motion-v": "^1.1.1",
|
"motion-v": "^1.10.3",
|
||||||
"nuxt": "^3.21.4",
|
"nuxt": "^3.21.4",
|
||||||
"ogl": "^1.0.11",
|
"ogl": "^1.0.11",
|
||||||
"reka-ui": "^1.0.0-alpha.6",
|
"reka-ui": "^1.0.0-alpha.11",
|
||||||
"sanitize-html": "^2.15.0",
|
"sanitize-html": "^2.17.3",
|
||||||
"swiper": "^11.2.6",
|
"swiper": "^11.2.10",
|
||||||
"universal-cookie": "^7.2.2",
|
"universal-cookie": "^7.2.2",
|
||||||
"vue": "^3.5.12",
|
"vue": "^3.5.33",
|
||||||
"vue-image-zoomer": "^2.4.4",
|
"vue-image-zoomer": "^2.4.4",
|
||||||
"vue-router": "latest",
|
"vue-router": "latest",
|
||||||
"vue-skeletor": "^1.0.6",
|
"vue-skeletor": "^1.0.6",
|
||||||
"vue3-marquee": "^4.2.2",
|
"vue3-marquee": "^4.2.2",
|
||||||
"vue3-persian-datetime-picker": "^1.2.2",
|
"vue3-persian-datetime-picker": "^1.2.2",
|
||||||
"web-push": "^3.6.7",
|
"web-push": "^3.6.7",
|
||||||
"workbox-window": "^7.3.0",
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/postcss": "^4.1.4",
|
"@tailwindcss/postcss": "^4.2.4",
|
||||||
"@types/node": "^22.13.11",
|
"@types/node": "^22.19.17",
|
||||||
"@types/sanitize-html": "^2.13.0",
|
"@types/sanitize-html": "^2.16.1",
|
||||||
"@types/web-push": "^3.6.4",
|
"@types/web-push": "^3.6.4",
|
||||||
"autoprefixer": "^10.4.20",
|
"autoprefixer": "^10.5.0",
|
||||||
"postcss": "^8.5.3",
|
"postcss": "^8.5.13",
|
||||||
"tailwindcss": "^4.1.4",
|
"tailwindcss": "^4.2.4",
|
||||||
"typescript": "^5.8.2",
|
"typescript": "^5.9.3",
|
||||||
"vue-tsc": "^2.2.8",
|
"vue-tsc": "^2.2.12",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1659,7 +1658,7 @@
|
|||||||
|
|
||||||
"node-abi": ["node-abi@3.90.0", "", { "dependencies": { "semver": "^7.3.5" } }, "sha512-pZNQT7UnYlMwMBy5N1lV5X/YLTbZM5ncytN3xL7CHEzhDN8uVe0u55yaPUJICIJjaCW8NrM5BFdqr7HLweStNA=="],
|
"node-abi": ["node-abi@3.90.0", "", { "dependencies": { "semver": "^7.3.5" } }, "sha512-pZNQT7UnYlMwMBy5N1lV5X/YLTbZM5ncytN3xL7CHEzhDN8uVe0u55yaPUJICIJjaCW8NrM5BFdqr7HLweStNA=="],
|
||||||
|
|
||||||
"node-addon-api": ["node-addon-api@6.1.0", "", {}, "sha512-+eawOlIgy680F0kBzPUNFhMZGtJ1YmqM6l4+Crf4IkImjYrO/mqPwRMh352g23uIaQKFItcQ64I7KMaJxHgAVA=="],
|
"node-addon-api": ["node-addon-api@7.1.1", "", {}, "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ=="],
|
||||||
|
|
||||||
"node-fetch": ["node-fetch@2.7.0", "", { "dependencies": { "whatwg-url": "^5.0.0" }, "peerDependencies": { "encoding": "^0.1.0" }, "optionalPeers": ["encoding"] }, "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A=="],
|
"node-fetch": ["node-fetch@2.7.0", "", { "dependencies": { "whatwg-url": "^5.0.0" }, "peerDependencies": { "encoding": "^0.1.0" }, "optionalPeers": ["encoding"] }, "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A=="],
|
||||||
|
|
||||||
@@ -2395,8 +2394,6 @@
|
|||||||
|
|
||||||
"@nuxtjs/sitemap/@nuxt/kit": ["@nuxt/kit@4.4.4", "", { "dependencies": { "c12": "^3.3.4", "consola": "^3.4.2", "defu": "^6.1.7", "destr": "^2.0.5", "errx": "^0.1.0", "exsolve": "^1.0.8", "ignore": "^7.0.5", "jiti": "^2.6.1", "klona": "^2.0.6", "mlly": "^1.8.2", "ohash": "^2.0.11", "pathe": "^2.0.3", "pkg-types": "^2.3.1", "rc9": "^3.0.1", "scule": "^1.3.0", "semver": "^7.7.4", "tinyglobby": "^0.2.16", "ufo": "^1.6.4", "unctx": "^2.5.0", "untyped": "^2.0.0" } }, "sha512-oy4fAeMkyz7gelnalDQLPm8QZRN+c5c/Eh/M6oFgPx86jnA8m6xeOlONpJN2dk0GhcJwJYuN/kmzBffZ93WXPQ=="],
|
"@nuxtjs/sitemap/@nuxt/kit": ["@nuxt/kit@4.4.4", "", { "dependencies": { "c12": "^3.3.4", "consola": "^3.4.2", "defu": "^6.1.7", "destr": "^2.0.5", "errx": "^0.1.0", "exsolve": "^1.0.8", "ignore": "^7.0.5", "jiti": "^2.6.1", "klona": "^2.0.6", "mlly": "^1.8.2", "ohash": "^2.0.11", "pathe": "^2.0.3", "pkg-types": "^2.3.1", "rc9": "^3.0.1", "scule": "^1.3.0", "semver": "^7.7.4", "tinyglobby": "^0.2.16", "ufo": "^1.6.4", "unctx": "^2.5.0", "untyped": "^2.0.0" } }, "sha512-oy4fAeMkyz7gelnalDQLPm8QZRN+c5c/Eh/M6oFgPx86jnA8m6xeOlONpJN2dk0GhcJwJYuN/kmzBffZ93WXPQ=="],
|
||||||
|
|
||||||
"@parcel/watcher/node-addon-api": ["node-addon-api@7.1.1", "", {}, "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ=="],
|
|
||||||
|
|
||||||
"@parcel/watcher-wasm/napi-wasm": ["napi-wasm@1.1.3", "", { "bundled": true }, "sha512-h/4nMGsHjZDCYmQVNODIrYACVJ+I9KItbG+0si6W/jSjdA9JbWDoU4LLeMXVcEQGHjttI2tuXqDrbGF7qkUHHg=="],
|
"@parcel/watcher-wasm/napi-wasm": ["napi-wasm@1.1.3", "", { "bundled": true }, "sha512-h/4nMGsHjZDCYmQVNODIrYACVJ+I9KItbG+0si6W/jSjdA9JbWDoU4LLeMXVcEQGHjttI2tuXqDrbGF7qkUHHg=="],
|
||||||
|
|
||||||
"@rollup/plugin-babel/@rollup/pluginutils": ["@rollup/pluginutils@3.1.0", "", { "dependencies": { "@types/estree": "0.0.39", "estree-walker": "^1.0.1", "picomatch": "^2.2.2" }, "peerDependencies": { "rollup": "^1.20.0||^2.0.0" } }, "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg=="],
|
"@rollup/plugin-babel/@rollup/pluginutils": ["@rollup/pluginutils@3.1.0", "", { "dependencies": { "@types/estree": "0.0.39", "estree-walker": "^1.0.1", "picomatch": "^2.2.2" }, "peerDependencies": { "rollup": "^1.20.0||^2.0.0" } }, "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg=="],
|
||||||
@@ -2573,6 +2570,8 @@
|
|||||||
|
|
||||||
"send/mime-types": ["mime-types@3.0.2", "", { "dependencies": { "mime-db": "^1.54.0" } }, "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A=="],
|
"send/mime-types": ["mime-types@3.0.2", "", { "dependencies": { "mime-db": "^1.54.0" } }, "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A=="],
|
||||||
|
|
||||||
|
"sharp/node-addon-api": ["node-addon-api@6.1.0", "", {}, "sha512-+eawOlIgy680F0kBzPUNFhMZGtJ1YmqM6l4+Crf4IkImjYrO/mqPwRMh352g23uIaQKFItcQ64I7KMaJxHgAVA=="],
|
||||||
|
|
||||||
"source-map-support/source-map": ["source-map@0.6.1", "", {}, "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="],
|
"source-map-support/source-map": ["source-map@0.6.1", "", {}, "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="],
|
||||||
|
|
||||||
"string-width-cjs/emoji-regex": ["emoji-regex@8.0.0", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="],
|
"string-width-cjs/emoji-regex": ["emoji-regex@8.0.0", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="],
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
// types
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
isShow: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
type Emits = {
|
|
||||||
update: [value: any];
|
|
||||||
"update:isShow": [value: boolean];
|
|
||||||
};
|
|
||||||
|
|
||||||
// props
|
|
||||||
|
|
||||||
const props = defineProps<Props>();
|
|
||||||
|
|
||||||
const { isShow } = toRefs(props);
|
|
||||||
|
|
||||||
// emits
|
|
||||||
|
|
||||||
const emit = defineEmits<Emits>();
|
|
||||||
|
|
||||||
// computed
|
|
||||||
|
|
||||||
const visible = computed({
|
|
||||||
get: () => isShow.value ?? false,
|
|
||||||
set: (value: boolean) => emit("update:isShow", value),
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<Modal
|
|
||||||
v-model="visible"
|
|
||||||
title="ورژن جدید"
|
|
||||||
contectClass="!w-[90vw] lg:!w-[35vw]"
|
|
||||||
@close="visible = false"
|
|
||||||
>
|
|
||||||
<template #content>
|
|
||||||
<div class="w-full flex flex-col text-start gap-3 py-5" dir="rtl">
|
|
||||||
<p>
|
|
||||||
نسخه جدید و بهبود یافته اپلیکیشن با ویژگیهای جذاب منتظر
|
|
||||||
شماست
|
|
||||||
</p>
|
|
||||||
<p>برای تجربه بهتر، لطفا نسخه فعلی را بروزرسانی کنید</p>
|
|
||||||
<p>
|
|
||||||
پس از کلیک بر روی گزینه دریافت نسخه جدید، برنامه به صورت
|
|
||||||
خودکار بروز میشود
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="py-6 border-t border-slate-200 flex gap-3">
|
|
||||||
<Button
|
|
||||||
@click="emit('update', null)"
|
|
||||||
class="rounded-full px-10"
|
|
||||||
>
|
|
||||||
<span>دریافت ورژن جدید</span>
|
|
||||||
</Button>
|
|
||||||
<DialogClose aria-label="Close">
|
|
||||||
<Button variant="outlined" class="rounded-full px-10">
|
|
||||||
انصراف
|
|
||||||
</Button>
|
|
||||||
</DialogClose>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</Modal>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
export const usePWA = () => {
|
|
||||||
const isInstalledAsPWA = ref(false);
|
|
||||||
|
|
||||||
const checkPWAInstallation = () => {
|
|
||||||
const isStandalone = window.matchMedia(
|
|
||||||
"(display-mode: standalone)"
|
|
||||||
).matches;
|
|
||||||
const isIOSPWA = (window.navigator as any).standalone;
|
|
||||||
isInstalledAsPWA.value = isStandalone || isIOSPWA;
|
|
||||||
};
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
checkPWAInstallation();
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
isInstalledAsPWA,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -83,10 +83,6 @@ export default defineNuxtConfig({
|
|||||||
},
|
},
|
||||||
|
|
||||||
pwa: {
|
pwa: {
|
||||||
// strategies: "injectManifest",
|
|
||||||
// srcDir: "public",
|
|
||||||
// filename: "sw.js",
|
|
||||||
// registerType: process.env.NODE_ENV === "production" ? "autoUpdate" : "prompt",
|
|
||||||
manifest: {
|
manifest: {
|
||||||
name: "Heymlz",
|
name: "Heymlz",
|
||||||
short_name: "Heymlz",
|
short_name: "Heymlz",
|
||||||
@@ -118,15 +114,6 @@ export default defineNuxtConfig({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
workbox: {
|
|
||||||
navigateFallback: "/",
|
|
||||||
clientsClaim: true,
|
|
||||||
skipWaiting: true,
|
|
||||||
},
|
|
||||||
devOptions: {
|
|
||||||
enabled: process.env.NODE_ENV === "production",
|
|
||||||
type: "module",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
typescript: {
|
typescript: {
|
||||||
|
|||||||
@@ -50,8 +50,7 @@
|
|||||||
"vue-skeletor": "^1.0.6",
|
"vue-skeletor": "^1.0.6",
|
||||||
"vue3-marquee": "^4.2.2",
|
"vue3-marquee": "^4.2.2",
|
||||||
"vue3-persian-datetime-picker": "^1.2.2",
|
"vue3-persian-datetime-picker": "^1.2.2",
|
||||||
"web-push": "^3.6.7",
|
"web-push": "^3.6.7"
|
||||||
"workbox-window": "^7.4.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/postcss": "^4.2.4",
|
"@tailwindcss/postcss": "^4.2.4",
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
import { Workbox } from "workbox-window";
|
|
||||||
import { usePWA } from "~/composables/global/usePwa";
|
|
||||||
|
|
||||||
export default defineNuxtPlugin(() => {
|
|
||||||
const updateAvailable = ref(false);
|
|
||||||
let wb: Workbox | null = null;
|
|
||||||
|
|
||||||
const { isInstalledAsPWA } = usePWA();
|
|
||||||
|
|
||||||
if ("serviceWorker" in navigator && isInstalledAsPWA.value) {
|
|
||||||
// Initialize Workbox
|
|
||||||
wb = new Workbox("/sw.js");
|
|
||||||
|
|
||||||
navigator.serviceWorker
|
|
||||||
.register("/sw.js")
|
|
||||||
.then((registration) => {
|
|
||||||
// Native Service Worker API for update detection
|
|
||||||
registration.addEventListener("updatefound", () => {
|
|
||||||
const newWorker = registration.installing;
|
|
||||||
if (newWorker) {
|
|
||||||
newWorker.addEventListener("statechange", () => {
|
|
||||||
if (newWorker.state === "installed") {
|
|
||||||
// Only show prompt if there's a controller (not first install)
|
|
||||||
if (navigator.serviceWorker.controller) {
|
|
||||||
checkForUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Workbox events for consistency
|
|
||||||
wb?.addEventListener("waiting", () => {
|
|
||||||
checkForUpdate();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check if there's already a waiting worker
|
|
||||||
if (registration.waiting) {
|
|
||||||
checkForUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Periodic update checks (optional)
|
|
||||||
setInterval(() => {
|
|
||||||
registration.update().catch((err) => {
|
|
||||||
console.debug(
|
|
||||||
"Service worker update check failed:",
|
|
||||||
err
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}, 60 * 60 * 1000); // Check every hour
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error("Service worker registration failed:", err);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Register Workbox
|
|
||||||
wb.register().catch((error) => {
|
|
||||||
console.error("Workbox registration failed:", error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const checkForUpdate = () => {
|
|
||||||
if (!updateAvailable.value) {
|
|
||||||
updateAvailable.value = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleUpdate = () => {
|
|
||||||
if (wb) {
|
|
||||||
// Send skip waiting message
|
|
||||||
wb.messageSW({ type: "SKIP_WAITING" }).then(() => {
|
|
||||||
// Notify all tabs to reload
|
|
||||||
if (navigator.serviceWorker.controller) {
|
|
||||||
navigator.serviceWorker.controller.postMessage({
|
|
||||||
type: "CLIENT_RELOAD",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
window.location.reload();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
provide: {
|
|
||||||
updateAvailable,
|
|
||||||
handleUpdate,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
import { precacheAndRoute } from "workbox-precaching";
|
|
||||||
|
|
||||||
// Precaching configuration for PWA assets
|
|
||||||
precacheAndRoute(self.__WB_MANIFEST);
|
|
||||||
|
|
||||||
const VERSION = "1.0.4";
|
|
||||||
|
|
||||||
// Only enable skipWaiting and claim in production
|
|
||||||
const isProduction = process.env.NODE_ENV === "production";
|
|
||||||
|
|
||||||
self.addEventListener("install", (event) => {
|
|
||||||
if (isProduction) {
|
|
||||||
self.skipWaiting();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
self.addEventListener("activate", (event) => {
|
|
||||||
event.waitUntil(
|
|
||||||
(async () => {
|
|
||||||
if (isProduction) {
|
|
||||||
const clients = await self.clients.matchAll({ type: "window" });
|
|
||||||
clients.forEach((client) =>
|
|
||||||
client.postMessage({
|
|
||||||
type: "VERSION_CHECK",
|
|
||||||
version: VERSION,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
self.clients.claim();
|
|
||||||
}
|
|
||||||
console.log("Service Worker Activated (Version: " + VERSION + ")");
|
|
||||||
})()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Rest of your existing handlers remain the same...
|
|
||||||
self.addEventListener("push", (event) => {
|
|
||||||
try {
|
|
||||||
const payload = event.data?.json() || {
|
|
||||||
title: "New Notification",
|
|
||||||
body: "You have a new message",
|
|
||||||
icon: "/logo-192x192.png",
|
|
||||||
data: { url: "/" },
|
|
||||||
};
|
|
||||||
|
|
||||||
event.waitUntil(
|
|
||||||
self.registration.showNotification(payload.title, {
|
|
||||||
body: payload.body,
|
|
||||||
icon: payload.icon || "/logo-192x192.png",
|
|
||||||
data: payload.data,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Push handling failed:", error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
self.addEventListener("notificationclick", (event) => {
|
|
||||||
event.notification.close();
|
|
||||||
event.waitUntil(clients.openWindow(event.notification.data?.url || "/"));
|
|
||||||
});
|
|
||||||
|
|
||||||
self.addEventListener("message", (event) => {
|
|
||||||
if (event.data === "SKIP_WAITING") {
|
|
||||||
self.skipWaiting();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user