mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
ui: coooool
This commit is contained in:
committed by
Aiden McClelland
parent
fe7410c0fa
commit
bcbd972502
@@ -26,81 +26,105 @@ export class StartupAlertsNotifier {
|
|||||||
checkedOSForUpdates = false
|
checkedOSForUpdates = false
|
||||||
checkedAppsForUpdates = false
|
checkedAppsForUpdates = false
|
||||||
|
|
||||||
async handleSpecial (server: Readonly<S9Server>): Promise<void> {
|
// So. This takes our three checks and filters down to those that should run.
|
||||||
if (this.needsWelcomeMessage(server)) {
|
// Then, the reduce fires, quickly iterating through yielding a promise (acc) to the next element
|
||||||
const serverUpdates = await this.handleOSWelcome(server)
|
// Each promise fires more or less concurrently, so each c.check(server) is run concurrently
|
||||||
if (this.needsAppsCheck({ ...server, ...serverUpdates })) await this.handleAppsCheck()
|
// Then, since we await acc before c.display(res), each promise executing gets hung awaiting the display of the previous run
|
||||||
return
|
async runChecks (server: Readonly<S9Server>): Promise<void> {
|
||||||
}
|
await this.checks
|
||||||
|
.filter(c => c.shouldRun(server) && !c.hasRun)
|
||||||
if (this.needsOSCheck(server)) {
|
.reduce(async (previousDisplay, c) => {
|
||||||
const thereIsANewOs = await this.handleOSCheck(server)
|
let checkRes
|
||||||
if (thereIsANewOs) return
|
try {
|
||||||
if (this.needsAppsCheck(server)) await this.handleAppsCheck()
|
checkRes = await c.check(server)
|
||||||
}
|
} catch (e) {
|
||||||
|
return console.error(`Exception in ${c.name} check:`, e)
|
||||||
|
}
|
||||||
|
c.hasRun = true
|
||||||
|
if (!checkRes) return
|
||||||
|
const displayRes = await previousDisplay
|
||||||
|
if (c.shouldRun(server) && !!displayRes) return c.display(checkRes)
|
||||||
|
}, Promise.resolve(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
needsWelcomeMessage (server: S9Server): boolean {
|
welcome: Check<S9Server> = {
|
||||||
return !server.welcomeAck && server.versionInstalled === this.config.version && !this.displayedWelcomeMessage
|
name: 'welcome',
|
||||||
|
shouldRun: s => this.shouldRunOsWelcome(s),
|
||||||
|
check: async s => s,
|
||||||
|
display: s => this.displayOsWelcome(s),
|
||||||
|
hasRun: false,
|
||||||
|
}
|
||||||
|
osUpdate: Check<string | undefined> = {
|
||||||
|
name: 'osUpdate',
|
||||||
|
shouldRun: s => this.shouldRunOsUpdateCheck(s),
|
||||||
|
check: s => this.osUpdateCheck(s),
|
||||||
|
display: vl => this.displayOsUpdateCheck(vl),
|
||||||
|
hasRun: false,
|
||||||
|
}
|
||||||
|
apps: Check<boolean> = {
|
||||||
|
name: 'apps',
|
||||||
|
shouldRun: s => this.shouldRunAppsCheck(s),
|
||||||
|
check: () => this.appsCheck(),
|
||||||
|
display: () => this.displayAppsCheck(),
|
||||||
|
hasRun: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
needsAppsCheck (server: S9Server): boolean {
|
checks: Check<any>[] = [this.welcome, this.apps, this.osUpdate]
|
||||||
return server.autoCheckUpdates && !this.checkedAppsForUpdates
|
|
||||||
|
private shouldRunOsWelcome (s: S9Server): boolean {
|
||||||
|
return !s.welcomeAck && s.versionInstalled === this.config.version
|
||||||
}
|
}
|
||||||
|
|
||||||
needsOSCheck (server: S9Server): boolean {
|
private shouldRunAppsCheck (server: S9Server): boolean {
|
||||||
return server.autoCheckUpdates && !this.checkedOSForUpdates
|
return server.autoCheckUpdates
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleOSWelcome (server: Readonly<S9Server>): Promise<Partial<S9Server>> {
|
private shouldRunOsUpdateCheck (server: S9Server): boolean {
|
||||||
this.displayedWelcomeMessage = true
|
return server.autoCheckUpdates
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async osUpdateCheck (s: Readonly<S9Server>): Promise<string | undefined> {
|
||||||
|
const { versionLatest } = await this.apiService.getVersionLatest()
|
||||||
|
return this.osUpdateService.updateIsAvailable(s.versionInstalled, versionLatest) ? versionLatest : undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
private async appsCheck (): Promise<boolean> {
|
||||||
|
const availableApps = await this.apiService.getAvailableApps()
|
||||||
|
return !!availableApps.find(app => this.emver.compare(app.versionInstalled, app.versionLatest) === -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
private async displayOsWelcome (s: Readonly<S9Server>): Promise<boolean> {
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
const modal = await this.modalCtrl.create({
|
const modal = await this.modalCtrl.create({
|
||||||
backdropDismiss: false,
|
backdropDismiss: false,
|
||||||
component: OSWelcomePage,
|
component: OSWelcomePage,
|
||||||
presentingElement: await this.modalCtrl.getTop(),
|
presentingElement: await this.modalCtrl.getTop(),
|
||||||
componentProps: {
|
componentProps: {
|
||||||
version: server.versionInstalled,
|
version: s.versionInstalled,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
await modal.present()
|
await modal.present()
|
||||||
modal.onWillDismiss().then(res => resolve(res.data))
|
modal.onWillDismiss().then(res => {
|
||||||
|
s = Object.assign(s, res.data)
|
||||||
|
return resolve(true)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns whether there is a new OS available or not
|
private async displayOsUpdateCheck (versionLatest: string | undefined): Promise<boolean> {
|
||||||
private async handleOSCheck (server: Readonly<S9Server>): Promise<boolean> {
|
const { update } = await this.presentAlertNewOS(versionLatest)
|
||||||
this.checkedOSForUpdates = true
|
if (update) {
|
||||||
|
await this.loader.displayDuringP(
|
||||||
const { versionLatest } = await this.apiService.getVersionLatest()
|
this.osUpdateService.updateEmbassyOS(versionLatest),
|
||||||
if (this.osUpdateService.updateIsAvailable(server.versionInstalled, versionLatest)) {
|
).catch(e => alert(e))
|
||||||
const { update } = await this.presentAlertNewOS(versionLatest)
|
return false
|
||||||
if (update) {
|
|
||||||
await this.loader.displayDuringP(
|
|
||||||
this.osUpdateService.updateEmbassyOS(versionLatest),
|
|
||||||
).catch(e => alert(e))
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleAppsCheck () {
|
private async displayAppsCheck (): Promise<boolean> {
|
||||||
this.checkedAppsForUpdates = true
|
|
||||||
|
|
||||||
try {
|
|
||||||
const availableApps = await this.apiService.getAvailableApps()
|
|
||||||
if (!!availableApps.find(app => this.emver.compare(app.versionInstalled, app.versionLatest) === -1)) {
|
|
||||||
return this.presentAlertNewApps()
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(`Exception checking for new apps: `, e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async presentAlertNewApps (): Promise<void> {
|
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
const alert = await this.alertCtrl.create({
|
const alert = await this.alertCtrl.create({
|
||||||
backdropDismiss: true,
|
backdropDismiss: true,
|
||||||
@@ -110,17 +134,17 @@ export class StartupAlertsNotifier {
|
|||||||
{
|
{
|
||||||
text: 'Cancel',
|
text: 'Cancel',
|
||||||
role: 'cancel',
|
role: 'cancel',
|
||||||
|
handler: () => resolve(true),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'View in Marketplace',
|
text: 'View in Marketplace',
|
||||||
handler: () => {
|
handler: () => {
|
||||||
return this.navCtrl.navigateForward('/services/marketplace')
|
return this.navCtrl.navigateForward('/services/marketplace').then(() => resolve(false))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
alert.onWillDismiss().then(() => resolve())
|
|
||||||
await alert.present()
|
await alert.present()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -147,3 +171,17 @@ export class StartupAlertsNotifier {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Check<T> = {
|
||||||
|
// validates whether a check should run based on server properties
|
||||||
|
shouldRun: (s: S9Server) => boolean
|
||||||
|
// executes a check, often requiring api call. It should return a false-y value if there should be no display.
|
||||||
|
check: (s: S9Server) => Promise<T>
|
||||||
|
// display an alert based on the result of the check.
|
||||||
|
// return false if subsequent modals should be cancelled
|
||||||
|
display: (a: T) => Promise<boolean>
|
||||||
|
// tracks if this check has run in this app instance.
|
||||||
|
hasRun: boolean
|
||||||
|
// for logging purposes
|
||||||
|
name: string
|
||||||
|
}
|
||||||
@@ -38,7 +38,7 @@ export class SyncDaemon {
|
|||||||
sync (): Observable<void> {
|
sync (): Observable<void> {
|
||||||
return from(this.getServerAndApps()).pipe(
|
return from(this.getServerAndApps()).pipe(
|
||||||
concatMap(() => this.syncNotifier.handleSpecial(this.serverModel.peek())),
|
concatMap(() => this.syncNotifier.handleSpecial(this.serverModel.peek())),
|
||||||
concatMap(() => this.startupAlertsNotifier.handleSpecial(this.serverModel.peek())),
|
concatMap(() => this.startupAlertsNotifier.runChecks(this.serverModel.peek())),
|
||||||
tap(() => this.$synced$.next()),
|
tap(() => this.$synced$.next()),
|
||||||
catchError(e => of(console.error(`Exception in sync service`, e))),
|
catchError(e => of(console.error(`Exception in sync service`, e))),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user