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.