Feat/update progress (#1944)

* uodate FE to show progress once calculated

* update mocks

* only show progress when known

Co-authored-by: Aiden McClelland <me@drbonez.dev>
This commit is contained in:
Matt Hill
2022-11-15 20:57:03 -07:00
committed by Aiden McClelland
parent 5b91b5f436
commit 18ee1e2685
9 changed files with 59 additions and 32 deletions

View File

@@ -135,7 +135,7 @@ async fn maybe_do_update(
}; };
status.update_progress = Some(UpdateProgress { status.update_progress = Some(UpdateProgress {
size: Some(100), size: None,
downloaded: 0, downloaded: 0,
}); });
status.save(&mut tx).await?; status.save(&mut tx).await?;
@@ -301,7 +301,7 @@ async fn copy_ssh_host_keys() -> Result<(), Error> {
async fn sync_boot() -> Result<(), Error> { async fn sync_boot() -> Result<(), Error> {
Rsync::new( Rsync::new(
"/media/embassy/next/boot/", "/media/embassy/next/boot/",
"/boot", "/boot/",
RsyncOptions { RsyncOptions {
delete: false, delete: false,
force: false, force: false,

View File

@@ -4,13 +4,30 @@
[@heightCollapse]="animation" [@heightCollapse]="animation"
> >
<ion-list class="list"> <ion-list class="list">
<ion-list-header> <!-- show progress -->
<ion-label>Downloading EOS: {{ getProgress(progress) }}%</ion-label> <ng-container *ngIf="progress.size !== null; else calculating">
</ion-list-header> <ion-list-header>
<ion-progress-bar <ion-label
class="progress" >Downloading:
color="secondary" {{ getProgress(progress.size, progress.downloaded) }}%</ion-label
[value]="getProgress(progress) / 100" >
></ion-progress-bar> </ion-list-header>
<ion-progress-bar
class="progress"
color="secondary"
[value]="getProgress(progress.size, progress.downloaded) / 100"
></ion-progress-bar>
</ng-container>
<!-- show calculating -->
<ng-template #calculating>
<ion-list-header>
<ion-label>Calculating download size</ion-label>
</ion-list-header>
<ion-progress-bar
class="progress"
color="secondary"
type="indeterminate"
></ion-progress-bar>
</ng-template>
</ion-list> </ion-list>
</ion-toolbar> </ion-toolbar>

View File

@@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'
import { heightCollapse } from '../../util/animations' import { heightCollapse } from '../../util/animations'
import { PatchDB } from 'patch-db-client' import { PatchDB } from 'patch-db-client'
import { map } from 'rxjs/operators' import { map } from 'rxjs/operators'
import { DataModel, ServerInfo } from '../../services/patch-db/data-model' import { DataModel } from '../../services/patch-db/data-model'
@Component({ @Component({
selector: 'footer[appFooter]', selector: 'footer[appFooter]',
@@ -26,10 +26,7 @@ export class FooterComponent {
constructor(private readonly patch: PatchDB<DataModel>) {} constructor(private readonly patch: PatchDB<DataModel>) {}
getProgress({ getProgress(size: number, downloaded: number): number {
downloaded, return Math.round((100 * downloaded) / (size || 1))
size,
}: NonNullable<ServerInfo['status-info']['update-progress']>): number {
return Math.round((100 * (downloaded || 1)) / (size || 1))
} }
} }

View File

@@ -1,7 +1,7 @@
<toast <toast
*ngIf="visible$ | async as message" *ngIf="visible$ | async as message"
class="success-toast" class="success-toast"
header="EOS download complete!" header="embassyOS download complete!"
(dismiss)="onDismiss()" (dismiss)="onDismiss()"
> >
Restart your Embassy for these updates to take effect. It can take several Restart your Embassy for these updates to take effect. It can take several

View File

@@ -40,7 +40,7 @@ export class ToOptionsPipe implements PipeTransform {
} }
private compare(version: string): boolean { private compare(version: string): boolean {
// checks to see if backup was made on a newer version of EOS // checks to see if backup was made on a newer version of eOS
return this.emver.compare(version, this.config.version) === 1 return this.emver.compare(version, this.config.version) === 1
} }
} }

View File

@@ -232,12 +232,12 @@ export class MockApiService extends ApiService {
async updateServer(url?: string): Promise<RR.UpdateServerRes> { async updateServer(url?: string): Promise<RR.UpdateServerRes> {
await pauseFor(2000) await pauseFor(2000)
const initialProgress = { const initialProgress = {
size: 10000, size: null,
downloaded: 0, downloaded: 0,
} }
setTimeout(() => { setTimeout(() => {
this.updateOSProgress(initialProgress.size) this.updateOSProgress()
}, 500) }, 500)
const patch = [ const patch = [
@@ -916,8 +916,19 @@ export class MockApiService extends ApiService {
}, 1000) }, 1000)
} }
private async updateOSProgress(size: number) { private async updateOSProgress() {
let size = 10000
let downloaded = 0 let downloaded = 0
const patch0 = [
{
op: PatchOp.REPLACE,
path: `/server-info/status-info/update-progress/size`,
value: size,
},
]
this.mockRevision(patch0)
while (downloaded < size) { while (downloaded < size) {
await pauseFor(250) await pauseFor(250)
downloaded += 500 downloaded += 500

View File

@@ -22,7 +22,7 @@ export class PatchDataService extends Observable<DataModel> {
switchMap(() => this.patch.watch$()), switchMap(() => this.patch.watch$()),
take(1), take(1),
tap(({ ui }) => { tap(({ ui }) => {
// check for updates to EOS and services // check for updates to eOS and services
this.checkForUpdates() this.checkForUpdates()
// show eos welcome message // show eos welcome message
this.showEosWelcome(ui['ack-welcome']) this.showEosWelcome(ui['ack-welcome'])

View File

@@ -12,7 +12,7 @@ export interface DataModel {
export interface UIData { export interface UIData {
name: string | null name: string | null
'pkg-order': string[] 'pkg-order': string[]
'ack-welcome': string // EOS emver 'ack-welcome': string // eOS emver
marketplace: UIMarketplaceData marketplace: UIMarketplaceData
dev: DevData dev: DevData
gaming: { gaming: {

View File

@@ -98,15 +98,17 @@ impl Rsync {
}) })
.lines(); .lines();
while let Some(line) = lines.next_line().await? { while let Some(line) = lines.next_line().await? {
if let Some(percentage) = line if line.contains(" to-chk=0/") {
.split_ascii_whitespace() if let Some(percentage) = line
.find_map(|col| col.strip_suffix("%")) .split_ascii_whitespace()
{ .find_map(|col| col.strip_suffix("%"))
if let Err(err) = send.send(percentage.parse::<f64>()? / 100.0) { {
return Err(Error::new( if let Err(err) = send.send(percentage.parse::<f64>()? / 100.0) {
eyre!("rsync progress send error: {}", err), return Err(Error::new(
ErrorKind::Filesystem, eyre!("rsync progress send error: {}", err),
)); ErrorKind::Filesystem,
));
}
} }
} }
} }