Force PWA updates before push registration
This commit is contained in:
@@ -469,7 +469,11 @@ const serveStatic = (req, res) => {
|
||||
'.json': 'application/json',
|
||||
'.webmanifest': 'application/manifest+json',
|
||||
}
|
||||
res.writeHead(200, { 'Content-Type': types[ext] || 'application/octet-stream' })
|
||||
const headers = { 'Content-Type': types[ext] || 'application/octet-stream' }
|
||||
if (path.basename(safePath) === 'sw.js' || ext === '.html' || ext === '.webmanifest') {
|
||||
headers['Cache-Control'] = 'no-store'
|
||||
}
|
||||
res.writeHead(200, headers)
|
||||
createReadStream(safePath).pipe(res)
|
||||
}
|
||||
|
||||
|
||||
11
src/main.js
11
src/main.js
@@ -6,8 +6,17 @@ createApp(App).mount('#app')
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker.register('/sw.js').catch((error) => {
|
||||
navigator.serviceWorker.register('/sw.js', { updateViaCache: 'none' }).then((registration) => {
|
||||
registration.update().catch(() => {})
|
||||
}).catch((error) => {
|
||||
console.warn('Service worker registration failed:', error)
|
||||
})
|
||||
})
|
||||
|
||||
let refreshing = false
|
||||
navigator.serviceWorker.addEventListener('controllerchange', () => {
|
||||
if (refreshing) return
|
||||
refreshing = true
|
||||
window.location.reload()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ const explainSubscribeError = async (error) => {
|
||||
if (brave && /push service|registration failed|not available|permission/i.test(message)) {
|
||||
return 'Brave is blocking Web Push. In Brave settings, enable "Use Google services for push messaging", then fully close and reopen the installed L484 app.'
|
||||
}
|
||||
if (/push service|registration failed|not available/i.test(message)) {
|
||||
return 'The browser push service is unavailable. In Brave, enable "Use Google services for push messaging"; otherwise fully close and reopen the installed app, then try again.'
|
||||
}
|
||||
return `Push registration failed: ${message}. Fully close and reopen the installed app, then try again.`
|
||||
}
|
||||
|
||||
@@ -77,7 +80,7 @@ export const subscribeToNotifications = async () => {
|
||||
permission.value = requested
|
||||
if (requested !== 'granted') throw new Error('Notification permission was not granted.')
|
||||
|
||||
const registered = await navigator.serviceWorker.register('/sw.js', { scope: '/' })
|
||||
const registered = await navigator.serviceWorker.register('/sw.js', { scope: '/', updateViaCache: 'none' })
|
||||
await registered.update().catch(() => {})
|
||||
const readyRegistration = await navigator.serviceWorker.ready
|
||||
const existing = await readyRegistration.pushManager.getSubscription()
|
||||
|
||||
Reference in New Issue
Block a user