swUpdate fix

This commit is contained in:
Michał Zieliński
2023-11-07 12:57:35 +01:00
parent 2d9fd3e42d
commit 05f67ff9f3

View File

@@ -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,10 +17,14 @@ export class AppComponent {
private readonly _swUpdate: SwUpdate,
private _notifications: NotificationsService
) {
this.subscribeUpdates();
}
subscribeUpdates() {
if (this._swUpdate.isEnabled && environment.production) {
this._swUpdate.versionUpdates
.pipe(filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY'))
.subscribe((evt) => {
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,
@@ -35,8 +39,10 @@ export class AppComponent {
});
}
})
break;
}
}
});
}
}
}