import {Injectable} from '@angular/core'; import {Http} from "@angular/http"; import {Observable} from "rxjs/Observable"; @Injectable() export class SelfUpdaterService { private appRevision: number = 0; private initFailed: boolean = false; constructor(private httpService: Http) { console.log("init"); this.getDeployedRevision().subscribe( result => this.appRevision = result, () => { console.log( "%c Couldn't load initial revision data from server. Self update disabled.", "background: #222; color: #bada55;" ); this.initFailed = true; } ); } private getDeployedRevision(): Observable { return this.httpService.get("/revision.json").map(result => result.json()); } public checkAndReloadIfNecessary() { if (!this.initFailed) { this.getDeployedRevision().subscribe( result => { if (result > this.appRevision) { document.location.reload(true); } }, () => {} ); } } }