From 5e7d151cad82bb0ffb1d85fb0f9723fe471282a0 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Thu, 27 Feb 2020 20:25:37 -0500 Subject: [PATCH] fix update listening --- src/app/services/service-worker.service.ts | 12 ++++++++++-- src/manifest.json | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/app/services/service-worker.service.ts b/src/app/services/service-worker.service.ts index 2b9dc9ca..2c2ab0f9 100644 --- a/src/app/services/service-worker.service.ts +++ b/src/app/services/service-worker.service.ts @@ -10,6 +10,8 @@ export class ServiceWorkerService { newAppVersionIsAvailable = new BehaviorSubject(false); + private isListening = false; + constructor(appRef: ApplicationRef, updates: SwUpdate) { //https://angular.io/guide/service-worker-communications @@ -30,8 +32,14 @@ export class ServiceWorkerService { // }); const updateCheckTimer$ = interval(6 * 60 * 60 * 1000); - updateCheckTimer$.subscribe(() => { - updates.checkForUpdate(); + + appRef.isStable.subscribe(() => { + if (this.isListening) return; + this.isListening = true; + + updateCheckTimer$.subscribe(() => { + updates.checkForUpdate(); + }); }); } diff --git a/src/manifest.json b/src/manifest.json index 39dc07fa..0133f778 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -5,7 +5,7 @@ "background_color": "#fafafa", "display": "standalone", "scope": "/", - "start_url": "/index.html", + "start_url": "/", "icons": [ { "src": "assets/icons/icon-72x72.png",