From 1516d2066f832e5d7873f3b5139c1d43be0ebc24 Mon Sep 17 00:00:00 2001 From: Claudio Nicora Date: Sat, 16 Sep 2023 01:41:12 +0200 Subject: [PATCH] Application version is now retrieved from application build data, no need to store it in multiple files anymore --- android/app/src/main/res/values/strings.xml | 4 +-- src/app/app-routing.module.ts | 6 ++-- src/app/app.module.ts | 4 ++- src/app/pages/about/about.page.html | 6 ++-- src/app/pages/main/main.page.html | 2 +- src/app/pages/main/main.page.ts | 2 +- src/app/services/settings.service.ts | 1 + src/app/version.ts | 37 ++++++++++++++++----- 8 files changed, 42 insertions(+), 20 deletions(-) diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index c8515db..4be5624 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -1,7 +1,7 @@ - BCR Gui - BCR Gui + BCR-GUI + BCR-GUI com.github.nicorac.bcrgui com.github.nicorac.bcrgui diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 787988c..34d8c57 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -13,9 +13,9 @@ export enum AppRoutesEnum { const routes: Routes = [ { path: '', pathMatch: 'full', redirectTo: AppRoutesEnum.Main }, - { path: AppRoutesEnum.Main, title: version.appName, component: MainPage }, - { path: AppRoutesEnum.Settings, title: 'Settings', component: SettingsPage }, - { path: AppRoutesEnum.About, title: 'About', component: AboutPage }, + { path: AppRoutesEnum.Main, title: '' /* set by page itself */, component: MainPage }, + { path: AppRoutesEnum.Settings, title: 'Settings', component: SettingsPage }, + { path: AppRoutesEnum.About, title: 'About', component: AboutPage }, ]; @NgModule({ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8a0f60c..20add4e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -18,6 +18,7 @@ import { RecordingsSortPipe } from './pipes/recordings-sort.pipe'; import { ToHmsPipe } from './pipes/to-hms.pipe'; import { RecordingsService } from './services/recordings.service'; import { SettingsService } from './services/settings.service'; +import version from './version'; @NgModule({ declarations: [ @@ -62,7 +63,8 @@ function appInitializer(recordingsService: RecordingsService, settings: Settings // wait for Ionic initialization await platform.ready(); - // initialize settings + // initialize version & settings + await version.initialize(); await settings.initialize(); // initialize recordings service diff --git a/src/app/pages/about/about.page.html b/src/app/pages/about/about.page.html index 27b0b9b..66c4e25 100644 --- a/src/app/pages/about/about.page.html +++ b/src/app/pages/about/about.page.html @@ -7,7 +7,7 @@
{{ version.appName }}
- BCR-GUI is a companion app for + {{ version.appName }} is a companion app for BCR (Basic Call Recorder) to ease management of its recordings database
@@ -27,14 +27,14 @@

Version

Copyright

-

{{ version.copyright }} ({{ version.website }})

+

{{ version.copyright }} ({{ version.websiteUri }})

Source code

-

GitHub ({{ version.sources }})

+

GitHub ({{ version.sourcesUri }})

diff --git a/src/app/pages/main/main.page.html b/src/app/pages/main/main.page.html index 2e174dd..79ccc73 100644 --- a/src/app/pages/main/main.page.html +++ b/src/app/pages/main/main.page.html @@ -1,4 +1,4 @@ - + diff --git a/src/app/pages/main/main.page.ts b/src/app/pages/main/main.page.ts index faef428..0dbe7f0 100644 --- a/src/app/pages/main/main.page.ts +++ b/src/app/pages/main/main.page.ts @@ -5,12 +5,12 @@ import { MessageBoxService } from 'src/app/services/message-box.service'; import { RecordingsService } from 'src/app/services/recordings.service'; import { SettingsService } from 'src/app/services/settings.service'; import { bringIntoView } from 'src/app/utils/scroll'; +import version from '../../version'; import { AndroidSAF } from 'src/plugins/capacitorandroidsaf'; import { DatePipe } from '@angular/common'; import { Component } from '@angular/core'; import { Directory, Filesystem } from '@capacitor/filesystem'; import { Share } from '@capacitor/share'; -import version from '../../version'; @Component({ selector: 'app-main', diff --git a/src/app/services/settings.service.ts b/src/app/services/settings.service.ts index daffd90..99cd87e 100644 --- a/src/app/services/settings.service.ts +++ b/src/app/services/settings.service.ts @@ -3,6 +3,7 @@ import { Injectable } from '@angular/core'; import { Preferences } from '@capacitor/preferences'; import { SortMode } from '../pipes/recordings-sort.pipe'; import { FromJSON, Serialized, ToJSON } from '../utils/json-serializer'; +import version from '../version'; export type Appearance = 'system' | 'light' | 'dark'; export type Theme = 'light' | 'dark'; diff --git a/src/app/version.ts b/src/app/version.ts index 39d5633..bf435a3 100644 --- a/src/app/version.ts +++ b/src/app/version.ts @@ -1,9 +1,28 @@ -export default { - // NOTE: remember to change version number in Android apk too: - // android\app\build.gradle --> versionName + versionCode - "appName": "BCR-GUI", - "version": "0.0.10", - "copyright": "Claudio Nicora (nicorac) 2023", - "website": "https://coolsoft.altervista.org", - "sources": "https://github.com/nicorac/bcr-gui" -} \ No newline at end of file +import { App } from '@capacitor/app'; + +class versionClass { + + // dynamic values + // these fields are injected at runtime by SettingsService.initialize() + // set their values in file `android/app/build.gradle` + private _appName = ''; + get appName(): string { return this._appName }; + private _version = ''; + get version(): string { return this._version }; + + // static values + readonly copyright = "Claudio Nicora (nicorac) 2023"; + readonly websiteUri = "https://coolsoft.altervista.org"; + readonly sourcesUri = "https://github.com/nicorac/bcr-gui"; + + // read version + async initialize() { + const ver = await App.getInfo(); + this._appName = ver.name; + this._version = ver.version; + } + +} + +let version = new versionClass(); +export default version;