From f518d5ef90b20e37a8909e3011faa8f0d5178303 Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Mon, 27 Jun 2022 22:32:58 +0200 Subject: [PATCH] add warning and SteamId hook --- src/main/services/bs-installer.service.ts | 15 +++++++-- src/renderer/services/auth-user.service.ts | 5 +++ .../services/bs-downloader.service.ts | 32 +++++++++---------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/main/services/bs-installer.service.ts b/src/main/services/bs-installer.service.ts index e92def74..9bb73413 100644 --- a/src/main/services/bs-installer.service.ts +++ b/src/main/services/bs-installer.service.ts @@ -6,6 +6,7 @@ import { UtilsService } from "./utils.service"; import { ChildProcessWithoutNullStreams, spawn } from "child_process"; import log from "electron-log"; import { InstallationLocationService } from "./installation-location.service"; +import { of } from "rxjs"; export class BSInstallerService{ @@ -102,7 +103,7 @@ export class BSInstallerService{ this.downloadProcess.kill(); resolve({type: "[Password]", data: bsVersion}); } - else if(out[0] === "[2FA]" as DownloadEventType){ + else if(out[0] === "[Guard]" as DownloadEventType){ resolve({type: "[2FA]"}); } else if(out[0] === "[2FA]" as DownloadEventType){ @@ -115,8 +116,15 @@ export class BSInstallerService{ resolve({type: "[Finished]"}); this.downloadProcess.kill(); } + else if(out[0] === "[SteamID]" as DownloadEventType){ + this.utils.newIpcSenc("bs-download.[SteamID]", {success: true, data: out[1]}); + } + else if(out[0] === "[Warning]" as DownloadEventType){ + this.utils.newIpcSenc("bs-download.[Warning]", {success: true, data: out[1]}); + } else if(out[0] === "[Error]" as DownloadEventType){ reject(out); + this.downloadProcess.kill(); log.error("Download Event, Error", data.toString()); } }); @@ -125,14 +133,17 @@ export class BSInstallerService{ this.downloadProcess.stdout.on('error', (err) => { log.error("BS-DOWNLOAD ERROR", err.toString()); + this.downloadProcess.kill(); reject(err); }); this.downloadProcess.stderr.on('data', (err) => { log.error("BS-DOWNLOAD ERROR", err.toString()); + this.downloadProcess.kill(); reject(err); }); this.downloadProcess.stderr.on('error', (err) => { log.error("BS-DOWNLOAD ERROR", err.toString()); + this.downloadProcess.kill(); reject(err); }); @@ -156,4 +167,4 @@ export interface DownloadEvent{ data?: any, } -export type DownloadEventType = "[Password]" | "[Guard]" | "[2FA]" | "[Progress]" | "[Validated]" | "[Finished]" | "[AlreadyDownloading]" | "[Error]"; +export type DownloadEventType = "[Password]" | "[Guard]" | "[2FA]" | "[Progress]" | "[Validated]" | "[Finished]" | "[AlreadyDownloading]" | "[Error]" | "[Warning]" | "[SteamID]"; diff --git a/src/renderer/services/auth-user.service.ts b/src/renderer/services/auth-user.service.ts index cb36ef32..c2861aea 100644 --- a/src/renderer/services/auth-user.service.ts +++ b/src/renderer/services/auth-user.service.ts @@ -7,6 +7,7 @@ export class AuthUserService { private readonly configService: ConfigurationService; private readonly STEAM_USERNAME_KEY = "STEAM-USERNAME"; + private readonly STEAM_ID_KEY = "STEAM-ID"; public static getInstance(): AuthUserService{ if(!AuthUserService.instance){ AuthUserService.instance = new AuthUserService() } @@ -25,6 +26,10 @@ export class AuthUserService { this.configService.set(this.STEAM_USERNAME_KEY, username, stay); } + public setSteamID(steamID: string): void{ + this.configService.set(this.STEAM_ID_KEY, steamID); + } + public getSteamUsername(): string{ return this.configService.get(this.STEAM_USERNAME_KEY); } public deleteSteamSession(): void { this.configService.delete(this.STEAM_USERNAME_KEY); } diff --git a/src/renderer/services/bs-downloader.service.ts b/src/renderer/services/bs-downloader.service.ts index 30690c06..1e6b76aa 100644 --- a/src/renderer/services/bs-downloader.service.ts +++ b/src/renderer/services/bs-downloader.service.ts @@ -5,6 +5,7 @@ import { DownloadInfo } from '../../main/ipcs/bs-download-ipcs'; import { BSVersion } from '../../main/services/bs-version-manager.service' import { AuthUserService } from './auth-user.service'; import { BSVersionManagerService } from './bs-version-manager.service'; +import { ConfigurationService } from './configuration.service'; import { IpcService } from './ipc.service'; import { ModalExitCode, ModalService, ModalType } from './modale.service'; @@ -15,10 +16,11 @@ export class BsDownloaderService{ private readonly modalService: ModalService; private readonly ipcService: IpcService; private readonly bsVersionManager: BSVersionManagerService; - public readonly authService: AuthUserService; + private readonly authService: AuthUserService; public readonly currentBsVersionDownload$: BehaviorSubject = new BehaviorSubject(null); public readonly downloadProgress$: BehaviorSubject = new BehaviorSubject(0); + public readonly downloadWarning$: BehaviorSubject = new BehaviorSubject(null); public readonly selectedBsVersion$: BehaviorSubject = new BehaviorSubject(null); @@ -37,9 +39,11 @@ export class BsDownloaderService{ private asignListerners(): void{ - this.ipcService.watch("bs-download.[Progress]").pipe(distinctUntilChanged()).subscribe(response => { - this.downloadProgress$.next(response.data); - }); + this.ipcService.watch("bs-download.[Progress]").pipe(distinctUntilChanged()).subscribe(response => this.downloadProgress$.next(response.data)); + + this.ipcService.watch("bs-download.[SteamID]").subscribe(response => response.success && this.authService.setSteamID(response.data)); + + this.ipcService.watch("bs-download.[Warning]").subscribe(response => response.success && this.downloadWarning$.next(response.data)); this.currentBsVersionDownload$.subscribe(version => { if(version){ this.bsVersionManager.setInstalledVersions([...this.bsVersionManager.installedVersions$.value, version]); } @@ -73,18 +77,14 @@ export class BsDownloaderService{ } this.currentBsVersionDownload$.next(bsVersion); - return promise.then(res => { - if(res.success){ - if(res.data.type === "[Password]"){ - this.authService.deleteSteamSession(); - return this.download(bsVersion); - } - else if(res.data.type === "[2FA]"){ - return this.send2FA().then(res => { - this.resetDownload(); - return res; - }); - } + 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;