swUpdate fix
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user