swUpdate fix
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { RouterOutlet } from '@angular/router';
|
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 { environment } from 'src/environments/environment';
|
||||||
import { NotificationsService } from './services/notifications.service';
|
import { NotificationsService } from './services/notifications.service';
|
||||||
import { filter } from 'rxjs';
|
import { filter } from 'rxjs';
|
||||||
@@ -17,10 +17,14 @@ export class AppComponent {
|
|||||||
private readonly _swUpdate: SwUpdate,
|
private readonly _swUpdate: SwUpdate,
|
||||||
private _notifications: NotificationsService
|
private _notifications: NotificationsService
|
||||||
) {
|
) {
|
||||||
|
this.subscribeUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribeUpdates() {
|
||||||
if (this._swUpdate.isEnabled && environment.production) {
|
if (this._swUpdate.isEnabled && environment.production) {
|
||||||
this._swUpdate.versionUpdates
|
this._swUpdate.versionUpdates.subscribe((evt: VersionEvent) => {
|
||||||
.pipe(filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY'))
|
switch (evt.type) {
|
||||||
.subscribe((evt) => {
|
case 'VERSION_READY': {
|
||||||
this._notifications.add({
|
this._notifications.add({
|
||||||
text: "New version available. DiunaBI will restart in 10 seconds.",
|
text: "New version available. DiunaBI will restart in 10 seconds.",
|
||||||
duration: 10000,
|
duration: 10000,
|
||||||
@@ -35,8 +39,10 @@ export class AppComponent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user