notification links
All checks were successful
/ upload (release) Successful in 35s

This commit is contained in:
pavel 2026-02-12 21:26:41 +01:00
commit 42a78c529d
5 changed files with 74 additions and 5 deletions

View file

@ -1,4 +1,4 @@
const CACHE_NAME = 'agency-cache-v2';
const CACHE_NAME = 'agency-cache-v3';
const ASSETS = [
'/',
'/index.html',
@ -34,8 +34,16 @@ self.addEventListener('fetch', (event) => {
})
);
});
self.addEventListener('push', (event) => {
const data = event.data ? event.data.json() : { title: 'Notification', body: 'New update from Agency' };
let data = { title: 'Notification', body: 'New update from Agency' };
try {
if (event.data) {
data = event.data.json();
}
} catch (e) {
console.error('Error parsing push data:', e);
}
const options = {
body: data.body,
@ -44,7 +52,9 @@ self.addEventListener('push', (event) => {
vibrate: [100, 50, 100],
data: {
dateOfArrival: Date.now(),
primaryKey: '1'
primaryKey: '1',
taskId: data.task_id,
runId: data.run_id
}
};
@ -55,7 +65,27 @@ self.addEventListener('push', (event) => {
self.addEventListener('notificationclick', (event) => {
event.notification.close();
const taskId = event.notification.data.taskId;
const runId = event.notification.data.runId;
let url = '/';
if (taskId && runId) {
url = `/?taskId=${taskId}&runId=${runId}`;
}
event.waitUntil(
clients.openWindow('/')
clients.matchAll({ type: 'window', includeUncontrolled: true }).then((windowClients) => {
// Check if there is already a window open and focus it, or open a new one
for (let client of windowClients) {
if ('focus' in client) {
// Navigate the existing client to the new URL if it's the same app
return client.navigate(url).then(c => c.focus());
}
}
if (clients.openWindow) {
return clients.openWindow(url);
}
})
);
});