From 24630198ed6563f85f4ed4f47925eae5e0f8dc34 Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Tue, 28 Jun 2022 22:55:49 +0200 Subject: [PATCH] fix bs version download bugs --- src/main/ipcs/bs-download-ipcs.ts | 4 +- src/main/services/bs-installer.service.ts | 4 +- .../services/bs-downloader.service.ts | 38 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/ipcs/bs-download-ipcs.ts b/src/main/ipcs/bs-download-ipcs.ts index db76b380..f5735028 100644 --- a/src/main/ipcs/bs-download-ipcs.ts +++ b/src/main/ipcs/bs-download-ipcs.ts @@ -31,8 +31,8 @@ ipcMain.on('bs-download.start', async (event, request: IpcRequest) }); }); -ipcMain.on(`bs-download.${"[2FA]" as DownloadEventType}`, async (event, args) => { - BSInstallerService.getInstance().sendInputProcess(args); +ipcMain.on(`bs-download.${"[2FA]" as DownloadEventType}`, async (event, args: IpcRequest) => { + BSInstallerService.getInstance().sendInputProcess(args.args); }); ipcMain.on('bs-download.installation-folder', async (event, request: IpcRequest) => { diff --git a/src/main/services/bs-installer.service.ts b/src/main/services/bs-installer.service.ts index 9bb73413..a0bea0e3 100644 --- a/src/main/services/bs-installer.service.ts +++ b/src/main/services/bs-installer.service.ts @@ -104,10 +104,10 @@ export class BSInstallerService{ resolve({type: "[Password]", data: bsVersion}); } else if(out[0] === "[Guard]" as DownloadEventType){ - resolve({type: "[2FA]"}); + this.utils.newIpcSenc(`bs-download.${"[2FA]" as DownloadEventType}`, {success: true}); } else if(out[0] === "[2FA]" as DownloadEventType){ - resolve({type: "[2FA]"}); + this.utils.newIpcSenc(`bs-download.${"[2FA]" as DownloadEventType}`, {success: true}); } else if(out[0] === "[Progress]" as DownloadEventType || (out[0] === "[Validated]" as DownloadEventType && parseFloat(out[1]) < 100)){ this.utils.newIpcSenc(`bs-download.${"[Progress]" as DownloadEventType}`, {success: true, data: parseFloat(out[1])}); diff --git a/src/renderer/services/bs-downloader.service.ts b/src/renderer/services/bs-downloader.service.ts index 1e6b76aa..58b86875 100644 --- a/src/renderer/services/bs-downloader.service.ts +++ b/src/renderer/services/bs-downloader.service.ts @@ -45,6 +45,13 @@ export class BsDownloaderService{ this.ipcService.watch("bs-download.[Warning]").subscribe(response => response.success && this.downloadWarning$.next(response.data)); + this.ipcService.watch("bs-download.[2FA]").subscribe(async response => { + if(!response.success){ return; } + const res = await this.modalService.openModal(ModalType.GUARD_CODE); + if(res.exitCode !== ModalExitCode.COMPLETED){ return; } + this.ipcService.sendLazy('bs-download.[2FA]', {args: res.data}); + }); + this.currentBsVersionDownload$.subscribe(version => { if(version){ this.bsVersionManager.setInstalledVersions([...this.bsVersionManager.installedVersions$.value, version]); } else{ this.bsVersionManager.askInstalledVersions(); } @@ -57,13 +64,6 @@ export class BsDownloaderService{ this.selectedBsVersion$.next(null); } - public async send2FA(): Promise>{ - const res = await this.modalService.openModal(ModalType.GUARD_CODE); - if(res.exitCode !== ModalExitCode.COMPLETED){ return {success: false}; } - - return this.ipcService.send('bs-download.2FA', {args: res.data}); - } - public async download(bsVersion: BSVersion): Promise>{ let promise; if(!this.authService.sessionExist()){ @@ -75,20 +75,20 @@ export class BsDownloaderService{ else{ promise = this.ipcService.send('bs-download.start', {args: {bsVersion: bsVersion, username: this.authService.getSteamUsername()}}); } + this.currentBsVersionDownload$.next(bsVersion); - return promise.then(async res => { - if(!res.success){ return res; } - if(res.data.type === "[Password]"){ - this.authService.deleteSteamSession(); - res = await this.download(bsVersion); - } - else if(res.data.type === "[2FA]"){ - res = await this.send2FA(); - } - this.resetDownload(); - return res; - }); + let res = await promise; + + if(!res.success){ return res; } + + if(res.data.type === "[Password]"){ + this.authService.deleteSteamSession(); + res = await this.download(bsVersion); + } + + this.resetDownload(); + return res; } public get isDownloading(): boolean{