fix(aio): when browser lacks service worker, disable sw feature

This commit is contained in:
Ward Bell 2017-04-03 11:48:46 -06:00 committed by Hans
parent 91b2e394d5
commit c530c5d317
1 changed files with 11 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { Injectable, OnDestroy } from '@angular/core';
import { Injectable, Injector, OnDestroy } from '@angular/core';
import { NgServiceWorker } from '@angular/service-worker';
import { Observable } from 'rxjs/Observable';
import { ReplaySubject } from 'rxjs/ReplaySubject';
@ -36,9 +36,13 @@ export class SwUpdatesService implements OnDestroy {
private onDestroy = new Subject();
private checkForUpdateSubj = new Subject();
private isUpdateAvailableSubj = new ReplaySubject<boolean>(1);
private sw: NgServiceWorker | NullServiceWorker = null;
isUpdateAvailable = this.isUpdateAvailableSubj.distinctUntilChanged();
isServiceWorkAvailable = !!navigator['serviceWorker'];
constructor(injector: Injector) {
this.sw = this.isServiceWorkAvailable ? injector.get(NgServiceWorker) : new NullServiceWorker();
constructor(private sw: NgServiceWorker) {
this.checkForUpdateSubj
.debounceTime(this.checkInterval)
.takeUntil(this.onDestroy)
@ -74,3 +78,8 @@ export class SwUpdatesService implements OnDestroy {
.subscribe(v => this.isUpdateAvailableSubj.next(v));
}
}
class NullServiceWorker {
checkForUpdate() { return Observable.of(false); }
activateUpdate(version: string) { return Observable.of(false); }
}