mirror of https://github.com/vector-im/riot-web
Apply suggestions from code review
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>pull/27326/head
parent
d4efdf221a
commit
37e3dfdb36
|
@ -45,8 +45,8 @@ export default class WebPlatform extends VectorBasePlatform {
|
||||||
public constructor() {
|
public constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
// noinspection JSIgnoredPromiseFromCall - can run async
|
// Register the service worker in the background
|
||||||
this.tryRegisterServiceWorker();
|
this.tryRegisterServiceWorker().catch((e) => console.error("Error registering/updating service worker:", e));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async tryRegisterServiceWorker(): Promise<void> {
|
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`
|
// sw.js is exported by webpack, sourced from `/src/serviceworker/index.ts`
|
||||||
const swPromise = navigator.serviceWorker.register("sw.js");
|
const registration = await navigator.serviceWorker.register("sw.js");
|
||||||
if (!swPromise) {
|
if (!registration) {
|
||||||
// Registration didn't return a promise for some reason - assume failed and ignore.
|
// Registration didn't work for some reason - assume failed and ignore.
|
||||||
// This typically happens in Jest.
|
// This typically happens in Jest.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const registration = await swPromise;
|
|
||||||
await registration.update();
|
await registration.update();
|
||||||
navigator.serviceWorker.addEventListener("message", this.onServiceWorkerPostMessage.bind(this));
|
navigator.serviceWorker.addEventListener("message", this.onServiceWorkerPostMessage.bind(this));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue