mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
ui: adds a banner to the marketplace page when an OS update is detected
This commit is contained in:
committed by
Aiden McClelland
parent
6da3c7e326
commit
89ff5de01b
@@ -420,7 +420,7 @@ const mockApiServer: () => ReqRes.GetServerRes = () => ({
|
||||
})
|
||||
|
||||
const mockVersionLatest: ReqRes.GetVersionLatestRes = {
|
||||
versionLatest: '0.2.8',
|
||||
versionLatest: '15.2.8',
|
||||
canUpdate: true,
|
||||
}
|
||||
|
||||
|
||||
48
ui/src/app/services/os-update.service.ts
Normal file
48
ui/src/app/services/os-update.service.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { NavController } from '@ionic/angular'
|
||||
import { BehaviorSubject, forkJoin, Observable, of } from 'rxjs'
|
||||
import { catchError, map, take, tap } from 'rxjs/operators'
|
||||
import { ServerModel, ServerStatus } from '../models/server-model'
|
||||
import { ApiService } from './api/api.service'
|
||||
import { Emver } from './emver.service'
|
||||
|
||||
|
||||
// call checkForUpdates in marketplace pages, can subscribe globally however
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class OsUpdateService {
|
||||
private readonly $updateAvailable$ = new BehaviorSubject(undefined)
|
||||
|
||||
constructor (
|
||||
private readonly emver: Emver,
|
||||
private readonly serverModel: ServerModel,
|
||||
private readonly apiService: ApiService,
|
||||
private readonly navCtrl: NavController,
|
||||
) { }
|
||||
|
||||
watchForUpdateAvailable (): Observable<undefined | string> {
|
||||
return this.$updateAvailable$.asObservable()
|
||||
}
|
||||
|
||||
// undefined when no update available, string for the versionLatest if there is
|
||||
checkForUpdates (): Promise<undefined | string> {
|
||||
return forkJoin([
|
||||
this.apiService.getVersionLatest(),
|
||||
this.serverModel.watch().versionInstalled.pipe(take(1)),
|
||||
]).pipe(
|
||||
map(([vl, vi]) => this.emver.compare(vi, vl.versionLatest) === -1 ? vl.versionLatest : undefined),
|
||||
catchError(e => {
|
||||
console.error(`OsUpdateService Error: ${e}`)
|
||||
return of(undefined)
|
||||
}),
|
||||
// cache the result for components to learn update available without having to have called this method
|
||||
tap(updateAvailable => this.$updateAvailable$.next(updateAvailable)),
|
||||
).toPromise()
|
||||
}
|
||||
|
||||
async updateEmbassyOS (versionLatest: string): Promise<void> {
|
||||
await this.apiService.updateAgent(versionLatest)
|
||||
this.serverModel.update({ status: ServerStatus.UPDATING })
|
||||
this.$updateAvailable$.next(undefined)
|
||||
await this.navCtrl.navigateRoot('/embassy')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user