fix occasional issues with stale state

This commit is contained in:
Matt Hill
2021-10-24 11:18:43 -06:00
committed by Aiden McClelland
parent 8056285a7f
commit 442bb4c224
9 changed files with 25 additions and 25 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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,
}
})

View File

@@ -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)

View File

@@ -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

View File

@@ -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<MarketplacePkg> {
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

View File

@@ -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),

View File

@@ -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<DataModel>,
@Inject(PATCH_HTTP) private readonly http: ApiService,

View File

@@ -21,7 +21,6 @@ import { ServerConfigService } from './server-config.service'
})
export class StartupAlertsService {
private checks: Check<any>[]
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<RR.GetMarketplaceEOSRes | undefined> {
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<boolean> {
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<boolean> {
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 })