taurus-tv/src/app/kanban/shared/self-updater.service.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

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<number> {
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);
}
},
() => {}
);
}
}
}