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

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

View File

@ -13,7 +13,7 @@ export class ServiceWorkerService {
constructor(appRef: ApplicationRef, updates: SwUpdate) {
//https://angular.io/guide/service-worker-communications
updates.available.subscribe(event => {
console.log('current version is', event.current);
console.log('available version is', event.available);
@ -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

@ -5,8 +5,13 @@ import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
.then(() => {
if ('serviceWorker' in navigator && environment.production) {
navigator.serviceWorker.register('./ngsw-worker.js');
}
})
.catch(err => console.log(err));