mirror of
https://github.com/danog/telegram-tt.git
synced 2025-01-22 13:21:37 +01:00
Service Worker: Auto-recover after hard reload (#1707)
This commit is contained in:
parent
94cdf97b0b
commit
b366d22575
@ -43,7 +43,8 @@ const READABLE_ERROR_MESSAGES: Record<string, string> = {
|
||||
MESSAGE_TOO_LONG: 'Message is too long',
|
||||
|
||||
// Non-API errors
|
||||
SERVICE_WORKER_DISABLED: 'Service Worker is disabled. Please reload the page without holding <Shift> key.',
|
||||
// eslint-disable-next-line max-len
|
||||
SERVICE_WORKER_DISABLED: 'Service Worker is disabled. Streaming media may not be supported. Try reloading the page without holding <Shift> key',
|
||||
// eslint-disable-next-line max-len
|
||||
MESSAGE_TOO_LONG_PLEASE_REMOVE_CHARACTERS: 'The provided message is too long. Please remove {EXTRA_CHARS_COUNT} character{PLURAL_S}.',
|
||||
// eslint-disable-next-line max-len
|
||||
|
@ -38,6 +38,17 @@ function subscribeToWorker() {
|
||||
if (IS_SERVICE_WORKER_SUPPORTED) {
|
||||
window.addEventListener('load', async () => {
|
||||
try {
|
||||
if (!navigator.serviceWorker.controller) {
|
||||
const registrations = await navigator.serviceWorker.getRegistrations();
|
||||
if (registrations.length) {
|
||||
if (DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[SW] Hard reload detected, re-enabling Service Worker');
|
||||
}
|
||||
await Promise.all(registrations.map(r => r.unregister()));
|
||||
}
|
||||
}
|
||||
|
||||
await navigator.serviceWorker.register(new URL('../serviceWorker.ts', import.meta.url));
|
||||
|
||||
if (DEBUG) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user