order
This commit is contained in:
@@ -1,6 +1,49 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
|
||||
const CACHE_NAME = "pwa-cache-v10";
|
||||
// عین google-services.json/pushToken.ts اندروید — این مقادیر عمومی و امن برای
|
||||
// مرورگرند. سرویسورکرِ استاتیک نمیتونه process.env بخونه، پس مستقیم اینجا نوشته
|
||||
// شدن (دقیقاً همون چیزی که NEXT_PUBLIC_FIREBASE_* توی باندلِ کلاینت هم inline میشه)
|
||||
importScripts("https://www.gstatic.com/firebasejs/10.13.2/firebase-app-compat.js");
|
||||
importScripts("https://www.gstatic.com/firebasejs/10.13.2/firebase-messaging-compat.js");
|
||||
|
||||
firebase.initializeApp({
|
||||
apiKey: "AIzaSyDpUh8AlafwyM931o519oX3z7JYnXZJyBg",
|
||||
authDomain: "modstagram-com.firebaseapp.com",
|
||||
projectId: "modstagram-com",
|
||||
storageBucket: "modstagram-com.firebasestorage.app",
|
||||
messagingSenderId: "767614062479",
|
||||
appId: "1:767614062479:web:ec2aea23cc8ce17dfe45fa",
|
||||
});
|
||||
|
||||
// پیامِ پوش وقتی تب بسته/پسزمینهست — عین رفتار پیشفرضِ اندروید (نوتیفِ سیستمی).
|
||||
// وقتی تب باز و فعاله، Firebase این رویداد رو صدا نمیزنه — اونجا onMessage
|
||||
// (pushNotifications.ts سمتِ کلاینت) با toast جایگزینش میکنه
|
||||
const messaging = firebase.messaging.isSupported() ? firebase.messaging() : null;
|
||||
if (messaging) {
|
||||
messaging.onBackgroundMessage((payload) => {
|
||||
const title = payload.notification?.title || "modstagram";
|
||||
self.registration.showNotification(title, {
|
||||
body: payload.notification?.body,
|
||||
icon: "/images/icons/192x192.png",
|
||||
badge: "/images/icons/192x192.png",
|
||||
data: payload.data || {},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
self.addEventListener("notificationclick", (event) => {
|
||||
event.notification.close();
|
||||
const url = "/settings/notifications";
|
||||
event.waitUntil(
|
||||
self.clients.matchAll({ type: "window", includeUncontrolled: true }).then((clientsArr) => {
|
||||
const existing = clientsArr.find((c) => c.url.includes(url));
|
||||
if (existing) return existing.focus();
|
||||
return self.clients.openWindow(url);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
const CACHE_NAME = "pwa-cache-v11";
|
||||
|
||||
const PRECACHE_URLS = [
|
||||
"/",
|
||||
|
||||
Reference in New Issue
Block a user