feat: app release notes

This commit is contained in:
Thea Schöbl
2023-12-01 12:34:20 +00:00
parent 5d47a17629
commit 37945f7d19
18 changed files with 335 additions and 7 deletions

View File

@@ -0,0 +1,60 @@
import {Injectable} from '@angular/core';
import {StorageProvider} from '../storage/storage.provider';
import {ConfigProvider} from '../config/config.provider';
import {ModalController} from '@ionic/angular';
import {Capacitor} from '@capacitor/core';
import {ReleaseNotesComponent} from './release-notes.component';
import {SCAppVersionInfo} from '@openstapps/core';
import {App} from '@capacitor/app';
export const RELEASE_NOTES_SHOWN_KEY = 'release_notes_shown';
@Injectable({providedIn: 'root'})
export class AppVersionService {
constructor(
private storage: StorageProvider,
private config: ConfigProvider,
private modalController: ModalController,
) {}
/**
* Get the release notes of the latest published version
*/
get publishedVersions() {
const platform = Capacitor.getPlatform() as 'android' | 'ios' | 'web';
return this.config.config.app.versionHistory?.filter(({published}) => published[platform] !== undefined);
}
/**
* Get the latest release notes that have not been presented yet
*/
async getPendingReleaseNotes() {
if (Capacitor.getPlatform() === 'web') {
return;
}
const storedVersion = (await this.storage.has(RELEASE_NOTES_SHOWN_KEY))
? await this.storage.get<string>(RELEASE_NOTES_SHOWN_KEY)
: '';
const currentVersion = await App.getInfo().then(info => info.version);
return this.publishedVersions?.find(({version}) => {
const wasNotShown = version.localeCompare(storedVersion, undefined, {numeric: true}) === 1;
const isNotFutureVersion = version.localeCompare(currentVersion, undefined, {numeric: true}) <= 0;
return wasNotShown && isNotFutureVersion;
});
}
/**
* Present release notes
*/
async presentReleaseNotes(version: SCAppVersionInfo) {
const modal = await this.modalController.create({
component: ReleaseNotesComponent,
componentProps: {
versionInfo: version,
},
});
await modal.present();
await modal.onDidDismiss();
await this.storage.put(RELEASE_NOTES_SHOWN_KEY, version.version);
}
}