From e077d9ca5fada912fec4a1b06ba1c6ffc4b71a25 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 15 Jan 2021 12:25:21 +0000 Subject: [PATCH] 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.