From ce615f1475dde94ce145ebd00051118389e002f6 Mon Sep 17 00:00:00 2001 From: _Bastler Date: Wed, 7 Dec 2022 21:44:37 +0100 Subject: [PATCH] small improvements, pwa update --- ngsw-config.json | 2 +- package.json | 2 +- src/app/pages/search/search.page.scss | 18 ++++++----- src/app/ui/entries/entries.ui.html | 2 +- src/app/ui/main/main.ui.html | 2 +- src/app/ui/main/main.ui.ts | 43 ++++++++++++++++++++++++++- src/assets/i18n/de-informal.json | 1 + src/assets/i18n/en.json | 1 + 8 files changed, 59 insertions(+), 12 deletions(-) diff --git a/ngsw-config.json b/ngsw-config.json index ace6c43..a60d6c8 100644 --- a/ngsw-config.json +++ b/ngsw-config.json @@ -2,7 +2,7 @@ "$schema": "./node_modules/@angular/service-worker/config/schema.json", "index": "/index.html", "appData": { - "version": "1.5.2" + "version": "1.5.3" }, "assetGroups": [ { diff --git a/package.json b/package.json index 4c956ea..e0ec676 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bstlboard", - "version": "1.5.2", + "version": "1.5.3", "license": "AGPL3", "scripts": { "ng": "ng", diff --git a/src/app/pages/search/search.page.scss b/src/app/pages/search/search.page.scss index 5934a63..eea525c 100644 --- a/src/app/pages/search/search.page.scss +++ b/src/app/pages/search/search.page.scss @@ -2,15 +2,19 @@ mat-list mat-list-item { height: auto; } -mat-form-field { - margin-right: 15px; - flex-basis: 0; - flex-grow: 1; - min-width: 100px; -} - .container { margin-bottom: 0; + + mat-form-field { + margin-right: 15px; + flex-basis: 0; + flex-grow: 1; + min-width: 50px; + + &:first-child { + min-width: 300px; + } + } } mat-form-field .mat-form-field-wrapper { diff --git a/src/app/ui/entries/entries.ui.html b/src/app/ui/entries/entries.ui.html index f1ddab4..f4d4647 100644 --- a/src/app/ui/entries/entries.ui.html +++ b/src/app/ui/entries/entries.ui.html @@ -36,7 +36,7 @@
-
+
filter_alt diff --git a/src/app/ui/main/main.ui.html b/src/app/ui/main/main.ui.html index 0b83150..2e64fd4 100644 --- a/src/app/ui/main/main.ui.html +++ b/src/app/ui/main/main.ui.html @@ -86,7 +86,7 @@ style="font-size: 0.7em;"> {{'page.privacy-policy' | i18n}} - v{{version}} + v{{version}} {{'updateSw' | i18n}} diff --git a/src/app/ui/main/main.ui.ts b/src/app/ui/main/main.ui.ts index 22e66ec..ed627ad 100644 --- a/src/app/ui/main/main.ui.ts +++ b/src/app/ui/main/main.ui.ts @@ -11,6 +11,7 @@ import { I18nService } from '../../services/i18n.service'; import { SettingsService } from '../../services/settings.service'; import packageJson from '../../../../package.json'; +import { SwUpdate } from '@angular/service-worker'; @Component({ selector: 'ui-main', @@ -28,6 +29,7 @@ export class UiMain { authenticated: boolean = false; moderator: boolean = false; searchFocus: boolean = false; + hasUpdate: boolean = false; touchThresh: number = 150; touchStartX: number; @@ -43,8 +45,23 @@ export class UiMain { private router: Router, private iconRegistry: MatIconRegistry, private sanitizer: DomSanitizer, - private _adapter: DateAdapter) { + private _adapter: DateAdapter, private swUpdate: SwUpdate) { iconRegistry.addSvgIcon('logo', sanitizer.bypassSecurityTrustResourceUrl('assets/icons/logo.svg')); + + this.swUpdate.versionUpdates.subscribe(evt => { + if (evt.type == 'VERSION_READY') { + this.hasUpdate = true; + } else if (evt.type == 'VERSION_INSTALLATION_FAILED') { + console.error(`Failed to install version '${evt.version.hash}': ${evt.error}`); + } + }) + + if (this.swUpdate.isEnabled) { + // check for PWA update every 30s + setInterval(() => { + this.swUpdate.checkForUpdate(); + }, 30000); + } } async ngOnInit() { @@ -98,6 +115,7 @@ export class UiMain { close() { this.opened = false; + this.searchFocus = false; } preventClose(event) { @@ -193,5 +211,28 @@ export class UiMain { }) } + updateSw(force: boolean = false): void { + if (this.hasUpdate || force) { + if (this.swUpdate.isEnabled) { + this.swUpdate.activateUpdate().then(() => { + this.clearAndRefresh(); + }); + } else { + this.clearAndRefresh(); + } + } + } + + clearAndRefresh() { + if ('caches' in window) { + caches.keys() + .then(function (keyList) { + return Promise.all(keyList.map(function (key) { + return caches.delete(key); + })); + }) + } + window.location.reload() + } } diff --git a/src/assets/i18n/de-informal.json b/src/assets/i18n/de-informal.json index 742d00f..50881cc 100644 --- a/src/assets/i18n/de-informal.json +++ b/src/assets/i18n/de-informal.json @@ -152,6 +152,7 @@ "error": "Url erforderlich" } }, + "updateSw": "Update?", "user": { ".": "User", "about": "Über", diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index b55e5c3..06ca9e9 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -152,6 +152,7 @@ "error": "url required" } }, + "updateSw": "Update?", "user": { ".": "user", "about": "about",