mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-02 05:23:14 +00:00
* wip * restructure backend for new ui structure * new patchdb bootstrap, single websocket api, local storage migration, more * update db websocket * init apis * update patch-db * setup progress * feat: implement state service, alert and routing Signed-off-by: waterplea <alexander@inkin.ru> * update setup wizard for new types * feat: add init page Signed-off-by: waterplea <alexander@inkin.ru> * chore: refactor message, patch-db source stream and connection service Signed-off-by: waterplea <alexander@inkin.ru> * fix method not found on state * fix backend bugs * fix compat assets * address comments * remove unneeded styling * cleaner progress * bugfixes * fix init logs * fix progress reporting * fix navigation by getting state after init * remove patch dependency from live api * fix caching * re-add patchDB to live api * fix metrics values * send close frame * add bootId and fix polling --------- Signed-off-by: waterplea <alexander@inkin.ru> Co-authored-by: Aiden McClelland <me@drbonez.dev> Co-authored-by: waterplea <alexander@inkin.ru>
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { Injectable } from '@angular/core'
|
|
import { Emver } from '@start9labs/shared'
|
|
import { BehaviorSubject, combineLatest } from 'rxjs'
|
|
import { distinctUntilChanged, map } from 'rxjs/operators'
|
|
import { OSUpdate } from 'src/app/services/api/api.types'
|
|
import { ApiService } from 'src/app/services/api/embassy-api.service'
|
|
import { PatchDB } from 'patch-db-client'
|
|
import { getServerInfo } from 'src/app/util/get-server-info'
|
|
import { DataModel } from './patch-db/data-model'
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class EOSService {
|
|
osUpdate?: OSUpdate
|
|
updateAvailable$ = new BehaviorSubject<boolean>(false)
|
|
|
|
readonly updating$ = this.patch.watch$('serverInfo', 'statusInfo').pipe(
|
|
map(status => !!status.updateProgress || status.updated),
|
|
distinctUntilChanged(),
|
|
)
|
|
|
|
readonly backingUp$ = this.patch
|
|
.watch$('serverInfo', 'statusInfo', 'backupProgress')
|
|
.pipe(
|
|
map(obj => !!obj),
|
|
distinctUntilChanged(),
|
|
)
|
|
|
|
readonly updatingOrBackingUp$ = combineLatest([
|
|
this.updating$,
|
|
this.backingUp$,
|
|
]).pipe(
|
|
map(([updating, backingUp]) => {
|
|
return updating || backingUp
|
|
}),
|
|
)
|
|
|
|
readonly showUpdate$ = combineLatest([
|
|
this.updateAvailable$,
|
|
this.updating$,
|
|
]).pipe(
|
|
map(([available, updating]) => {
|
|
return available && !updating
|
|
}),
|
|
)
|
|
|
|
constructor(
|
|
private readonly api: ApiService,
|
|
private readonly emver: Emver,
|
|
private readonly patch: PatchDB<DataModel>,
|
|
) {}
|
|
|
|
async loadEos(): Promise<void> {
|
|
const { version, id } = await getServerInfo(this.patch)
|
|
this.osUpdate = await this.api.checkOSUpdate({ serverId: id })
|
|
const updateAvailable =
|
|
this.emver.compare(this.osUpdate.version, version) === 1
|
|
this.updateAvailable$.next(updateAvailable)
|
|
}
|
|
}
|