Apply suggestions from code review

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
pull/27326/head
Travis Ralston 2024-05-01 09:42:36 -06:00 committed by GitHub
parent d4efdf221a
commit 37e3dfdb36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 7 deletions

View File

@ -45,8 +45,8 @@ export default class WebPlatform extends VectorBasePlatform {
public constructor() {
super();
// noinspection JSIgnoredPromiseFromCall - can run async
this.tryRegisterServiceWorker();
// Register the service worker in the background
this.tryRegisterServiceWorker().catch((e) => console.error("Error registering/updating service worker:", e));
}
private async tryRegisterServiceWorker(): Promise<void> {
@ -55,15 +55,14 @@ export default class WebPlatform extends VectorBasePlatform {
}
// sw.js is exported by webpack, sourced from `/src/serviceworker/index.ts`
const swPromise = navigator.serviceWorker.register("sw.js");
if (!swPromise) {
// Registration didn't return a promise for some reason - assume failed and ignore.
const registration = await navigator.serviceWorker.register("sw.js");
if (!registration) {
// Registration didn't work for some reason - assume failed and ignore.
// This typically happens in Jest.
return;
}
try {
const registration = await swPromise;
await registration.update();
navigator.serviceWorker.addEventListener("message", this.onServiceWorkerPostMessage.bind(this));
} catch (e) {