mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-02-28 03:42:11 +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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {ThingTranslateModule} from '../../translation/thing-translate.module';
|
||||
import {IonicModule, ModalController} from '@ionic/angular';
|
||||
import {TranslateModule} from '@ngx-translate/core';
|
||||
import {UtilModule} from '../../util/util.module';
|
||||
import {CommonModule} from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'stapps-release-notes',
|
||||
@@ -12,10 +13,10 @@ import {UtilModule} from '../../util/util.module';
|
||||
styleUrls: ['release-notes.scss'],
|
||||
standalone: true,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
imports: [UtilModule, MarkdownModule, ThingTranslateModule, IonicModule, TranslateModule],
|
||||
imports: [UtilModule, MarkdownModule, ThingTranslateModule, IonicModule, TranslateModule, CommonModule],
|
||||
})
|
||||
export class ReleaseNotesComponent {
|
||||
@Input() versionInfo: SCAppVersionInfo;
|
||||
@Input() versionInfos: SCAppVersionInfo[];
|
||||
|
||||
constructor(readonly modalController: ModalController) {}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<ion-content parallax>
|
||||
<markdown
|
||||
class="content-card ion-padding"
|
||||
[data]="'releaseNotes' | translateSimple: versionInfo"
|
||||
></markdown>
|
||||
<ng-container *ngFor="let versionInfo of versionInfos">
|
||||
<markdown
|
||||
class="content-card ion-padding"
|
||||
[data]="'releaseNotes' | translateSimple: versionInfo"
|
||||
></markdown>
|
||||
</ng-container>
|
||||
</ion-content>
|
||||
|
||||
Reference in New Issue
Block a user