v0.12.4 windsurf changes

This commit is contained in:
2026-03-23 11:46:22 -04:00
parent cf9b22feb5
commit b3cc9727e4
5 changed files with 166 additions and 26 deletions

View File

@@ -1,24 +1,35 @@
// ── Firebase Messaging (background push for Android PWA) ──────────────────────
// Fill in the values below from Firebase Console → Project Settings → General → Your apps
// Leave apiKey as '__FIREBASE_API_KEY__' if not using FCM (push will be disabled).
// Dynamically fetch Firebase config from backend to ensure consistency
importScripts('https://www.gstatic.com/firebasejs/10.14.1/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/10.14.1/firebase-messaging-compat.js');
const FIREBASE_CONFIG = {
apiKey: "AIzaSyDx191unzXFT4WA1OvkdbrIY_c57kgruAU",
authDomain: "rosterchirp-push.firebaseapp.com",
projectId: "rosterchirp-push",
storageBucket: "rosterchirp-push.firebasestorage.app",
messagingSenderId: "126479377334",
appId: "1:126479377334:web:280abdd135cf7e0c50d717"
};
let FIREBASE_CONFIG = null;
let VAPID_KEY = null;
// Only initialise Firebase if the config has been filled in
// Fetch Firebase config and initialise messaging
let messaging = null;
if (FIREBASE_CONFIG.apiKey !== '__FIREBASE_API_KEY__') {
firebase.initializeApp(FIREBASE_CONFIG);
messaging = firebase.messaging();
}
let firebaseConfigPromise = fetch('/api/push/firebase-config')
.then(res => res.json())
.then(config => {
FIREBASE_CONFIG = {
apiKey: config.apiKey,
authDomain: config.authDomain || `${config.projectId}.firebaseapp.com`,
projectId: config.projectId,
storageBucket: config.storageBucket || `${config.projectId}.firebasestorage.app`,
messagingSenderId: config.messagingSenderId,
appId: config.appId
};
VAPID_KEY = config.vapidKey;
if (FIREBASE_CONFIG.apiKey) {
firebase.initializeApp(FIREBASE_CONFIG);
messaging = firebase.messaging();
console.log('[SW] Firebase initialized with dynamic config');
}
})
.catch(err => {
console.warn('[SW] Failed to fetch Firebase config:', err);
});
// ── Cache ─────────────────────────────────────────────────────────────────────
const CACHE_NAME = 'rosterchirp-v1';
@@ -70,14 +81,17 @@ function showRosterChirpNotification(data) {
}
// ── FCM background messages ───────────────────────────────────────────────────
if (messaging) {
messaging.onBackgroundMessage((payload) => {
console.log('[SW] onBackgroundMessage received, data:', JSON.stringify(payload.data));
return showRosterChirpNotification(payload.data || {});
});
} else {
console.warn('[SW] Firebase messaging not initialised — push notifications disabled');
}
// Wait for Firebase config to be loaded before setting up message handler
firebaseConfigPromise.then(() => {
if (messaging) {
messaging.onBackgroundMessage((payload) => {
console.log('[SW] onBackgroundMessage received, data:', JSON.stringify(payload.data));
return showRosterChirpNotification(payload.data || {});
});
} else {
console.warn('[SW] Firebase messaging not initialised — push notifications disabled');
}
});
// ── Raw push event (fallback diagnostic) ─────────────────────────────────────
// Fires for every push event BEFORE the Firebase SDK handles it.