add warning and SteamId hook

This commit is contained in:
MathieuG-P
2022-06-27 22:32:58 +02:00
parent e09c245bcb
commit f518d5ef90
3 changed files with 34 additions and 18 deletions
+13 -2
View File
@@ -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]";
@@ -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); }
+16 -16
View File
@@ -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<BSVersion> = new BehaviorSubject(null);
public readonly downloadProgress$: BehaviorSubject<number> = new BehaviorSubject(0);
public readonly downloadWarning$: BehaviorSubject<string> = new BehaviorSubject(null);
public readonly selectedBsVersion$: BehaviorSubject<BSVersion> = new BehaviorSubject(null);
@@ -37,9 +39,11 @@ export class BsDownloaderService{
private asignListerners(): void{
this.ipcService.watch<number>("bs-download.[Progress]").pipe(distinctUntilChanged()).subscribe(response => {
this.downloadProgress$.next(response.data);
});
this.ipcService.watch<number>("bs-download.[Progress]").pipe(distinctUntilChanged()).subscribe(response => this.downloadProgress$.next(response.data));
this.ipcService.watch<string>("bs-download.[SteamID]").subscribe(response => response.success && this.authService.setSteamID(response.data));
this.ipcService.watch<string>("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;