temp: try unregister sw

This commit is contained in:
fly_mc 2024-10-25 21:03:08 +08:00
parent 7864a631c4
commit 574798d019
2 changed files with 28 additions and 11 deletions

View file

@ -6,13 +6,30 @@
import { lang } from '@@/js/config.js';
export async function initializeSw() {
if (!('serviceWorker' in navigator)) return;
if (!('serviceWorker' in navigator)) return;
navigator.serviceWorker.register('/sw.js', { scope: '/', type: 'classic' });
navigator.serviceWorker.ready.then(registration => {
registration.active?.postMessage({
msg: 'initialize',
lang,
});
});
try {
const registrations = await navigator.serviceWorker.getRegistrations();
await Promise.all(
registrations.map(registration => registration.unregister())
);
console.info('Successfully unregistered old service worker(s)');
const registration = await navigator.serviceWorker.register('/sw.js', {
scope: '/',
type: 'classic'
});
await navigator.serviceWorker.ready;
registration.active?.postMessage({
msg: 'initialize',
lang,
});
console.info('Successfully registered and initialized new service worker');
} catch (error) {
console.error('Service worker registration/initialization failed:', error);
}
}

View file

@ -134,9 +134,9 @@ globalThis.addEventListener('notificationclick', (ev: ServiceWorkerGlobalScopeEv
case 'showFollowRequests':
client = await swos.openClient('push', '/my/follow-requests', loginId);
break;
case 'edited':
if ('note' in data.body) client = await swos.openPost({ reply: data.body.note }, loginId);
break;
case 'edited':
if ('note' in data.body) client = await swos.openPost({ reply: data.body.note }, loginId);
break;
default:
switch (data.body.type) {
case 'receiveFollowRequest':