From 05f67ff9f3a720fb090841302444b26b9ca1644e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Tue, 7 Nov 2023 12:57:35 +0100 Subject: [PATCH] swUpdate fix --- Frontend/src/app/app.component.ts | 48 +++++++++++++++++-------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/Frontend/src/app/app.component.ts b/Frontend/src/app/app.component.ts index b8febb4..8f25100 100644 --- a/Frontend/src/app/app.component.ts +++ b/Frontend/src/app/app.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import { RouterOutlet } from '@angular/router'; -import { SwUpdate, VersionReadyEvent } from '@angular/service-worker'; +import { SwUpdate, VersionEvent, VersionReadyEvent } from '@angular/service-worker'; import { environment } from 'src/environments/environment'; import { NotificationsService } from './services/notifications.service'; import { filter } from 'rxjs'; @@ -17,26 +17,32 @@ export class AppComponent { private readonly _swUpdate: SwUpdate, private _notifications: NotificationsService ) { - if (this._swUpdate.isEnabled && environment.production) { - this._swUpdate.versionUpdates - .pipe(filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY')) - .subscribe((evt) => { - this._notifications.add({ - text: "New version available. DiunaBI will restart in 10 seconds.", - duration: 10000, - dismiss: () => { - window.location.reload() - }, - btn: 'Cancel', - action: () => { - this._notifications.add({ - text: "Restart canceled.", - btn: "Hide" - }); - } - }) - }); - } + this.subscribeUpdates(); + } + subscribeUpdates() { + if (this._swUpdate.isEnabled && environment.production) { + this._swUpdate.versionUpdates.subscribe((evt: VersionEvent) => { + switch (evt.type) { + case 'VERSION_READY': { + this._notifications.add({ + text: "New version available. DiunaBI will restart in 10 seconds.", + duration: 10000, + dismiss: () => { + window.location.reload() + }, + btn: 'Cancel', + action: () => { + this._notifications.add({ + text: "Restart canceled.", + btn: "Hide" + }); + } + }) + break; + } + } + }); + } } }