mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
ui: readability improvements
This commit is contained in:
committed by
Aiden McClelland
parent
66ddf752ac
commit
d224b7a114
@@ -35,7 +35,7 @@ export class AppAvailableListPage {
|
|||||||
|
|
||||||
markAsLoadingDuringP(this.$loading$, Promise.all([
|
markAsLoadingDuringP(this.$loading$, Promise.all([
|
||||||
this.getApps(),
|
this.getApps(),
|
||||||
this.osUpdateService.checkForUpdates(), // checks for an os update, banner component renders conditionally
|
this.osUpdateService.checkWhenNotAvailable$().toPromise(), // checks for an os update, banner component renders conditionally
|
||||||
pauseFor(600),
|
pauseFor(600),
|
||||||
]))
|
]))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export module ReqRes {
|
|||||||
export type PostLoginRes = Unit
|
export type PostLoginRes = Unit
|
||||||
export type GetCheckAuthRes = { }
|
export type GetCheckAuthRes = { }
|
||||||
export type GetServerRes = ApiServer
|
export type GetServerRes = ApiServer
|
||||||
export type GetVersionLatestRes = { versionLatest: string, canUpdate: boolean }
|
export type GetVersionLatestRes = { versionLatest: string, canUpdate: boolean } // canUpdate not supported at least at 0.2.8
|
||||||
export type GetServerMetricsRes = ServerMetrics
|
export type GetServerMetricsRes = ServerMetrics
|
||||||
export type GetAppAvailableRes = ApiAppAvailableFull
|
export type GetAppAvailableRes = ApiAppAvailableFull
|
||||||
export type GetAppAvailableVersionInfoRes = AppAvailableVersionSpecificInfo
|
export type GetAppAvailableVersionInfoRes = AppAvailableVersionSpecificInfo
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { Injectable } from '@angular/core'
|
import { Injectable } from '@angular/core'
|
||||||
import { NavController } from '@ionic/angular'
|
import { NavController } from '@ionic/angular'
|
||||||
import { BehaviorSubject, forkJoin, Observable, of } from 'rxjs'
|
import { BehaviorSubject, forkJoin, Observable, of } from 'rxjs'
|
||||||
import { catchError, concatMap, distinctUntilChanged, filter, map, take, tap } from 'rxjs/operators'
|
import { catchError, concatMap, distinctUntilChanged, map, take, tap } from 'rxjs/operators'
|
||||||
import { ServerModel, ServerStatus } from '../models/server-model'
|
import { ServerModel, ServerStatus } from '../models/server-model'
|
||||||
import { traceWheel } from '../util/misc.util'
|
|
||||||
import { ApiService } from './api/api.service'
|
import { ApiService } from './api/api.service'
|
||||||
import { Emver } from './emver.service'
|
import { Emver } from './emver.service'
|
||||||
|
|
||||||
@@ -25,22 +24,16 @@ export class OsUpdateService {
|
|||||||
private readonly navCtrl: NavController,
|
private readonly navCtrl: NavController,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
// emits everytime autoCheckUpdates becomes (or is) true
|
// emits the latest version or re-checks to see if there's a new latest version
|
||||||
autoCheck$ (): Observable<string> {
|
checkWhenNotAvailable$ (): Observable<undefined | string> {
|
||||||
return this.serverModel.watch().autoCheckUpdates.pipe(
|
return this.$updateAvailable$.pipe(
|
||||||
traceWheel('auto check updates 1'),
|
take(1),
|
||||||
distinctUntilChanged(),
|
concatMap(vl => vl ? of(vl) : this.checkForUpdates$()),
|
||||||
filter(check => check),
|
|
||||||
traceWheel('auto check updates 2'),
|
|
||||||
concatMap(() => this.apiService.getVersionLatest()),
|
|
||||||
traceWheel('getVersionLatest'),
|
|
||||||
map(({ canUpdate, versionLatest }) => canUpdate ? versionLatest : undefined),
|
|
||||||
tap(this.$updateAvailable$),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// can call this imperatively and take the return value as gospel, or watch the $updateAvailable$ subject for the same info.
|
// can sub to this imperatively and take the return value as gospel, or watch the $updateAvailable$ subject for the same info.
|
||||||
checkForUpdates (): Promise<undefined | string> {
|
checkForUpdates$ (): Observable<undefined | string> {
|
||||||
return forkJoin([
|
return forkJoin([
|
||||||
this.serverModel.watch().versionInstalled.pipe(take(1)),
|
this.serverModel.watch().versionInstalled.pipe(take(1)),
|
||||||
this.apiService.getVersionLatest(),
|
this.apiService.getVersionLatest(),
|
||||||
@@ -52,7 +45,7 @@ export class OsUpdateService {
|
|||||||
}),
|
}),
|
||||||
// cache the result for components to learn update available without having to have called this method
|
// cache the result for components to learn update available without having to have called this method
|
||||||
tap(this.$updateAvailable$),
|
tap(this.$updateAvailable$),
|
||||||
).toPromise()
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkForAppsUpdate (): Promise<boolean> {
|
async checkForAppsUpdate (): Promise<boolean> {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { Injectable } from '@angular/core'
|
import { Injectable } from '@angular/core'
|
||||||
import { AlertController, ModalController, NavController } from '@ionic/angular'
|
import { AlertController, ModalController, NavController } from '@ionic/angular'
|
||||||
import { combineLatest, EMPTY, iif, Observable, of } from 'rxjs'
|
import { combineLatest, Observable, of } from 'rxjs'
|
||||||
import { concatMap, filter, take } from 'rxjs/operators'
|
import { concatMap, filter, map, switchMap, take } from 'rxjs/operators'
|
||||||
import { OSWelcomePage } from '../modals/os-welcome/os-welcome.page'
|
import { OSWelcomePage } from '../modals/os-welcome/os-welcome.page'
|
||||||
import { ServerModel } from '../models/server-model'
|
import { ServerModel } from '../models/server-model'
|
||||||
import { exists, traceWheel } from '../util/misc.util'
|
import { exists } from '../util/misc.util'
|
||||||
import { ApiService } from './api/api.service'
|
import { ApiService } from './api/api.service'
|
||||||
import { ConfigService } from './config.service'
|
import { ConfigService } from './config.service'
|
||||||
import { LoaderService } from './loader.service'
|
import { LoaderService } from './loader.service'
|
||||||
@@ -26,51 +26,57 @@ export class GlobalAlertsNotifier {
|
|||||||
|
|
||||||
init () {
|
init () {
|
||||||
console.log('init')
|
console.log('init')
|
||||||
this.osWelcome$().pipe(
|
of({ }).pipe(
|
||||||
concatMap(() => this.autoUpdateCheck$()),
|
concatMap(
|
||||||
|
() => this.welcomeNeeded$().pipe(
|
||||||
|
take(1), // we only show welcome at most once per app instance
|
||||||
|
concatMap(vi => vi ? this.presentOsWelcome(vi) : of({ })),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
concatMap(
|
||||||
|
() => this.osUpdateAlertNeeded$().pipe(
|
||||||
|
switchMap(vl => vl ? this.presentUpdateDailogues(vl) : of({ })),
|
||||||
|
),
|
||||||
|
),
|
||||||
).subscribe()
|
).subscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
private osWelcome$ (): Observable<void> {
|
// emits versionInstalled when welcomeAck is false and f.e and b.e have same version
|
||||||
|
private welcomeNeeded$ (): Observable<string | undefined> {
|
||||||
const { welcomeAck, versionInstalled } = this.server.watch()
|
const { welcomeAck, versionInstalled } = this.server.watch()
|
||||||
|
|
||||||
return combineLatest([ welcomeAck, versionInstalled ]).pipe(
|
return combineLatest([ welcomeAck, versionInstalled ]).pipe(
|
||||||
filter( ([_, vi]) => !!vi),
|
filter(([_, vi]) => !!vi),
|
||||||
traceWheel('osWelcome'),
|
map(([wa, vi]) => !wa && vi === this.config.version ? vi : undefined),
|
||||||
take(1), // we will check and show welcome message at most once per app instance
|
|
||||||
concatMap(([wa, vi]) => iif(
|
|
||||||
() => !wa && vi === this.config.version,
|
|
||||||
this.presentOsWelcome(vi),
|
|
||||||
EMPTY,
|
|
||||||
)),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private autoUpdateCheck$ (): Observable<void> {
|
// emits versionLatest whenever autoCheckUpdates becomes true and checkForUpdates yields a new version
|
||||||
// this emits iff autoCheck is on and update available
|
private osUpdateAlertNeeded$ (): Observable<string | undefined> {
|
||||||
return this.osUpdateService.autoCheck$().pipe(
|
return this.server.watch().autoCheckUpdates.pipe(
|
||||||
traceWheel('autoUpdateCheck'),
|
filter(exists), //
|
||||||
filter(exists),
|
concatMap(() => this.osUpdateService.checkForUpdates$()),
|
||||||
concatMap(async vl => {
|
|
||||||
const { update } = await this.presentAlertNewOS(vl)
|
|
||||||
if (update) {
|
|
||||||
return this.loader.displayDuringP(
|
|
||||||
this.osUpdateService.updateEmbassyOS(vl),
|
|
||||||
).catch(e => alert(e))
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const newApps = await this.osUpdateService.checkForAppsUpdate()
|
|
||||||
if (newApps) {
|
|
||||||
return this.presentAlertNewApps()
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(`Exception checking for new apps: `, e)
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async presentUpdateDailogues (vl : string): Promise<any> {
|
||||||
|
const { update } = await this.presentAlertNewOS(vl)
|
||||||
|
if (update) {
|
||||||
|
return this.loader.displayDuringP(
|
||||||
|
this.osUpdateService.updateEmbassyOS(vl),
|
||||||
|
).catch(e => alert(e))
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const newApps = await this.osUpdateService.checkForAppsUpdate()
|
||||||
|
if (newApps) {
|
||||||
|
return this.presentAlertNewApps()
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Exception checking for new apps: `, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async presentOsWelcome (vi: string): Promise<void> {
|
private async presentOsWelcome (vi: string): Promise<void> {
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
const modal = await this.modalCtrl.create({
|
const modal = await this.modalCtrl.create({
|
||||||
|
|||||||
Reference in New Issue
Block a user