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 {
|
||||
this.updateAvailable = false;
|
||||
setTimeout(() => {
|
||||
this.updateAvailable = true;
|
||||
}, 2000);
|
||||
this.updateAvailable = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue