From c6eda35cc0ec8696cbc580fe5318012b04846ddd Mon Sep 17 00:00:00 2001
From: AUBRY JEAN-PASCAL <jean-pascal.aubry@inrae.fr>
Date: Mon, 4 Dec 2023 08:57:04 +0100
Subject: [PATCH] =?UTF-8?q?Resolve=20"PWA:=20L'application=20ne=20se=20met?=
 =?UTF-8?q?=20pas=20=C3=A0=20jour=20sur=20Firefox=20et=20Safari"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ngsw-config-template.json                      |  4 ++--
 .../services/service-worker-update.service.ts  | 18 +++++++++---------
 src/locale/messages.en.json                    |  2 +-
 src/locale/messages.fr.json                    |  2 +-
 4 files changed, 13 insertions(+), 13 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"
         ]
       }
     }
diff --git a/src/app/services/service-worker-update.service.ts b/src/app/services/service-worker-update.service.ts
index 163fd4a12..857a66278 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,
@@ -28,11 +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);
+                    this.notificationService.notify(this.i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_DETECTED", { "ver": ver }), 10000);
                     break;
 
                 case 'VERSION_READY':
@@ -40,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);
                     // -> 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();
@@ -60,15 +61,14 @@ export class ServiceWorkerUpdateService {
                     break;
 
                 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);
+                    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;
             }
         });
         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);
         });
     }
 }
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