mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-01 21:13:09 +00:00
Bugfix/040 UI (#2881)
* fix sideload and install flow * move updates chevron inside upddate button * update dictionaries to include langauge names * fix: address todos (#2880) * fix: address todos * fix enlgish translation --------- Co-authored-by: Matt Hill <mattnine@protonmail.com> * use existing translation, no need to duplicate * fix: update dialog and other fixes (#2882) --------- Co-authored-by: Alex Inkin <alexander@inkin.ru> Co-authored-by: Aiden McClelland <me@drbonez.dev>
This commit is contained in:
56
web/projects/ui/src/app/services/os.service.ts
Normal file
56
web/projects/ui/src/app/services/os.service.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { PatchDB } from 'patch-db-client'
|
||||
import { BehaviorSubject, distinctUntilChanged, map, combineLatest } from 'rxjs'
|
||||
import { OSUpdate } from 'src/app/services/api/api.types'
|
||||
import { ApiService } from 'src/app/services/api/embassy-api.service'
|
||||
import { getServerInfo } from 'src/app/utils/get-server-info'
|
||||
import { DataModel } from './patch-db/data-model'
|
||||
import { Version } from '@start9labs/start-sdk'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class OSService {
|
||||
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]) => updating || backingUp))
|
||||
|
||||
readonly showUpdate$ = combineLatest([
|
||||
this.updateAvailable$,
|
||||
this.updating$,
|
||||
]).pipe(
|
||||
map(([available, updating]) => {
|
||||
return available && !updating
|
||||
}),
|
||||
)
|
||||
|
||||
constructor(
|
||||
private readonly api: ApiService,
|
||||
private readonly patch: PatchDB<DataModel>,
|
||||
) {}
|
||||
|
||||
async loadOS(): Promise<void> {
|
||||
const { version, id } = await getServerInfo(this.patch)
|
||||
this.osUpdate = await this.api.checkOSUpdate({ serverId: id })
|
||||
const updateAvailable =
|
||||
Version.parse(this.osUpdate.version).compare(Version.parse(version)) ===
|
||||
'greater'
|
||||
this.updateAvailable$.next(updateAvailable)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user