Added update detection

This commit is contained in:
2024-11-10 12:19:32 +01:00
parent effd1965dc
commit dc567d24c3
3 changed files with 36 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
import { Component } from '@angular/core';
import { IonApp, IonRouterOutlet } from '@ionic/angular/standalone';
import {AlertController, IonApp, IonRouterOutlet} from '@ionic/angular/standalone';
import {SwUpdate} from "@angular/service-worker";
@Component({
selector: 'app-root',
@@ -9,5 +10,36 @@ import { IonApp, IonRouterOutlet } from '@ionic/angular/standalone';
})
export class AppComponent {
public static currentDate: any;
constructor() {}
constructor(private updates: SwUpdate, private alerts: AlertController) {
if (updates.isEnabled) {
updates.checkForUpdate().then(async available => {
if (available) await this.showUpdateAlert();
});
}
}
private async showUpdateAlert() {
const alert = await this.alerts.create({
header: "Update verfügbar!",
message: 'Möchtest du das Update herunterladen?',
buttons: [
{
text: "Nein",
role: "cancel"
},
{
text: "Ja",
role: "destructive"
}
]
});
await alert.present();
const result = await alert.onDidDismiss();
if (result.role == "destructive") {
await this.updates.activateUpdate();
document.location.reload();
}
}
}