fix serviceworker registration and update check

This commit is contained in:
Nicolas Constant 2020-02-27 00:12:18 -05:00
parent 55edfbd24a
commit 0cd16fd0de
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 19 additions and 11 deletions

View File

@ -129,9 +129,6 @@ export class AppComponent implements OnInit, OnDestroy {
closeAutoUpdate(): boolean {
this.updateAvailable = false;
setTimeout(() => {
this.updateAvailable = true;
}, 2000);
return false;
}
}

View File

@ -22,11 +22,17 @@ export class ServiceWorkerService {
});
// 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(2 * 60 * 60 * 1000);
const everySixHoursOnceAppIsStable$ = concat(appIsStable$, everySixHours$);
//const appIsStable$ = appRef.isStable.pipe(first(isStable => isStable === true));
// const everySixHoursOnceAppIsStable$ = concat(appIsStable$, everySixHours$);
// everySixHoursOnceAppIsStable$.subscribe(() => {
// console.warn('wat?');
// updates.checkForUpdate();
// });
everySixHoursOnceAppIsStable$.subscribe(() => updates.checkForUpdate());
const updateCheckTimer$ = interval(2 * 60 * 60 * 1000);
updateCheckTimer$.subscribe(() => {
updates.checkForUpdate();
});
}
loadNewAppVersion() {

View File

@ -9,4 +9,9 @@ if (environment.production) {
}
platformBrowserDynamic().bootstrapModule(AppModule)
.then(() => {
if ('serviceWorker' in navigator && environment.production) {
navigator.serviceWorker.register('./ngsw-worker.js');
}
})
.catch(err => console.log(err));