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