mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-02-22 00:42:09 +00:00
feat: simplify version history api
This commit is contained in:
committed by
Rainer Killinger
parent
d44204cf8d
commit
d2c8120255
@@ -6,6 +6,7 @@ import {Capacitor} from '@capacitor/core';
|
||||
import {ReleaseNotesComponent} from './release-notes.component';
|
||||
import {SCAppVersionInfo} from '@openstapps/core';
|
||||
import {App} from '@capacitor/app';
|
||||
import {coerce} from 'semver';
|
||||
|
||||
export const RELEASE_NOTES_SHOWN_KEY = 'release_notes_shown';
|
||||
|
||||
@@ -17,14 +18,6 @@ export class AppVersionService {
|
||||
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
|
||||
*/
|
||||
@@ -32,29 +25,38 @@ export class AppVersionService {
|
||||
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;
|
||||
});
|
||||
const storedVersion = coerce(
|
||||
(await this.storage.has(RELEASE_NOTES_SHOWN_KEY))
|
||||
? await this.storage.get<string>(RELEASE_NOTES_SHOWN_KEY)
|
||||
: '0.0.0',
|
||||
)!;
|
||||
const currentVersion = coerce(await App.getInfo().then(info => info.version))!;
|
||||
|
||||
return this.config.config.app.versionHistory
|
||||
?.filter(({version}) => {
|
||||
const semanticVersion = coerce(version)!;
|
||||
const wasNotShown = semanticVersion.compare(storedVersion) === 1;
|
||||
const isNotFutureVersion = semanticVersion.compare(currentVersion) <= 0;
|
||||
return wasNotShown && isNotFutureVersion;
|
||||
})
|
||||
?.sort((a, b) => coerce(a.version)!.compare(b.version));
|
||||
}
|
||||
|
||||
/**
|
||||
* Present release notes
|
||||
*/
|
||||
async presentReleaseNotes(version: SCAppVersionInfo) {
|
||||
async presentReleaseNotes(versions: SCAppVersionInfo[]) {
|
||||
if (!versions || versions.length === 0) {
|
||||
return;
|
||||
}
|
||||
const modal = await this.modalController.create({
|
||||
component: ReleaseNotesComponent,
|
||||
componentProps: {
|
||||
versionInfo: version,
|
||||
versionInfos: versions,
|
||||
},
|
||||
});
|
||||
await modal.present();
|
||||
await modal.onDidDismiss();
|
||||
await this.storage.put(RELEASE_NOTES_SHOWN_KEY, version.version);
|
||||
await this.storage.put(RELEASE_NOTES_SHOWN_KEY, versions[0].version);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user