From 0967689a8f64b88a4e789f07e36f7758627a5541 Mon Sep 17 00:00:00 2001 From: Vasilii Mikhailovskii Date: Thu, 5 Dec 2024 14:11:11 +0200 Subject: [PATCH] update manifest --- apps/frontend/public/service-worker.js | 24 +++++++++++++----------- apps/frontend/vite.config.ts | 5 +++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/apps/frontend/public/service-worker.js b/apps/frontend/public/service-worker.js index 0c086d0..8c3799e 100644 --- a/apps/frontend/public/service-worker.js +++ b/apps/frontend/public/service-worker.js @@ -1,4 +1,4 @@ -const VER = 6 +const VER = 7 self.addEventListener('message', async (event) => { event.waitUntil(debug(event.source, Object.assign({ answer: true }, event.data))) @@ -27,12 +27,18 @@ self.addEventListener('push', (event) => { if (!pushData || !pushData.notification.title) { console.error('Received WebPush with an empty title. Received body: ', pushData) } - self.registration - .showNotification(pushData.notification.title, pushData.notification.options) - .then(function () { - // You can save to your analytics fact that push was shown - // fetch('https://your_backend_server.com/track_show?message_id=' + pushData.data.message_id); - }) + event.waitUntil( + self.registration + .showNotification(pushData.notification.title, pushData.notification.options) + .then(function () { + // You can save to your analytics fact that push was shown + // fetch('https://your_backend_server.com/track_show?message_id=' + pushData.data.message_id); + }), + ) +}) + +self.addEventListener('notificationclick', (event) => { + event.waitUntil(handleNotificationClick(event)) }) async function handleNotificationClick(event) { @@ -57,10 +63,6 @@ async function handleNotificationClick(event) { await openURL(event.notification.data.url) } -self.addEventListener('notificationclick', (event) => { - event.waitUntil(handleNotificationClick(event)) -}) - async function openURL(urlToOpen) { let matchedClients try { diff --git a/apps/frontend/vite.config.ts b/apps/frontend/vite.config.ts index 4ce3d68..e47a24e 100644 --- a/apps/frontend/vite.config.ts +++ b/apps/frontend/vite.config.ts @@ -127,9 +127,10 @@ export default defineConfig(({ mode }) => { '/manifest.json': { async handler(req, res) { const { default: manifestJSON } = await import('./src/manifest.json') + const result = { ...manifestJSON, ...manifest, id: `//${req.headers.host}` } res.statusCode = 200 - res.setHeader('Content-Type', 'text/html') - res.end(JSON.stringify({ ...manifestJSON, ...manifest }, null, 2)) + res.setHeader('Content-Type', 'application/json;charset=utf-8') + res.end(JSON.stringify(result, null, 2)) }, } satisfies RouteConfig, },