mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 22:39:46 +00:00
ui: finalize PR
This commit is contained in:
committed by
Aiden McClelland
parent
39accaa382
commit
ba04b7c431
@@ -7,16 +7,10 @@ import { Storage } from '@ionic/storage'
|
|||||||
import { throttleTime, delay } from 'rxjs/operators'
|
import { throttleTime, delay } from 'rxjs/operators'
|
||||||
import { StorageKeys } from './storage-keys'
|
import { StorageKeys } from './storage-keys'
|
||||||
|
|
||||||
export enum ServerModelState {
|
|
||||||
BOOT,
|
|
||||||
LOCALSTORAGE,
|
|
||||||
LIVE,
|
|
||||||
}
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class ServerModel {
|
export class ServerModel {
|
||||||
$modelState$ = new BehaviorSubject(ServerModelState.BOOT)
|
|
||||||
lastUpdateTimestamp: Date
|
lastUpdateTimestamp: Date
|
||||||
$delta$ = new Subject<void>()
|
$delta$ = new Subject<void>()
|
||||||
private embassy: PropertySubject<S9Server>
|
private embassy: PropertySubject<S9Server>
|
||||||
@@ -32,7 +26,6 @@ export class ServerModel {
|
|||||||
).subscribe(() => {
|
).subscribe(() => {
|
||||||
this.commitCache()
|
this.commitCache()
|
||||||
})
|
})
|
||||||
this.$modelState$.subscribe(s => console.log('model state', s))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// client fxns
|
// client fxns
|
||||||
@@ -44,12 +37,6 @@ export class ServerModel {
|
|||||||
return peekProperties(this.embassy)
|
return peekProperties(this.embassy)
|
||||||
}
|
}
|
||||||
|
|
||||||
nextState (s: ServerModelState) {
|
|
||||||
this.$modelState$.subscribe(s2 => {
|
|
||||||
if (s > s2) this.$modelState$.next(s)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
update (update: Partial<S9Server>, timestamp: Date = new Date()): void {
|
update (update: Partial<S9Server>, timestamp: Date = new Date()): void {
|
||||||
if (this.lastUpdateTimestamp > timestamp) return
|
if (this.lastUpdateTimestamp > timestamp) return
|
||||||
|
|
||||||
@@ -90,7 +77,7 @@ export class ServerModel {
|
|||||||
|
|
||||||
async restoreCache (): Promise<void> {
|
async restoreCache (): Promise<void> {
|
||||||
const emb = await this.storage.get(StorageKeys.SERVER_CACHE_KEY)
|
const emb = await this.storage.get(StorageKeys.SERVER_CACHE_KEY)
|
||||||
if (emb && emb.versionInstalled === this.config.version) this.update(emb, new Date())
|
if (emb && emb.versionInstalled === this.config.version) this.update(emb)
|
||||||
}
|
}
|
||||||
|
|
||||||
// server state change
|
// server state change
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export class OsUpdateService {
|
|||||||
this.serverModel.watch().versionInstalled.pipe(take(1)),
|
this.serverModel.watch().versionInstalled.pipe(take(1)),
|
||||||
this.apiService.getVersionLatest(),
|
this.apiService.getVersionLatest(),
|
||||||
]).pipe(
|
]).pipe(
|
||||||
map(([vi, vl]) => updateIsAvailable(this.emver, vi, vl.versionLatest)),
|
map(([vi, vl]) => this.updateIsAvailable(vi, vl.versionLatest) ? vl : undefined),
|
||||||
catchError(e => {
|
catchError(e => {
|
||||||
console.error(`OsUpdateService Error: ${e}`)
|
console.error(`OsUpdateService Error: ${e}`)
|
||||||
return of(undefined)
|
return of(undefined)
|
||||||
@@ -59,11 +59,6 @@ export class OsUpdateService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkForAppsUpdate (): Promise<boolean> {
|
|
||||||
const availableApps = await this.apiService.getAvailableApps()
|
|
||||||
return !!availableApps.find(app => this.emver.compare(app.versionInstalled, app.versionLatest) === -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateEmbassyOS (versionLatest: string): Promise<void> {
|
async updateEmbassyOS (versionLatest: string): Promise<void> {
|
||||||
await this.apiService.updateAgent(versionLatest)
|
await this.apiService.updateAgent(versionLatest)
|
||||||
this.serverModel.update({ status: ServerStatus.UPDATING })
|
this.serverModel.update({ status: ServerStatus.UPDATING })
|
||||||
@@ -71,8 +66,3 @@ export class OsUpdateService {
|
|||||||
await this.navCtrl.navigateRoot('/embassy')
|
await this.navCtrl.navigateRoot('/embassy')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateIsAvailable (e: Emver, vi: string, vl: string): string | undefined {
|
|
||||||
if (!vi || !vl) return undefined
|
|
||||||
return e.compare(vi, vl) === -1 ? vl : undefined
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"useMocks": true
|
"useMocks": false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user