ui: super clear conditionals

This commit is contained in:
Aaron Greenspan
2021-01-20 17:00:12 -07:00
committed by Aiden McClelland
parent e482ccf7fd
commit 219f66ae8a
3 changed files with 86 additions and 57 deletions

View File

@@ -17,7 +17,6 @@ export class OSWelcomePage {
constructor ( constructor (
private readonly modalCtrl: ModalController, private readonly modalCtrl: ModalController,
private readonly apiService: ApiService, private readonly apiService: ApiService,
private readonly serverModel: ServerModel,
private readonly config: ConfigService, private readonly config: ConfigService,
) { } ) { }
@@ -25,10 +24,9 @@ export class OSWelcomePage {
async dismiss () { async dismiss () {
this.apiService this.apiService
.patchServerConfig('autoCheckUpdates', this.autoCheckUpdates) .patchServerConfig('autoCheckUpdates', this.autoCheckUpdates)
.then(() => this.serverModel.update({ autoCheckUpdates: this.autoCheckUpdates }))
.then(() => this.apiService.acknowledgeOSWelcome(this.config.version)) .then(() => this.apiService.acknowledgeOSWelcome(this.config.version))
.catch(console.error), .catch(console.error)
this.modalCtrl.dismiss({ autoCheckUpdates: this.autoCheckUpdates }) return this.modalCtrl.dismiss({ autoCheckUpdates: this.autoCheckUpdates })
} }
} }

View File

@@ -22,43 +22,71 @@ export class StartupAlertsNotifier {
) { } ) { }
displayedWelcomeMessage = false displayedWelcomeMessage = false
checkedForUpdates = false checkedOSForUpdates = false
checkedAppsForUpdates = false
async handleSpecial (server: Readonly<S9Server>): Promise<void> { async handleSpecial (server: Readonly<S9Server>): Promise<void> {
this.handleOSWelcome(server) if (this.needsWelcomeMessage(server)) {
if (!this.displayedWelcomeMessage) this.handleUpdateCheck(server) await this.handleOSWelcome(server)
} if (this.needsAppsCheck(server)) await this.handleAppsCheck()
private async handleOSWelcome (server: Readonly<S9Server>) {
if (server.welcomeAck || server.versionInstalled !== this.config.version || this.displayedWelcomeMessage) return
this.displayedWelcomeMessage = true
const modal = await this.modalCtrl.create({
backdropDismiss: false,
component: OSWelcomePage,
presentingElement: await this.modalCtrl.getTop(),
componentProps: {
version: server.versionInstalled,
},
})
await modal.present()
}
private async handleUpdateCheck (server: Readonly<S9Server>) {
if (!server.autoCheckUpdates || this.checkedForUpdates) return
this.checkedForUpdates = true
if (this.osUpdateService.updateIsAvailable(server.versionInstalled, server.versionLatest)) {
const { update } = await this.presentAlertNewOS(server.versionLatest)
if (update) {
return this.loader
.displayDuringP(this.osUpdateService.updateEmbassyOS(server.versionLatest))
.catch(e => alert(e))
}
} }
if (this.needsOSCheck(server)) {
const thereIsANewOs = await this.handleOSCheck(server)
if (thereIsANewOs) return
if (this.needsAppsCheck(server)) await this.handleAppsCheck()
}
}
needsWelcomeMessage (server: S9Server): boolean {
return !server.welcomeAck && server.versionInstalled === this.config.version && !this.displayedWelcomeMessage
}
needsAppsCheck (server: S9Server): boolean {
return server.autoCheckUpdates && !this.checkedAppsForUpdates
}
needsOSCheck (server: S9Server): boolean {
return server.autoCheckUpdates && !this.checkedOSForUpdates
}
private async handleOSWelcome (server: Readonly<S9Server>): Promise<void> {
this.displayedWelcomeMessage = true
return new Promise(async resolve => {
const modal = await this.modalCtrl.create({
backdropDismiss: false,
component: OSWelcomePage,
presentingElement: await this.modalCtrl.getTop(),
componentProps: {
version: server.versionInstalled,
},
})
await modal.present()
modal.onWillDismiss().then(() => resolve())
})
}
// returns whether there is a new OS available or not
private async handleOSCheck (server: Readonly<S9Server>): Promise<boolean> {
this.checkedOSForUpdates = true
const { versionLatest } = await this.apiService.getVersionLatest()
if (this.osUpdateService.updateIsAvailable(server.versionInstalled, versionLatest)) {
const { update } = await this.presentAlertNewOS(server.versionLatest)
if (update) {
await this.loader.displayDuringP(
this.osUpdateService.updateEmbassyOS(versionLatest),
).catch(e => alert(e))
}
return true
}
return false
}
private async handleAppsCheck () {
this.checkedAppsForUpdates = true
try { try {
const availableApps = await this.apiService.getAvailableApps() const availableApps = await this.apiService.getAvailableApps()
if (!!availableApps.find(app => this.emver.compare(app.versionInstalled, app.versionLatest) === -1)) { if (!!availableApps.find(app => this.emver.compare(app.versionInstalled, app.versionLatest) === -1)) {
@@ -69,26 +97,29 @@ export class StartupAlertsNotifier {
} }
} }
private async presentAlertNewApps () { private async presentAlertNewApps (): Promise<void> {
const alert = await this.alertCtrl.create({ return new Promise(async resolve => {
backdropDismiss: true, const alert = await this.alertCtrl.create({
header: 'Updates Available!', backdropDismiss: true,
message: 'New service updates are available in the Marketplace.', header: 'Updates Available!',
buttons: [ message: 'New service updates are available in the Marketplace.',
{ buttons: [
text: 'Cancel', {
role: 'cancel', text: 'Cancel',
}, role: 'cancel',
{
text: 'View in Marketplace',
handler: () => {
return this.navCtrl.navigateForward('/services/marketplace')
}, },
}, {
], text: 'View in Marketplace',
}) handler: () => {
return this.navCtrl.navigateForward('/services/marketplace')
},
},
],
})
await alert.present() alert.onWillDismiss().then(() => resolve())
await alert.present()
})
} }
private async presentAlertNewOS (versionLatest: string): Promise<{ cancel?: true, update?: true }> { private async presentAlertNewOS (versionLatest: string): Promise<{ cancel?: true, update?: true }> {
@@ -112,4 +143,4 @@ export class StartupAlertsNotifier {
await alert.present() await alert.present()
}) })
} }
} }

View File

@@ -1,3 +1,3 @@
{ {
"useMocks": false "useMocks": true
} }