mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +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 { StorageKeys } from './storage-keys'
|
||||
|
||||
export enum ServerModelState {
|
||||
BOOT,
|
||||
LOCALSTORAGE,
|
||||
LIVE,
|
||||
}
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ServerModel {
|
||||
$modelState$ = new BehaviorSubject(ServerModelState.BOOT)
|
||||
lastUpdateTimestamp: Date
|
||||
$delta$ = new Subject<void>()
|
||||
private embassy: PropertySubject<S9Server>
|
||||
@@ -32,7 +26,6 @@ export class ServerModel {
|
||||
).subscribe(() => {
|
||||
this.commitCache()
|
||||
})
|
||||
this.$modelState$.subscribe(s => console.log('model state', s))
|
||||
}
|
||||
|
||||
// client fxns
|
||||
@@ -44,12 +37,6 @@ export class ServerModel {
|
||||
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 {
|
||||
if (this.lastUpdateTimestamp > timestamp) return
|
||||
|
||||
@@ -90,7 +77,7 @@ export class ServerModel {
|
||||
|
||||
async restoreCache (): Promise<void> {
|
||||
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
|
||||
|
||||
@@ -38,7 +38,7 @@ export class OsUpdateService {
|
||||
this.serverModel.watch().versionInstalled.pipe(take(1)),
|
||||
this.apiService.getVersionLatest(),
|
||||
]).pipe(
|
||||
map(([vi, vl]) => updateIsAvailable(this.emver, vi, vl.versionLatest)),
|
||||
map(([vi, vl]) => this.updateIsAvailable(vi, vl.versionLatest) ? vl : undefined),
|
||||
catchError(e => {
|
||||
console.error(`OsUpdateService Error: ${e}`)
|
||||
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> {
|
||||
await this.apiService.updateAgent(versionLatest)
|
||||
this.serverModel.update({ status: ServerStatus.UPDATING })
|
||||
@@ -71,8 +66,3 @@ export class OsUpdateService {
|
||||
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