From 442bb4c2247cfbfc62062fa2f0bbab4c05c5b4fe Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Sun, 24 Oct 2021 11:18:43 -0600 Subject: [PATCH] fix occasional issues with stale state --- ui/README.md | 10 +++++----- .../app/modals/app-config/app-config.page.ts | 2 +- .../app-recover-select.page.ts | 2 +- .../app-interfaces/app-interfaces.page.ts | 2 +- .../apps-routes/app-show/app-show.page.ts | 2 +- .../marketplace-routes/marketplace.service.ts | 8 ++++---- .../preferences/preferences.page.ts | 4 ++-- .../app/services/patch-db/patch-db.service.ts | 2 ++ ui/src/app/services/startup-alerts.service.ts | 18 ++++++++---------- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ui/README.md b/ui/README.md index bc1647ed1..ec6e5da91 100644 --- a/ui/README.md +++ b/ui/README.md @@ -12,13 +12,13 @@ npm --version v8.0.0 ``` -### Building The Mock Development Server +### Running The Mock Development Server `git clone https://github.com/Start9Labs/ws-example.git` `cd ws-example` -**Start the server** +`git submodule update --init --recursive` `cargo run -- -vvv -c example-config.toml` @@ -36,10 +36,10 @@ v8.0.0 `npm --prefix . install @ionic/cli` -`npm --prefix . run build-deps` - `npm --prefix . install` +`npm --prefix . run build-deps` + Copy `config-sample.json` to new file `config.json` In `config.json`, edit the "mocks" section to look like the following: @@ -69,7 +69,7 @@ You can also enable or disable startup alerts. If you want to update mock data inside ws-example, you must do the following: 1. Stop the ws-example server -1. Run `rm embassy.db` +1. In es-example, run `rm embassy.db` 1. Delete `patch-db-cache` from your browser's Local Storage 1. Restart ws-example 1. Refresh the browser window \ No newline at end of file diff --git a/ui/src/app/modals/app-config/app-config.page.ts b/ui/src/app/modals/app-config/app-config.page.ts index 2a85f8b96..20f8b1e62 100644 --- a/ui/src/app/modals/app-config/app-config.page.ts +++ b/ui/src/app/modals/app-config/app-config.page.ts @@ -42,7 +42,7 @@ export class AppConfigPage { ) { } async ngOnInit () { - this.pkg = this.patch.data['package-data'][this.pkgId] + this.pkg = this.patch.getData()['package-data'][this.pkgId] this.hasConfig = !!this.pkg.manifest.config if (!this.hasConfig) return diff --git a/ui/src/app/modals/app-recover-select/app-recover-select.page.ts b/ui/src/app/modals/app-recover-select/app-recover-select.page.ts index 4f15c0f99..b64ce358d 100644 --- a/ui/src/app/modals/app-recover-select/app-recover-select.page.ts +++ b/ui/src/app/modals/app-recover-select/app-recover-select.page.ts @@ -40,7 +40,7 @@ export class AppRecoverSelectPage { ...this.backupInfo['package-backups'][id], id, checked: false, - installed: !!this.patch.data['package-data'][id], + installed: !!this.patch.getData()['package-data'][id], 'newer-eos': this.emver.compare(this.backupInfo['package-backups'][id]['os-version'], this.config.version) === 1, } }) diff --git a/ui/src/app/pages/apps-routes/app-interfaces/app-interfaces.page.ts b/ui/src/app/pages/apps-routes/app-interfaces/app-interfaces.page.ts index 3b0d824e5..5028f5ab8 100644 --- a/ui/src/app/pages/apps-routes/app-interfaces/app-interfaces.page.ts +++ b/ui/src/app/pages/apps-routes/app-interfaces/app-interfaces.page.ts @@ -28,7 +28,7 @@ export class AppInterfacesPage { ngOnInit () { const pkgId = this.route.snapshot.paramMap.get('pkgId') - const pkg = this.patch.data['package-data'][pkgId] + const pkg = this.patch.getData()['package-data'][pkgId] const interfaces = pkg.manifest.interfaces const uiKey = getUiInterfaceKey(interfaces) diff --git a/ui/src/app/pages/apps-routes/app-show/app-show.page.ts b/ui/src/app/pages/apps-routes/app-show/app-show.page.ts index 0f86b7670..a78f1349a 100644 --- a/ui/src/app/pages/apps-routes/app-show/app-show.page.ts +++ b/ui/src/app/pages/apps-routes/app-show/app-show.page.ts @@ -66,7 +66,7 @@ export class AppShowPage { async ngOnInit () { this.pkgId = this.route.snapshot.paramMap.get('pkgId') - this.pkg = this.patch.data['package-data'][this.pkgId] + this.pkg = this.patch.getData()['package-data'][this.pkgId] this.statuses = renderPkgStatus(this.pkg) this.healthChecks = Object.keys(this.pkg.manifest['health-checks']).reduce((obj, key) => { obj[key] = null diff --git a/ui/src/app/pages/marketplace-routes/marketplace.service.ts b/ui/src/app/pages/marketplace-routes/marketplace.service.ts index 75883f4c9..933efede7 100644 --- a/ui/src/app/pages/marketplace-routes/marketplace.service.ts +++ b/ui/src/app/pages/marketplace-routes/marketplace.service.ts @@ -27,7 +27,7 @@ export class MarketplaceService { const [data, eos, pkgs] = await Promise.all([ this.api.getMarketplaceData({ }), this.api.getEos({ - 'eos-version-compat': this.patch.data['server-info']['eos-version-compat'], + 'eos-version-compat': this.patch.getData()['server-info']['eos-version-compat'], }), this.getPkgs(1, 100), ]) @@ -40,7 +40,7 @@ export class MarketplaceService { const idAndCurrentVersions = Object.keys(localPkgs).map(key => ({ id: key, version: localPkgs[key].manifest.version })) const latestPkgs = await this.api.getMarketplacePkgs({ ids: idAndCurrentVersions, - 'eos-version-compat': this.patch.data['server-info']['eos-version-compat'], + 'eos-version-compat': this.patch.getData()['server-info']['eos-version-compat'], }) return latestPkgs.filter(latestPkg => { @@ -53,7 +53,7 @@ export class MarketplaceService { async getPkg (id: string, version?: string): Promise { const pkgs = await this.api.getMarketplacePkgs({ ids: [{ id, version: version || '*' }], - 'eos-version-compat': this.patch.data['server-info']['eos-version-compat'], + 'eos-version-compat': this.patch.getData()['server-info']['eos-version-compat'], }) const pkg = pkgs.find(pkg => pkg.manifest.id == id) @@ -72,7 +72,7 @@ export class MarketplaceService { const pkgs = await this.api.getMarketplacePkgs({ page: String(page), 'per-page': String(perPage), - 'eos-version-compat': this.patch.data['server-info']['eos-version-compat'], + 'eos-version-compat': this.patch.getData()['server-info']['eos-version-compat'], }) return pkgs diff --git a/ui/src/app/pages/server-routes/preferences/preferences.page.ts b/ui/src/app/pages/server-routes/preferences/preferences.page.ts index 9ea070ed4..c9809226a 100644 --- a/ui/src/app/pages/server-routes/preferences/preferences.page.ts +++ b/ui/src/app/pages/server-routes/preferences/preferences.page.ts @@ -24,7 +24,7 @@ export class PreferencesPage { ) { } ngOnInit () { - this.defaultName = `Embassy-${this.patch.data['server-info'].id}` + this.defaultName = `Embassy-${this.patch.getData()['server-info'].id}` } ngAfterViewInit () { @@ -40,7 +40,7 @@ export class PreferencesPage { useMask: false, placeholder: this.defaultName, nullable: true, - value: this.patch.data.ui.name, + value: this.patch.getData().ui.name, buttonText: 'Save', loadingText: 'Saving', submitFn: (value: string) => this.setDbValue('name', value || this.defaultName), diff --git a/ui/src/app/services/patch-db/patch-db.service.ts b/ui/src/app/services/patch-db/patch-db.service.ts index bc03b004b..9a7aa5690 100644 --- a/ui/src/app/services/patch-db/patch-db.service.ts +++ b/ui/src/app/services/patch-db/patch-db.service.ts @@ -27,6 +27,8 @@ export class PatchDbService { private patchSub: Subscription data: DataModel + getData () { return this.patchDb.store.cache.data } + constructor ( @Inject(PATCH_SOURCE) private readonly source: Source, @Inject(PATCH_HTTP) private readonly http: ApiService, diff --git a/ui/src/app/services/startup-alerts.service.ts b/ui/src/app/services/startup-alerts.service.ts index 9d36db9ad..892e37918 100644 --- a/ui/src/app/services/startup-alerts.service.ts +++ b/ui/src/app/services/startup-alerts.service.ts @@ -21,7 +21,6 @@ import { ServerConfigService } from './server-config.service' }) export class StartupAlertsService { private checks: Check[] - data: DataModel constructor ( private readonly alertCtrl: AlertController, @@ -72,8 +71,7 @@ export class StartupAlertsService { filter(data => !isEmptyObject(data)), take(1), ) - .subscribe(async data => { - this.data = data + .subscribe(async () => { await this.checks .filter(c => !this.config.skipStartupAlerts && c.shouldRun()) // returning true in the below block means to continue to next modal @@ -98,25 +96,25 @@ export class StartupAlertsService { // ** should run ** private shouldRunOsWelcome (): boolean { - return this.data.ui['ack-welcome'] !== this.config.version + return this.patch.getData().ui['ack-welcome'] !== this.config.version } private shouldRunShareStats (): boolean { - return !this.data.ui['ack-share-stats'] + return !this.patch.getData().ui['ack-share-stats'] } private shouldRunOsUpdateCheck (): boolean { - return this.data.ui['auto-check-updates'] + return this.patch.getData().ui['auto-check-updates'] } private shouldRunAppsCheck (): boolean { - return this.data.ui['auto-check-updates'] + return this.patch.getData().ui['auto-check-updates'] } // ** check ** private async osUpdateCheck (): Promise { const res = await this.api.getEos({ - 'eos-version-compat': this.patch.data['server-info']['eos-version-compat'], + 'eos-version-compat': this.patch.getData()['server-info']['eos-version-compat'], }) if (this.emver.compare(this.config.version, res.version) === -1) { @@ -127,7 +125,7 @@ export class StartupAlertsService { } private async appsCheck (): Promise { - const updates = await this.marketplaceService.getUpdates(this.data['package-data']) + const updates = await this.marketplaceService.getUpdates(this.patch.getData()['package-data']) return !!updates.length } @@ -153,7 +151,7 @@ export class StartupAlertsService { private async displayShareStats (): Promise { return new Promise(async resolve => { - const alert = await this.serverConfig.presentAlert('share-stats', this.data['server-info']['share-stats']) + const alert = await this.serverConfig.presentAlert('share-stats', this.patch.getData()['server-info']['share-stats']) alert.onDidDismiss().then(() => { this.api.setDbValue({ pointer: '/ack-share-stats', value: this.config.version })