diff --git a/packages/client/src/scripts/initialize-sw.ts b/packages/client/src/scripts/initialize-sw.ts index 7d3b265bc..584a023ef 100644 --- a/packages/client/src/scripts/initialize-sw.ts +++ b/packages/client/src/scripts/initialize-sw.ts @@ -9,7 +9,7 @@ export async function initializeSw() { navigator.serviceWorker.register('/sw.js', { scope: '/', type: 'classic' }); navigator.serviceWorker.ready.then(registration => { registration.active?.postMessage({ - msg: 'initialize', + type: 'initialize', lang, }); diff --git a/packages/sw/src/sw.ts b/packages/sw/src/sw.ts index 35eeb1f28..176f00b4e 100644 --- a/packages/sw/src/sw.ts +++ b/packages/sw/src/sw.ts @@ -163,24 +163,14 @@ self.addEventListener('notificationclose', { ev.waitUntil((async () => { - switch (ev.data) { - case 'clear': - // Cache Storage全削除 - await caches.keys() - .then(cacheNames => Promise.all( - cacheNames.map(name => caches.delete(name)) - )); - return; // TODO - } - if (typeof ev.data === 'object') { - // E.g. '[object Array]' → 'array' - const otype = Object.prototype.toString.call(ev.data).slice(8, -1).toLowerCase(); - - if (otype === 'object') { - if (ev.data.msg === 'initialize') { + switch (ev.data.type) { + case 'initialize': swLang.setLang(ev.data.lang); - } + break; + case 'notification': + createNotification(ev.data); + break; } } })());