From 87e67d81680ae3741f6757fb4322aee061ec21b5 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 15 Jan 2021 11:05:27 +0000 Subject: [PATCH 1/3] Skip the service worker for Electron At the moment, there's no point in installing the empty service worker on Electron. Fixes https://github.com/vector-im/element-web/issues/16008 --- src/vector/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector/index.ts b/src/vector/index.ts index d9c63755f6..37cf623d88 100644 --- a/src/vector/index.ts +++ b/src/vector/index.ts @@ -30,7 +30,7 @@ import {parseQsFromFragment} from "./url_utils"; import './modernizr'; // load service worker if available on this platform -if ('serviceWorker' in navigator) { +if (!window.electron && 'serviceWorker' in navigator) { navigator.serviceWorker.register('sw.js'); } From e077d9ca5fada912fec4a1b06ba1c6ffc4b71a25 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 15 Jan 2021 12:25:21 +0000 Subject: [PATCH 2/3] Move service worker into platform --- src/vector/index.ts | 5 ----- src/vector/init.tsx | 2 ++ src/vector/platform/WebPlatform.ts | 6 ++++++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/vector/index.ts b/src/vector/index.ts index 37cf623d88..02e2025c91 100644 --- a/src/vector/index.ts +++ b/src/vector/index.ts @@ -29,11 +29,6 @@ require('katex/dist/katex.css'); import {parseQsFromFragment} from "./url_utils"; import './modernizr'; -// load service worker if available on this platform -if (!window.electron && 'serviceWorker' in navigator) { - navigator.serviceWorker.register('sw.js'); -} - async function settled(...promises: Array>) { for (const prom of promises) { try { diff --git a/src/vector/init.tsx b/src/vector/init.tsx index de022622db..bb5e968c7c 100644 --- a/src/vector/init.tsx +++ b/src/vector/init.tsx @@ -49,6 +49,8 @@ export function preparePlatform() { console.log("Using Web platform"); PlatformPeg.set(new WebPlatform()); } + // Register service worker if available on this platform + PlatformPeg.get().registerServiceWorker(); } export async function loadConfig() { diff --git a/src/vector/platform/WebPlatform.ts b/src/vector/platform/WebPlatform.ts index ee399c8c8c..33e37edfe8 100644 --- a/src/vector/platform/WebPlatform.ts +++ b/src/vector/platform/WebPlatform.ts @@ -38,6 +38,12 @@ export default class WebPlatform extends VectorBasePlatform { return 'Web Platform'; // no translation required: only used for analytics } + registerServiceWorker(): void { + if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('sw.js'); + } + } + /** * Returns true if the platform supports displaying * notifications, otherwise false. From 0bbcda09af8d1053ee57655e4df0909f42d2770f Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 15 Jan 2021 12:35:42 +0000 Subject: [PATCH 3/3] Move into constructor --- src/vector/init.tsx | 2 -- src/vector/platform/WebPlatform.ts | 12 +++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/vector/init.tsx b/src/vector/init.tsx index bb5e968c7c..de022622db 100644 --- a/src/vector/init.tsx +++ b/src/vector/init.tsx @@ -49,8 +49,6 @@ export function preparePlatform() { console.log("Using Web platform"); PlatformPeg.set(new WebPlatform()); } - // Register service worker if available on this platform - PlatformPeg.get().registerServiceWorker(); } export async function loadConfig() { diff --git a/src/vector/platform/WebPlatform.ts b/src/vector/platform/WebPlatform.ts index 33e37edfe8..9f9f4a3995 100644 --- a/src/vector/platform/WebPlatform.ts +++ b/src/vector/platform/WebPlatform.ts @@ -34,16 +34,18 @@ const POKE_RATE_MS = 10 * 60 * 1000; // 10 min export default class WebPlatform extends VectorBasePlatform { private runningVersion: string = null; - getHumanReadableName(): string { - return 'Web Platform'; // no translation required: only used for analytics - } - - registerServiceWorker(): void { + constructor() { + super(); + // Register service worker if available on this platform if ('serviceWorker' in navigator) { navigator.serviceWorker.register('sw.js'); } } + getHumanReadableName(): string { + return 'Web Platform'; // no translation required: only used for analytics + } + /** * Returns true if the platform supports displaying * notifications, otherwise false.