fix: reset sideload service after websocket completes (#2798)

* fix: reset sideload service after websocket completes

* chore: fix comment
This commit is contained in:
Alex Inkin
2024-12-12 03:14:01 +04:00
committed by GitHub
parent c675d0feee
commit e9d851e4d3
4 changed files with 2577 additions and 1919 deletions

View File

@@ -6,7 +6,7 @@ import cbor from 'cbor'
import { ApiService } from 'src/app/services/api/embassy-api.service'
import { ConfigService } from 'src/app/services/config.service'
import { SideloadService } from './sideload.service'
import { firstValueFrom } from 'rxjs'
import { filter, firstValueFrom } from 'rxjs'
import mime from 'mime'
interface Positions {
@@ -124,7 +124,7 @@ export class SideloadPage {
this.api
.uploadPackage(res.upload, this.toUpload.file!)
.catch(e => console.error(e))
await firstValueFrom(this.sideloadService.websocketConnected$)
await firstValueFrom(this.progress$.pipe(filter(Boolean)))
} catch (e: any) {
this.errorService.handleError(e)
} finally {

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core'
import { T } from '@start9labs/start-sdk'
import { endWith, ReplaySubject, shareReplay, Subject, switchMap } from 'rxjs'
import { BehaviorSubject, endWith, shareReplay, Subject, switchMap } from 'rxjs'
import { ApiService } from 'src/app/services/api/embassy-api.service'
@Injectable({
@@ -9,17 +9,9 @@ import { ApiService } from 'src/app/services/api/embassy-api.service'
export class SideloadService {
private readonly guid$ = new Subject<string>()
readonly websocketConnected$ = new ReplaySubject()
readonly progress$ = this.guid$.pipe(
switchMap(guid =>
this.api
.openWebsocket$<T.FullProgress>(guid, {
openObserver: {
next: () => this.websocketConnected$.next(''),
},
})
.pipe(endWith(null)),
this.api.openWebsocket$<T.FullProgress>(guid).pipe(endWith(null)),
),
shareReplay(1),
)