Commit b2fddef4 authored by Grand Francois's avatar Grand Francois
Browse files

fix: update failure due to error in service worker update service (VERSION_READY case)

refs #604
Showing with 18 additions and 11 deletions
+18 -11
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { SwUpdate } from '@angular/service-worker'; import { SwUpdate, VersionEvent } from '@angular/service-worker';
import { I18nService } from "./internationalisation.service"; import { I18nService } from "./internationalisation.service";
import { NotificationsService } from "./notifications.service"; import { NotificationsService } from "./notifications.service";
...@@ -13,26 +13,33 @@ export class ServiceWorkerUpdateService { ...@@ -13,26 +13,33 @@ export class ServiceWorkerUpdateService {
swUpdate.versionUpdates.subscribe(evt => { swUpdate.versionUpdates.subscribe(evt => {
switch (evt.type) { switch (evt.type) {
case 'VERSION_DETECTED': case 'VERSION_DETECTED':
let ver = evt.version.appData["version"]; let ver = (evt as any).version?.appData?.version ?? "<NA>";
let msg = i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_DETECTED", { "ver": ver }); console.log("SwUpdate VERSION_DETECTED", ver);
notificationService.notify(msg, 10000); notificationService.notify(i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_DETECTED", { "ver": ver }), 10000);
break; break;
case 'VERSION_READY': case 'VERSION_READY':
const newVer = evt.latestVersion.appData["version"]; const currVer = (evt as any).currentVersion?.appData?.version ?? "<NA>";
// const currVer = evt.currentVersion.appData["version"]; const newVer = (evt as any).latestVersion?.appData?.version ?? "<NA>";
msg = i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_READY", { "ver": newVer }); console.log("SwUpdate VERSION_READY", currVer, newVer);
notificationService.notify(msg, 10000);
notificationService.notify(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 !!!
break; break;
case 'VERSION_INSTALLATION_FAILED': case 'VERSION_INSTALLATION_FAILED':
ver = evt.version.appData["version"]; ver = (evt as any).version?.appData?.version ?? "NA";
msg = i18nService.localizeText("ERROR_SERVICE_WORKER_INSTALL_FAILED", { "ver": ver }); console.log("SwUpdate VERSION_INSTALLATION_FAILED", ver);
notificationService.notify(msg, 10000); notificationService.notify(i18nService.localizeText("ERROR_SERVICE_WORKER_INSTALL_FAILED", { "ver": ver }), 10000);
break; break;
} }
}); });
swUpdate.unrecoverable.subscribe(event => { swUpdate.unrecoverable.subscribe(event => {
console.log("SwUpdate.unrecoverable", event.reason, event.type);
notificationService.notify("SwUpdate: unrecoverable state. Reason=" + event.reason + ", type=" + event.type, 10000); notificationService.notify("SwUpdate: unrecoverable state. Reason=" + event.reason + ", type=" + event.type, 10000);
}); });
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment