Check app updates

This commit is contained in:
2023-06-23 16:23:18 +02:00
parent e83f7b6311
commit 985ba7dccc
4 changed files with 52 additions and 17 deletions

View File

@@ -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"
});
}
})
});
}
})
}
}