fix serviceworker registration and update check
This commit is contained in:
parent
55edfbd24a
commit
0cd16fd0de
|
@ -128,10 +128,7 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
closeAutoUpdate(): boolean {
|
closeAutoUpdate(): boolean {
|
||||||
this.updateAvailable = false;
|
this.updateAvailable = false;
|
||||||
setTimeout(() => {
|
|
||||||
this.updateAvailable = true;
|
|
||||||
}, 2000);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ export class ServiceWorkerService {
|
||||||
constructor(appRef: ApplicationRef, updates: SwUpdate) {
|
constructor(appRef: ApplicationRef, updates: SwUpdate) {
|
||||||
|
|
||||||
//https://angular.io/guide/service-worker-communications
|
//https://angular.io/guide/service-worker-communications
|
||||||
|
|
||||||
updates.available.subscribe(event => {
|
updates.available.subscribe(event => {
|
||||||
console.log('current version is', event.current);
|
console.log('current version is', event.current);
|
||||||
console.log('available version is', event.available);
|
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()`.
|
// Allow the app to stabilize first, before starting polling for updates with `interval()`.
|
||||||
const appIsStable$ = appRef.isStable.pipe(first(isStable => isStable === true));
|
//const appIsStable$ = appRef.isStable.pipe(first(isStable => isStable === true));
|
||||||
const everySixHours$ = interval(2 * 60 * 60 * 1000);
|
// const everySixHoursOnceAppIsStable$ = concat(appIsStable$, everySixHours$);
|
||||||
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() {
|
loadNewAppVersion() {
|
||||||
|
|
|
@ -5,8 +5,13 @@ import { AppModule } from './app/app.module';
|
||||||
import { environment } from './environments/environment';
|
import { environment } from './environments/environment';
|
||||||
|
|
||||||
if (environment.production) {
|
if (environment.production) {
|
||||||
enableProdMode();
|
enableProdMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
platformBrowserDynamic().bootstrapModule(AppModule)
|
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));
|
||||||
|
|
Loading…
Reference in New Issue