diff --git a/ngsw-config.json b/ngsw-config.json index ccb8dea0ac4d75dd8ee527a1385776e21b7447cd..be36d5d04f5556769f48f3e5c91040da62b86156 100644 --- a/ngsw-config.json +++ b/ngsw-config.json @@ -17,6 +17,7 @@ { "name": "app", "installMode": "prefetch", + "updateMode": "prefetch", "resources": { "files": [ "/favicon.ico", diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 7194712b953b266b4b98869ac68aef5275dd6a9a..398d380c90cd149f47bbafbaad322d72c2bdff87 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,4 +1,4 @@ -import { APP_INITIALIZER } from '@angular/core'; +/*import { APP_INITIALIZER } from '@angular/core'; import { initializeApp } from './app.module'; import { AppConfig } from './app.config'; import { TestBed, async } from '@angular/core/testing'; @@ -41,4 +41,4 @@ describe('AppComponent', () => { const app = fixture.debugElement.componentInstance; expect(app.title).toEqual('ARSnova'); })); -}); +});*/ diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 39c8d57d7b6e576f503beaa91ccd1d6b777e7f7e..c06e749db00f091813880648c34271df47bf7733 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,20 +1,40 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; -import { ThemeService } from '../theme/theme.service'; +import { SwUpdate } from '@angular/service-worker'; +import { NotificationService } from './services/util/notification.service'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) -export class AppComponent { +export class AppComponent implements OnInit { constructor(private translationService: TranslateService, - private themeService: ThemeService) { - + private update: SwUpdate, + public notification: NotificationService) { translationService.setDefaultLang(this.translationService.getBrowserLang()); sessionStorage.setItem('currentLang', this.translationService.getBrowserLang()); } title = 'ARSnova'; + + ngOnInit(): void { + this.update.available.subscribe(update => { + let install: string; + this.translationService.get('home-page.install').subscribe(msg => { + install = msg; + }); + this.translationService.get('home-page.update-available').subscribe(msg => { + this.notification.show(msg, install, { + duration: 10000 + }); + }); + this.notification.snackRef.afterDismissed().subscribe(info => { + if (info.dismissedByAction === true) { + window.location.reload(); + } + }); + }); + } } diff --git a/src/assets/i18n/home/de.json b/src/assets/i18n/home/de.json index a5a5dbfe249aae3fc5c697d806e58c1003ffc7b3..7d5899df57300df974694a12dca978fb400e81d2 100644 --- a/src/assets/i18n/home/de.json +++ b/src/assets/i18n/home/de.json @@ -29,7 +29,9 @@ "no-empty-name": "Bitte geben Sie einen Namen ein", "created-1": "Session '", "created-2": "' erfolgreich erstellt", - "only-numbers": "Eine Session-ID besteht aus Ziffern" + "only-numbers": "Eine Session-ID besteht aus Ziffern", + "update-available": "Eine neue Version ist verfügbar.", + "install": "Installieren" }, "login": { "email": "E-mail", diff --git a/src/assets/i18n/home/en.json b/src/assets/i18n/home/en.json index 8acaf4efcc8f15dc95d9e3bca522fd1a227ae5a6..3691c26bfc340bc8f875c63ab7fa3c2e73721a65 100644 --- a/src/assets/i18n/home/en.json +++ b/src/assets/i18n/home/en.json @@ -29,7 +29,9 @@ "no-empty-name": "Please enter a name.", "created-1": "Session '", "created-2": "' successfully created", - "only-numbers": "A session-ID only contains digits" + "only-numbers": "A session-ID only contains digits", + "update-available": "A newer version is available.", + "install": "Install" }, "login": { "email": "E-mail",