Check app updates
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
import { SwUpdate } from '@angular/service-worker';
|
||||
import { NotificationsService } from './services/notifications.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@@ -9,5 +11,30 @@ import { RouterOutlet } from '@angular/router';
|
||||
imports: [RouterOutlet]
|
||||
})
|
||||
export class AppComponent {
|
||||
title = 'DiunaBI';
|
||||
}
|
||||
constructor(
|
||||
private readonly _swUpdate: SwUpdate,
|
||||
private _notifications: NotificationsService
|
||||
) {
|
||||
this._swUpdate.versionUpdates.subscribe((evt) => {
|
||||
console.log('Version update', evt);
|
||||
if (evt.type === 'VERSION_READY') {
|
||||
this._swUpdate.activateUpdate().then(() => {
|
||||
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"
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user