diff --git a/ngsw-config.json b/ngsw-config.json index 6c8ccf4..9ebbe89 100644 --- a/ngsw-config.json +++ b/ngsw-config.json @@ -1,6 +1,7 @@ { "$schema": "./node_modules/@angular/service-worker/config/schema.json", "index": "/index.html", + "navigationRequestStrategy": "freshness", "assetGroups": [ { "name": "app", diff --git a/package.json b/package.json index 729f143..341a816 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "WorkTime", - "version": "0.3.3", + "version": "0.3.4", "author": "Ionic Framework", "homepage": "https://ionicframework.com/", "scripts": { diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 9091b3a..f972550 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -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(); + } + } }