Skip to content
Snippets Groups Projects

Resolve "PWA: L'application ne se met pas à jour sur Firefox et Safari"

Files
4
@@ -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);
});
}
}
Loading