From 09c71caf3a543572d20d4ae729ac574eb4c72caa Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Thu, 26 May 2022 22:37:09 +0200 Subject: [PATCH] bug fix, and handle errors from download --- .../services/bs-downloader.service.ts | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/renderer/services/bs-downloader.service.ts b/src/renderer/services/bs-downloader.service.ts index de5cc3d8..1a51ea56 100644 --- a/src/renderer/services/bs-downloader.service.ts +++ b/src/renderer/services/bs-downloader.service.ts @@ -14,10 +14,20 @@ export class BsDownloaderService{ public readonly currentBsVersionDownload$: BehaviorSubject = new BehaviorSubject(null); public readonly downloadProgress$: BehaviorSubject = new BehaviorSubject(0); + public static getInstance(): BsDownloaderService{ + if(!BsDownloaderService.instance){ BsDownloaderService.instance = new BsDownloaderService(); } + return BsDownloaderService.instance; + } + private constructor(){ + this.asignListerners(); + } + + private asignListerners(): void{ window.electron.ipcRenderer.on(`bs-download.[Password]`, async (bsVersion: BSVersion) => { const res = await this.modalService.openModal(ModalType.STEAM_LOGIN); if(res.exitCode !== ModalExitCode.COMPLETED){ return; } + if(res.data.stay){ localStorage.setItem("username", res.data.username); } window.electron.ipcRenderer.sendMessage('bs-download.start', {bsVersion: bsVersion, username: res.data.username, password: res.data.password, stay: res.data.stay} as DownloadInfo) this.currentBsVersionDownload$.next(bsVersion); }); @@ -38,6 +48,11 @@ export class BsDownloaderService{ this.downloadProgress$.next(progress); }); + window.electron.ipcRenderer.on("bs-download.[Error]", async () => { + this.currentBsVersionDownload$.next(null); + this.downloadProgress$.next(0); + }); + this.currentBsVersionDownload$.subscribe(version => { if(version){ this.bsVersionManager.setInstalledVersions([...this.bsVersionManager.installedVersions$.value, version]); @@ -45,15 +60,10 @@ export class BsDownloaderService{ else{ this.bsVersionManager.askInstalledVersions(); } - }) + }); } - public static getInstance(){ - if(!BsDownloaderService.instance){ BsDownloaderService.instance = new BsDownloaderService(); } - return BsDownloaderService.instance; - } - - public async download(bsVersion: BSVersion){ + public async download(bsVersion: BSVersion): Promise{ let username = localStorage.getItem("username"); if(!username){ const res = await this.modalService.openModal(ModalType.STEAM_LOGIN);