mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-02 05:23:14 +00:00
quick cleanup
This commit is contained in:
committed by
Aiden McClelland
parent
c8740b09be
commit
a458e0b5bc
51
setup-wizard/src/app/services/state.service.ts
Normal file
51
setup-wizard/src/app/services/state.service.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { ApiService } from "./api/api.service"
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class StateService {
|
||||
loading = true
|
||||
|
||||
selectedDataDrive: string
|
||||
recoveryDrive: string
|
||||
hasPassword: Boolean
|
||||
dataTransferProgress: { bytesTransfered: number, totalBytes: number } | null
|
||||
dataProgress = 0
|
||||
|
||||
constructor (
|
||||
private readonly apiService: ApiService
|
||||
) {}
|
||||
|
||||
async getState () {
|
||||
const state = await this.apiService.getState()
|
||||
if(state) {
|
||||
this.selectedDataDrive = state['selected-data-drive']
|
||||
this.recoveryDrive = state['recovery-drive']
|
||||
this.hasPassword = state['has-password']
|
||||
|
||||
this.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
async pollDataTransferProgress () {
|
||||
if (
|
||||
this.dataTransferProgress?.totalBytes &&
|
||||
this.dataTransferProgress.bytesTransfered === this.dataTransferProgress.totalBytes
|
||||
) {return }
|
||||
const progress = await this.apiService.getDataTransferProgress()
|
||||
this.dataTransferProgress = {
|
||||
bytesTransfered: progress['bytes-transfered'],
|
||||
totalBytes: progress['total-bytes']
|
||||
}
|
||||
if (this.dataTransferProgress.totalBytes) {
|
||||
this.dataProgress = this.dataTransferProgress.bytesTransfered / this.dataTransferProgress.totalBytes
|
||||
}
|
||||
await pauseFor(7000)
|
||||
this.pollDataTransferProgress()
|
||||
}
|
||||
}
|
||||
|
||||
export function pauseFor (ms: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
Reference in New Issue
Block a user