iOS PWA and IT Job Checklist for IT Staff view

This commit is contained in:
2026-04-11 07:40:12 +08:00
parent 5cb6561924
commit f223d1f958
18 changed files with 389 additions and 109 deletions
+60 -9
View File
@@ -9,19 +9,70 @@ importScripts('https://www.gstatic.com/firebasejs/9.22.2/firebase-messaging-comp
firebase.initializeApp({
// values must match `firebase_options.dart` generated by `flutterfire`
apiKey: 'AIzaSyBKGSaHYiqpZvbEgsvJJY45soiIkV6MV3M',
appId: '1:173359574734:web:f894a6b43a443e902baa9f',
messagingSenderId: '173359574734',
projectId: 'tasq-17fb3',
authDomain: 'tasq-17fb3.firebaseapp.com',
storageBucket: 'tasq-17fb3.firebasestorage.app',
appId: '1:173359574734:web:f894a6b43a443e902baa9f',
messagingSenderId: '173359574734',
projectId: 'tasq-17fb3',
authDomain: 'tasq-17fb3.firebaseapp.com',
storageBucket: 'tasq-17fb3.firebasestorage.app',
});
const messaging = firebase.messaging();
messaging.onBackgroundMessage(function(payload) {
// display a notification using data in the payload
self.registration.showNotification(payload.notification.title, {
body: payload.notification.body,
const notificationTitle = payload.notification?.title
|| payload.data?.title
|| 'TasQ Notification';
const notificationBody = payload.notification?.body
|| payload.data?.body
|| '';
const notificationOptions = {
body: notificationBody,
icon: '/icons/Icon-192.png',
badge: '/icons/Icon-192.png',
data: payload.data,
});
// tag deduplicates: same notification_id won't stack
tag: payload.data?.notification_id || payload.messageId || 'tasq',
renotify: true,
};
return self.registration.showNotification(notificationTitle, notificationOptions);
});
// Handle notification click — focus the PWA window and navigate to the
// relevant task / ticket route based on the data payload.
self.addEventListener('notificationclick', function(event) {
event.notification.close();
const data = event.notification.data || {};
const navigateTo = data.navigate_to || data.route;
const taskId = data.task_id || data.taskId;
const ticketId = data.ticket_id || data.ticketId;
let targetPath = '/';
if (navigateTo && navigateTo !== '/') {
targetPath = navigateTo;
} else if (taskId) {
targetPath = '/tasks/' + taskId;
} else if (ticketId) {
targetPath = '/tickets/' + ticketId;
}
event.waitUntil(
clients
.matchAll({ type: 'window', includeUncontrolled: true })
.then(function(clientList) {
// If the app is already open, navigate it and bring it to front
for (const client of clientList) {
if ('navigate' in client) {
client.navigate(targetPath);
return client.focus();
}
}
// Otherwise open a new window
if (clients.openWindow) {
return clients.openWindow(targetPath);
}
})
);
});