fix(aio): when browser lacks service worker, disable sw feature
This commit is contained in:
parent
91b2e394d5
commit
c530c5d317
|
@ -1,4 +1,4 @@
|
||||||
import { Injectable, OnDestroy } from '@angular/core';
|
import { Injectable, Injector, OnDestroy } from '@angular/core';
|
||||||
import { NgServiceWorker } from '@angular/service-worker';
|
import { NgServiceWorker } from '@angular/service-worker';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { ReplaySubject } from 'rxjs/ReplaySubject';
|
import { ReplaySubject } from 'rxjs/ReplaySubject';
|
||||||
|
@ -36,9 +36,13 @@ export class SwUpdatesService implements OnDestroy {
|
||||||
private onDestroy = new Subject();
|
private onDestroy = new Subject();
|
||||||
private checkForUpdateSubj = new Subject();
|
private checkForUpdateSubj = new Subject();
|
||||||
private isUpdateAvailableSubj = new ReplaySubject<boolean>(1);
|
private isUpdateAvailableSubj = new ReplaySubject<boolean>(1);
|
||||||
|
private sw: NgServiceWorker | NullServiceWorker = null;
|
||||||
isUpdateAvailable = this.isUpdateAvailableSubj.distinctUntilChanged();
|
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
|
this.checkForUpdateSubj
|
||||||
.debounceTime(this.checkInterval)
|
.debounceTime(this.checkInterval)
|
||||||
.takeUntil(this.onDestroy)
|
.takeUntil(this.onDestroy)
|
||||||
|
@ -74,3 +78,8 @@ export class SwUpdatesService implements OnDestroy {
|
||||||
.subscribe(v => this.isUpdateAvailableSubj.next(v));
|
.subscribe(v => this.isUpdateAvailableSubj.next(v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NullServiceWorker {
|
||||||
|
checkForUpdate() { return Observable.of(false); }
|
||||||
|
activateUpdate(version: string) { return Observable.of(false); }
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue