Move service worker into platform

This commit is contained in:
J. Ryan Stinnett 2021-01-15 12:25:21 +00:00
parent 87e67d8168
commit e077d9ca5f
3 changed files with 8 additions and 5 deletions

View file

@ -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<Promise<any>>) {
for (const prom of promises) {
try {

View file

@ -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() {

View file

@ -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.