From 5ca4aefff4a989cd48b65b680135a2de79c7083b Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 24 Jan 2021 18:17:42 +0900 Subject: [PATCH] :v: --- src/client/init.ts | 6 ++++-- src/client/sw/sw.ts | 1 + src/server/web/boot.js | 4 ---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/client/init.ts b/src/client/init.ts index 6c1645867e..870304ddef 100644 --- a/src/client/init.ts +++ b/src/client/init.ts @@ -173,8 +173,10 @@ fetchInstance().then(() => { // Init service worker if (instance.swPublickey && ('serviceWorker' in navigator) && - ('PushManager' in window) && $i && $i.token - ) { + ('PushManager' in window) && + $i && $i.token) { + navigator.serviceWorker.register(`/sw.js`); + navigator.serviceWorker.ready.then(registration => { registration.active?.postMessage({ msg: 'initialize', diff --git a/src/client/sw/sw.ts b/src/client/sw/sw.ts index 25dea0e944..c92cae1292 100644 --- a/src/client/sw/sw.ts +++ b/src/client/sw/sw.ts @@ -98,6 +98,7 @@ self.addEventListener('message', ev => { } 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') { diff --git a/src/server/web/boot.js b/src/server/web/boot.js index 395128b8af..2bd306ea94 100644 --- a/src/server/web/boot.js +++ b/src/server/web/boot.js @@ -72,10 +72,6 @@ head.appendChild(script); //#endregion - //#region Service Worker - navigator.serviceWorker.register(`/sw.js`); - //#endregion - //#region Theme const theme = localStorage.getItem('theme'); if (theme) {