Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2912191091 | ||
|
|
95084b0a02 | ||
|
|
dbc0a7d695 | ||
|
|
8d180aa751 | ||
|
|
2acd08136e | ||
|
|
d68b04de45 |
No files matched your search
@@ -150,3 +150,4 @@ dump.rdb
|
|||||||
firebase-config.json
|
firebase-config.json
|
||||||
firebase.json
|
firebase.json
|
||||||
static/js/firebase-config.js
|
static/js/firebase-config.js
|
||||||
|
static/firebase-messaging-sw.js
|
||||||
+1
-1
@@ -40,5 +40,5 @@ requests==2.32.3
|
|||||||
rsa==4.9
|
rsa==4.9
|
||||||
sqlparse==0.5.3
|
sqlparse==0.5.3
|
||||||
uritemplate==4.1.1
|
uritemplate==4.1.1
|
||||||
urllib3==2.3.0
|
urllib3==2.4.0
|
||||||
whitenoise==6.9.0
|
whitenoise==6.9.0
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
importScripts(
|
||||||
|
"https://www.gstatic.com/firebasejs/9.22.0/firebase-app-compat.js",
|
||||||
|
);
|
||||||
|
importScripts(
|
||||||
|
"https://www.gstatic.com/firebasejs/9.22.0/firebase-messaging-compat.js",
|
||||||
|
);
|
||||||
|
|
||||||
|
firebase.initializeApp({
|
||||||
|
apiKey: "YOUR_API_KEY",
|
||||||
|
authDomain: "YOUR_AUTH_DOMAIN",
|
||||||
|
projectId: "YOUR_PROJECT_ID",
|
||||||
|
storageBucket: "YOUR_STORAGE_BUCKET",
|
||||||
|
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
|
||||||
|
appId: "YOUR_APP_ID",
|
||||||
|
measurementId: "YOUR_MEASUREMENT_ID",
|
||||||
|
});
|
||||||
|
|
||||||
|
const messaging = firebase.messaging();
|
||||||
|
|
||||||
|
// Handle background messages
|
||||||
|
messaging.onBackgroundMessage((payload) => {
|
||||||
|
console.log("Received background message:", payload);
|
||||||
|
|
||||||
|
// Default notification options
|
||||||
|
const notificationOptions = {
|
||||||
|
body: "You have a new message.",
|
||||||
|
icon: "/static/img/logo.png",
|
||||||
|
badge: "/static/img/logo.png",
|
||||||
|
timestamp: Date.now(),
|
||||||
|
requireInteraction: true,
|
||||||
|
vibrate: [200, 100, 200],
|
||||||
|
tag: "notification-" + Date.now(),
|
||||||
|
data: payload.data || {},
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
action: "open",
|
||||||
|
title: "Open",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: "close",
|
||||||
|
title: "Close",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set notification title and body based on payload
|
||||||
|
let notificationTitle = "New Notification";
|
||||||
|
if (payload.notification) {
|
||||||
|
notificationTitle = payload.notification.title || notificationTitle;
|
||||||
|
notificationOptions.body =
|
||||||
|
payload.notification.body || notificationOptions.body;
|
||||||
|
if (payload.notification.icon) {
|
||||||
|
notificationOptions.icon = payload.notification.icon;
|
||||||
|
}
|
||||||
|
} else if (payload.data) {
|
||||||
|
notificationTitle = payload.data.title || notificationTitle;
|
||||||
|
notificationOptions.body = payload.data.body || notificationOptions.body;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the notification
|
||||||
|
return self.registration
|
||||||
|
.showNotification(notificationTitle, notificationOptions)
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error showing notification:", error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle notification click
|
||||||
|
self.addEventListener("notificationclick", (event) => {
|
||||||
|
console.log("Notification clicked:", event);
|
||||||
|
|
||||||
|
event.notification.close();
|
||||||
|
|
||||||
|
if (event.action === "open") {
|
||||||
|
// Handle open action
|
||||||
|
const urlToOpen = event.notification.data.url || "/app/dashboard/";
|
||||||
|
event.waitUntil(clients.openWindow(urlToOpen));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle service worker installation
|
||||||
|
self.addEventListener("install", (event) => {
|
||||||
|
console.log("Service Worker installed");
|
||||||
|
self.skipWaiting();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle service worker activation
|
||||||
|
self.addEventListener("activate", (event) => {
|
||||||
|
console.log("Service Worker activated");
|
||||||
|
event.waitUntil(clients.claim());
|
||||||
|
});
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
importScripts('https://www.gstatic.com/firebasejs/9.22.0/firebase-app-compat.js');
|
|
||||||
importScripts('https://www.gstatic.com/firebasejs/9.22.0/firebase-messaging-compat.js');
|
|
||||||
|
|
||||||
firebase.initializeApp({
|
|
||||||
apiKey: "AIzaSyAYgYXsf4-iwSDEEBcNAJ3YJxz76C3STsU",
|
|
||||||
authDomain: "student-management-syste-2e040.firebaseapp.com",
|
|
||||||
projectId: "student-management-syste-2e040",
|
|
||||||
storageBucket: "student-management-syste-2e040.appspot.com",
|
|
||||||
messagingSenderId: "800148418884",
|
|
||||||
appId: "1:800148418884:web:144b9c85bfeeec12252711",
|
|
||||||
measurementId: "G-BNRM6QEJQV"
|
|
||||||
});
|
|
||||||
|
|
||||||
const messaging = firebase.messaging();
|
|
||||||
|
|
||||||
// Handle background messages
|
|
||||||
messaging.onBackgroundMessage((payload) => {
|
|
||||||
console.log('Received background message:', payload);
|
|
||||||
|
|
||||||
// Default notification options
|
|
||||||
const notificationOptions = {
|
|
||||||
body: 'You have a new message.',
|
|
||||||
icon: '/static/img/logo.png',
|
|
||||||
badge: '/static/img/logo.png',
|
|
||||||
timestamp: Date.now(),
|
|
||||||
requireInteraction: true,
|
|
||||||
vibrate: [200, 100, 200],
|
|
||||||
tag: 'notification-' + Date.now(),
|
|
||||||
data: payload.data || {},
|
|
||||||
actions: [
|
|
||||||
{
|
|
||||||
action: 'open',
|
|
||||||
title: 'Open'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
action: 'close',
|
|
||||||
title: 'Close'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
// Set notification title and body based on payload
|
|
||||||
let notificationTitle = 'New Notification';
|
|
||||||
if (payload.notification) {
|
|
||||||
notificationTitle = payload.notification.title || notificationTitle;
|
|
||||||
notificationOptions.body = payload.notification.body || notificationOptions.body;
|
|
||||||
if (payload.notification.icon) {
|
|
||||||
notificationOptions.icon = payload.notification.icon;
|
|
||||||
}
|
|
||||||
} else if (payload.data) {
|
|
||||||
notificationTitle = payload.data.title || notificationTitle;
|
|
||||||
notificationOptions.body = payload.data.body || notificationOptions.body;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show the notification
|
|
||||||
return self.registration.showNotification(notificationTitle, notificationOptions)
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error showing notification:', error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle notification click
|
|
||||||
self.addEventListener('notificationclick', (event) => {
|
|
||||||
console.log('Notification clicked:', event);
|
|
||||||
|
|
||||||
event.notification.close();
|
|
||||||
|
|
||||||
if (event.action === 'open') {
|
|
||||||
// Handle open action
|
|
||||||
const urlToOpen = event.notification.data.url || '/app/dashboard/';
|
|
||||||
event.waitUntil(
|
|
||||||
clients.openWindow(urlToOpen)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle service worker installation
|
|
||||||
self.addEventListener('install', (event) => {
|
|
||||||
console.log('Service Worker installed');
|
|
||||||
self.skipWaiting();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle service worker activation
|
|
||||||
self.addEventListener('activate', (event) => {
|
|
||||||
console.log('Service Worker activated');
|
|
||||||
event.waitUntil(clients.claim());
|
|
||||||
});
|
|
||||||
Reference in new issue
Block a user