From a2cd1ba57e001aeb360e325de7f8f15fba51dc78 Mon Sep 17 00:00:00 2001
From: Jean-Pascal <jean-pascal.aubry@inrae.fr>
Date: Fri, 1 Dec 2023 10:12:22 +0100
Subject: [PATCH 1/8] fix: push to test pwa

---
 src/app/services/service-worker-update.service.ts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/app/services/service-worker-update.service.ts b/src/app/services/service-worker-update.service.ts
index 163fd4a12..0d5a4404d 100644
--- a/src/app/services/service-worker-update.service.ts
+++ b/src/app/services/service-worker-update.service.ts
@@ -33,6 +33,7 @@ export class ServiceWorkerUpdateService {
                     let ver = (evt as any).version?.appData?.version ?? "<NA>";
                     console.log("ServiceWorkerUpdateService: VERSION_DETECTED", ver);
                     notificationService.notify(i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_DETECTED", { "ver": ver }), 10000);
+                    console.log("test");
                     break;
 
                 case 'VERSION_READY':
-- 
GitLab


From 6a02ca1c4fcbc98fb046e0ed433379fb8229e9a0 Mon Sep 17 00:00:00 2001
From: Jean-Pascal <jean-pascal.aubry@inrae.fr>
Date: Fri, 1 Dec 2023 11:15:23 +0100
Subject: [PATCH 2/8] bug: push to test pwa on mozilla android Refs #633

---
 src/app/services/service-worker-update.service.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/app/services/service-worker-update.service.ts b/src/app/services/service-worker-update.service.ts
index 0d5a4404d..b991b629d 100644
--- a/src/app/services/service-worker-update.service.ts
+++ b/src/app/services/service-worker-update.service.ts
@@ -33,7 +33,7 @@ export class ServiceWorkerUpdateService {
                     let ver = (evt as any).version?.appData?.version ?? "<NA>";
                     console.log("ServiceWorkerUpdateService: VERSION_DETECTED", ver);
                     notificationService.notify(i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_DETECTED", { "ver": ver }), 10000);
-                    console.log("test");
+                    console.log("test mozilla on android");
                     break;
 
                 case 'VERSION_READY':
-- 
GitLab


From 299eb7b701c045cf4424b8d863be5f78264f7429 Mon Sep 17 00:00:00 2001
From: Dorch <14124454+DDorch@users.noreply.github.com>
Date: Sun, 3 Dec 2023 16:29:52 +0000
Subject: [PATCH 3/8] fix: class properties ServiceWorkerUpdateService

Refs #633
---
 .../services/service-worker-update.service.ts  | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/app/services/service-worker-update.service.ts b/src/app/services/service-worker-update.service.ts
index b991b629d..621b0154b 100644
--- a/src/app/services/service-worker-update.service.ts
+++ b/src/app/services/service-worker-update.service.ts
@@ -28,12 +28,12 @@ export class ServiceWorkerUpdateService {
         }
 
         this.swUpdate.versionUpdates.subscribe(evt => {
+            console.log("ServiceWorkerUpdateService event:", evt.type);
             switch (evt.type) {
                 case 'VERSION_DETECTED':
                     let ver = (evt as any).version?.appData?.version ?? "<NA>";
                     console.log("ServiceWorkerUpdateService: VERSION_DETECTED", ver);
-                    notificationService.notify(i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_DETECTED", { "ver": ver }), 10000);
-                    console.log("test mozilla on android");
+                    this.notificationService.notify(this.i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_DETECTED", { "ver": ver }), 10000);
                     break;
 
                 case 'VERSION_READY':
@@ -41,15 +41,15 @@ export class ServiceWorkerUpdateService {
                     const newVer = (evt as any).latestVersion?.appData?.version ?? "<NA>";
                     console.log("ServiceWorkerUpdateService: VERSION_READY", currVer, "->", newVer);
 
-                    notificationService.notify(i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_READY", { "ver": newVer }), 10000);
+                    this.notificationService.notify(this.i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_READY", { "ver": newVer }), 10000);
                     // PLANTE si on stocke le message dans une variable !!!!
-                    // const msg = i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_READY", { "ver": newVer });
-                    // notificationService.notify(msg, 10000);
+                    // const msg = this.i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_READY", { "ver": newVer });
+                    // this.notificationService.notify(msg, 10000);
                     // -> ReferenceError: can't access lexical declaration 'xxx' before initialization
                     // avec xxx qui varie d'une fois à l'autre !!!
 
-                    userConfirmationService.askUserConfirmation("Confirmation",
-                        i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_READY", { "ver": newVer })).then(data => {
+                    this.userConfirmationService.askUserConfirmation("Confirmation",
+                        this.i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_READY", { "ver": newVer })).then(data => {
                             if (data["confirm"]) {
                                 console.log("ServiceWorkerUpdateService: application update confirmed");
                                 window.location.reload();
@@ -63,13 +63,13 @@ export class ServiceWorkerUpdateService {
                 case 'VERSION_INSTALLATION_FAILED':
                     ver = (evt as any).version?.appData?.version ?? "NA";
                     console.log("ServiceWorkerUpdateService: VERSION_INSTALLATION_FAILED", ver);
-                    notificationService.notify(i18nService.localizeText("ERROR_SERVICE_WORKER_INSTALL_FAILED", { "ver": ver }), 10000);
+                    this.notificationService.notify(this.i18nService.localizeText("ERROR_SERVICE_WORKER_INSTALL_FAILED", { "ver": ver }), 10000);
                     break;
             }
         });
         swUpdate.unrecoverable.subscribe(event => {
             console.log("SwUpdate.unrecoverable reason", event.reason, "type", event.type);
-            notificationService.notify("SwUpdate: unrecoverable state. Reason=" + event.reason + ", type=" + event.type, 10000);
+            this.notificationService.notify("SwUpdate: unrecoverable state. Reason=" + event.reason + ", type=" + event.type, 10000);
         });
     }
 }
-- 
GitLab


From 5fe1b20d602310ae127504c498c079f17013fa15 Mon Sep 17 00:00:00 2001
From: Dorch <14124454+DDorch@users.noreply.github.com>
Date: Sun, 3 Dec 2023 17:36:36 +0000
Subject: [PATCH 4/8] chore: put back original comments

Refs #633
---
 src/app/services/service-worker-update.service.ts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/app/services/service-worker-update.service.ts b/src/app/services/service-worker-update.service.ts
index 621b0154b..3dc0cd48d 100644
--- a/src/app/services/service-worker-update.service.ts
+++ b/src/app/services/service-worker-update.service.ts
@@ -43,8 +43,8 @@ export class ServiceWorkerUpdateService {
 
                     this.notificationService.notify(this.i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_READY", { "ver": newVer }), 10000);
                     // PLANTE si on stocke le message dans une variable !!!!
-                    // const msg = this.i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_READY", { "ver": newVer });
-                    // this.notificationService.notify(msg, 10000);
+                    // const msg = i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_READY", { "ver": newVer });
+                    // notificationService.notify(msg, 10000);
                     // -> ReferenceError: can't access lexical declaration 'xxx' before initialization
                     // avec xxx qui varie d'une fois à l'autre !!!
 
-- 
GitLab


From ed11d12447347b6b96e76169ccf5dbf4c773b2b9 Mon Sep 17 00:00:00 2001
From: Dorch <14124454+DDorch@users.noreply.github.com>
Date: Sun, 3 Dec 2023 19:00:34 +0000
Subject: [PATCH 5/8] fix: update ServiceWorker remove version in case of
 failed installation

Refs #633
---
 src/app/services/service-worker-update.service.ts | 5 ++---
 src/locale/messages.en.json                       | 2 +-
 src/locale/messages.fr.json                       | 2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/app/services/service-worker-update.service.ts b/src/app/services/service-worker-update.service.ts
index 3dc0cd48d..5869f53e5 100644
--- a/src/app/services/service-worker-update.service.ts
+++ b/src/app/services/service-worker-update.service.ts
@@ -61,9 +61,8 @@ export class ServiceWorkerUpdateService {
                     break;
 
                 case 'VERSION_INSTALLATION_FAILED':
-                    ver = (evt as any).version?.appData?.version ?? "NA";
-                    console.log("ServiceWorkerUpdateService: VERSION_INSTALLATION_FAILED", ver);
-                    this.notificationService.notify(this.i18nService.localizeText("ERROR_SERVICE_WORKER_INSTALL_FAILED", { "ver": ver }), 10000);
+                    console.log("ServiceWorkerUpdateService: VERSION_INSTALLATION_FAILED");
+                    this.notificationService.notify(this.i18nService.localizeText("ERROR_SERVICE_WORKER_INSTALL_FAILED"), 10000);
                     break;
             }
         });
diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json
index c8fd7869c..49d04bcaa 100755
--- a/src/locale/messages.en.json
+++ b/src/locale/messages.en.json
@@ -678,7 +678,7 @@
     "INFO_ESPECE_TITRE_COURT": "Species",
     "INFO_SERVICE_WORKER_VERSION_DETECTED": "Downloading Cassiopée version %ver%...",
     "INFO_SERVICE_WORKER_VERSION_READY": "Cassiopée version %ver% is ready to be used, please restart.",
-    "ERROR_SERVICE_WORKER_INSTALL_FAILED": "Cassiopée version %ver% installation failed.",
+    "ERROR_SERVICE_WORKER_INSTALL_FAILED": "Cassiopée new version installation failed.",
     "ERROR_JET_SUBMERGED_NO_SOLUTION": "There is no solution",
     "WARNING_DEVER_ZDV_INF_ZR": "Apron elevation of structure #%number% is below river bed elevation",
     "WARNING_JET_START_SUBMERGED": "Water elevation is greater than jet start elevation",
diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json
index 05ac13aef..764dfbbbf 100755
--- a/src/locale/messages.fr.json
+++ b/src/locale/messages.fr.json
@@ -679,7 +679,7 @@
     "INFO_ESPECE_TITRE_COURT": "Espèce",
     "INFO_SERVICE_WORKER_VERSION_DETECTED": "Téléchargement de la version %ver% de Cassiopée en cours...",
     "INFO_SERVICE_WORKER_VERSION_READY": "La version %ver% de Cassiopée est prête à être utilisée, veuillez redémarrer.",
-    "ERROR_SERVICE_WORKER_INSTALL_FAILED": "Erreur d'installation de Cassiopée version %ver%.",
+    "ERROR_SERVICE_WORKER_INSTALL_FAILED": "Erreur d'installation de la nouvelle version de Cassiopée.",
     "ERROR_JET_SUBMERGED_NO_SOLUTION": "Il n'y a pas de solution",
     "WARNING_DEVER_ZDV_INF_ZR": "La cote de radier de l'ouvrage n°%number% est sous la cote de fond du lit",
     "WARNING_JET_START_SUBMERGED": "La cote de l'eau est supérieure à la cote de départ du jet",
-- 
GitLab


From a05fbd9862ab0ac5d287b388208a7dcac6de03ce Mon Sep 17 00:00:00 2001
From: Dorch <14124454+DDorch@users.noreply.github.com>
Date: Sun, 3 Dec 2023 21:18:41 +0000
Subject: [PATCH 6/8] fix: service worker issue

Try root injection as in https://angular.io/guide/service-worker-communications and https://angular.io/guide/dependency-injection

Refs #633
---
 src/app/services/service-worker-update.service.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/app/services/service-worker-update.service.ts b/src/app/services/service-worker-update.service.ts
index 5869f53e5..5d98cc18d 100644
--- a/src/app/services/service-worker-update.service.ts
+++ b/src/app/services/service-worker-update.service.ts
@@ -5,7 +5,7 @@ import { NotificationsService } from "./notifications.service";
 import { UserConfirmationService } from "./user-confirmation.service";
 import { interval } from "rxjs";
 
-@Injectable()
+@Injectable({providedIn: 'root'})
 export class ServiceWorkerUpdateService {
     constructor(
         private swUpdate: SwUpdate,
-- 
GitLab


From 74b99d9f3f71ec7cdd109f3880e99ca4a6fb095a Mon Sep 17 00:00:00 2001
From: Dorch <14124454+DDorch@users.noreply.github.com>
Date: Mon, 4 Dec 2023 06:18:01 +0000
Subject: [PATCH 7/8] feat: add error log for failed update

Refs #366
---
 src/app/services/service-worker-update.service.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/app/services/service-worker-update.service.ts b/src/app/services/service-worker-update.service.ts
index 5d98cc18d..857a66278 100644
--- a/src/app/services/service-worker-update.service.ts
+++ b/src/app/services/service-worker-update.service.ts
@@ -61,7 +61,7 @@ export class ServiceWorkerUpdateService {
                     break;
 
                 case 'VERSION_INSTALLATION_FAILED':
-                    console.log("ServiceWorkerUpdateService: VERSION_INSTALLATION_FAILED");
+                    console.log(`Failed to install app version '${evt.version.hash}': ${evt.error}`);
                     this.notificationService.notify(this.i18nService.localizeText("ERROR_SERVICE_WORKER_INSTALL_FAILED"), 10000);
                     break;
             }
-- 
GitLab


From dd231be25f75f6169feee67158384a1bc8ec5cfa Mon Sep 17 00:00:00 2001
From: Dorch <14124454+DDorch@users.noreply.github.com>
Date: Mon, 4 Dec 2023 07:30:18 +0000
Subject: [PATCH 8/8] fix: service worker update issue

remove Matomo from the Service worker in order to avoid connectivity issue with ad blockers

Refs #633
---
 ngsw-config-template.json | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ngsw-config-template.json b/ngsw-config-template.json
index 7659ccaaf..3b0a4fbca 100644
--- a/ngsw-config-template.json
+++ b/ngsw-config-template.json
@@ -19,12 +19,12 @@
           "/*.css",
           "/*.js",
           "/*.json",
+          "/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2|eot)",
           "/3rdpartylicenses.txt",
-          "/MaterialIcons-Regular.1e50f5c2ffa6aba4.eot",
           "/assets/**",
           "!/**/*.pdf",
           "!/**/*.php",
-          "/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2)"
+          "!/assets/docs/javascripts/matomo-tracking.js"
         ]
       }
     }
-- 
GitLab