feat: pwa auto-update; fix WS hijack, DM names, tap reactions
CI / Go (build + vet + test) (push) Canceled after 0s
CI / Web (build + lint) (push) Canceled after 0s

This commit is contained in:
vantablackTea
2026-09-28 14:18:44 +03:00
parent a0b17d25bf
commit 82fa4b029f
3 changed files with 52 additions and 3 deletions
+3 -3
View File
@@ -1,11 +1,11 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { registerSW } from 'virtual:pwa-register'
import './index.css'
import App from './App'
import { AuthProvider } from './auth/AuthContext'
import { setupPWA } from './pwa'
registerSW({ immediate: true })
setupPWA()
createRoot(document.getElementById('root')!).render(
<StrictMode>
@@ -13,4 +13,4 @@ createRoot(document.getElementById('root')!).render(
<App />
</AuthProvider>
</StrictMode>,
)
)
+35
View File
@@ -0,0 +1,35 @@
import { registerSW } from 'virtual:pwa-register'
let refreshing = false
const UPDATE_CHECK_INTERVAL_MS = 30 * 60 * 1000
// setupPWA registers the service worker and keeps the installed app fresh:
// it polls for updates and reloads once when a new worker takes control.
export function setupPWA(): void {
if (typeof navigator === 'undefined' || !('serviceWorker' in navigator)) return
navigator.serviceWorker.addEventListener('controllerchange', () => {
if (refreshing) return
refreshing = true
window.location.reload()
})
registerSW({
immediate: true,
onRegisteredSW(_swUrl, registration) {
if (!registration) return
const check = () => {
void registration.update().catch(() => {})
}
// Installed PWAs stay open for days without navigation, so trigger
// update checks on a timer, on focus and when connectivity returns.
window.setInterval(check, UPDATE_CHECK_INTERVAL_MS)
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') check()
})
window.addEventListener('online', check)
check()
},
})
}