This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
const VER = 6
|
const VER = 7
|
||||||
|
|
||||||
self.addEventListener('message', async (event) => {
|
self.addEventListener('message', async (event) => {
|
||||||
event.waitUntil(debug(event.source, Object.assign({ answer: true }, event.data)))
|
event.waitUntil(debug(event.source, Object.assign({ answer: true }, event.data)))
|
||||||
@@ -27,12 +27,18 @@ self.addEventListener('push', (event) => {
|
|||||||
if (!pushData || !pushData.notification.title) {
|
if (!pushData || !pushData.notification.title) {
|
||||||
console.error('Received WebPush with an empty title. Received body: ', pushData)
|
console.error('Received WebPush with an empty title. Received body: ', pushData)
|
||||||
}
|
}
|
||||||
|
event.waitUntil(
|
||||||
self.registration
|
self.registration
|
||||||
.showNotification(pushData.notification.title, pushData.notification.options)
|
.showNotification(pushData.notification.title, pushData.notification.options)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
// You can save to your analytics fact that push was shown
|
// 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);
|
// 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) {
|
async function handleNotificationClick(event) {
|
||||||
@@ -57,10 +63,6 @@ async function handleNotificationClick(event) {
|
|||||||
await openURL(event.notification.data.url)
|
await openURL(event.notification.data.url)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.addEventListener('notificationclick', (event) => {
|
|
||||||
event.waitUntil(handleNotificationClick(event))
|
|
||||||
})
|
|
||||||
|
|
||||||
async function openURL(urlToOpen) {
|
async function openURL(urlToOpen) {
|
||||||
let matchedClients
|
let matchedClients
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -127,9 +127,10 @@ export default defineConfig(({ mode }) => {
|
|||||||
'/manifest.json': {
|
'/manifest.json': {
|
||||||
async handler(req, res) {
|
async handler(req, res) {
|
||||||
const { default: manifestJSON } = await import('./src/manifest.json')
|
const { default: manifestJSON } = await import('./src/manifest.json')
|
||||||
|
const result = { ...manifestJSON, ...manifest, id: `//${req.headers.host}` }
|
||||||
res.statusCode = 200
|
res.statusCode = 200
|
||||||
res.setHeader('Content-Type', 'text/html')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
res.end(JSON.stringify({ ...manifestJSON, ...manifest }, null, 2))
|
res.end(JSON.stringify(result, null, 2))
|
||||||
},
|
},
|
||||||
} satisfies RouteConfig,
|
} satisfies RouteConfig,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user