2019-01-09 18:44:47 +02:00
|
|
|
import { ApplicationRef, Injectable } from '@angular/core';
|
2017-11-27 13:48:32 -05:00
|
|
|
import { SwUpdate } from '@angular/service-worker';
|
2019-01-09 18:44:47 +02:00
|
|
|
import { concat, interval } from 'rxjs';
|
|
|
|
|
import { first } from 'rxjs/operators';
|
2017-12-06 18:12:19 -08:00
|
|
|
|
2017-11-27 13:48:32 -05:00
|
|
|
@Injectable()
|
|
|
|
|
export class CheckForUpdateService {
|
|
|
|
|
|
2019-01-09 18:44:47 +02:00
|
|
|
constructor(appRef: ApplicationRef, updates: SwUpdate) {
|
|
|
|
|
// Allow the app to stabilize first, before starting polling for updates with `interval()`.
|
|
|
|
|
const appIsStable$ = appRef.isStable.pipe(first(isStable => isStable === true));
|
|
|
|
|
const everySixHours$ = interval(6 * 60 * 60 * 1000);
|
|
|
|
|
const everySixHoursOnceAppIsStable$ = concat(appIsStable$, everySixHours$);
|
|
|
|
|
|
|
|
|
|
everySixHoursOnceAppIsStable$.subscribe(() => updates.checkForUpdate());
|
2017-11-27 13:48:32 -05:00
|
|
|
}
|
|
|
|
|
}
|