quick cleanup

This commit is contained in:
Matt Hill
2021-06-29 17:55:11 -06:00
committed by Aiden McClelland
parent c8740b09be
commit a458e0b5bc
12 changed files with 18 additions and 108 deletions

View 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))
}