add guard code modal

This commit is contained in:
MathieuG-P
2022-05-20 21:02:16 +02:00
parent e5a39a021e
commit e8621c257d
11 changed files with 52 additions and 36 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+6 -30
View File
@@ -3,7 +3,7 @@ import path from 'path';
import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
import { UtilsService } from '../services/utils.service';
import { BSVersion } from '../services/bs-version-manager.service';
import { BSInstallerService } from '../services/bs-installer.service';
import { BSInstallerService, DownloadEventType } from '../services/bs-installer.service';
export interface InitDownloadInfoInterface {
@@ -23,36 +23,12 @@ export interface DownloadInfo {
stay?: boolean
}
const DEPOT_DOWNLOADER_EXE = 'DepotDownloader.exe';
let PROCESS: ChildProcessWithoutNullStreams;
ipcMain.on('bs-download.start', async (event, args: DownloadInfo) => {
BSInstallerService.getInstance().downloadBsVersion(args);
return;
const DEPOT_DOWNLOADER_PATH = path.join(UtilsService.getInstance().getAssetsPath(), 'depot-downloader', DEPOT_DOWNLOADER_EXE);
console.log(UtilsService.getInstance().getAssetsPath());
console.log(DEPOT_DOWNLOADER_PATH);
console.log(args.cwd);
UtilsService.getInstance().createFolderIfNotExist(args.cwd);
PROCESS = spawn(DEPOT_DOWNLOADER_PATH, [`-app ${args.app}`, `-depot ${args.depot}`, `-manifest ${args.manifest}`, `-username ${args.username}`, `-dir ${args.folder}`, args.stay ? `-remember-password` : ''], {shell: true, cwd: args.cwd});
PROCESS.stdout.on('data', data => {
const out: string[] = data.toString().split('|');
console.log(out);
if(out[0] === "[Progress]"){ event.reply('bs-download.progress', out[1]); }
else if(out[0] === "[Password]"){ event.reply('bs-download.not-connected', args.bsVersion); PROCESS.kill(); }
else if(out[0] === "[2FA]"){ event.reply('bs-download.ask-2fa'); }
else if(out[0] === "[Guard]"){ event.reply('bs-download.ask-guard'); }
else if(out[0] === "[Error]"){ event.reply('bs-download.error', out); }
});
PROCESS.stderr.on('data', (data) => {console.log(data.toString())});
});
ipcMain.on('bs-download.enter-password', async (event, value: string) => {
if(PROCESS){ PROCESS.stdin.write(`${value}\n`); }
});
ipcMain.on(`bs-download${DownloadEventType.GUARD_CODE}`, async (event, args) => {
BSInstallerService.getInstance().sendInputProcess(args);
})
+1 -3
View File
@@ -1,8 +1,6 @@
import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron';
export type Channels = 'bs-download.start'|'bs-download.send-input'|'window.close'|'window.maximize'|'window.minimize'|'window.reset';
export type ReplyChannels = 'bs-download.ask-password';
export type Channels = any;
contextBridge.exposeInMainWorld('electron', {
ipcRenderer: {
+6 -2
View File
@@ -91,13 +91,17 @@ export class BSInstallerService{
this.downloadProcess.stdout.on('data', (data) => {
console.log(data.toString());
const out = (data.toString() as string).split("|");
if(out[0] === DownloadEventType.NOT_LOGGED_IN && downloadInfos.password){ this.sendInputProcess(downloadInfos.password); }
if(out[0] === DownloadEventType.NOT_LOGGED_IN && downloadInfos.password){ setTimeout(() => {this.sendInputProcess(downloadInfos.password);}, 2000) }
else if(out[0] === DownloadEventType.NOT_LOGGED_IN){ this.downloadProcess.kill(); this.utils.ipcSend(`bs-download.${DownloadEventType.NOT_LOGGED_IN}`); }
else if(out[0] === DownloadEventType.GUARD_CODE){ this.utils.ipcSend(`bs-download.${DownloadEventType.GUARD_CODE}`); }
else if(out[0] === DownloadEventType.TWO_FA_CODE){ this.utils.ipcSend(`bs-download.${DownloadEventType.TWO_FA_CODE}`); }
else if(out[0] === DownloadEventType.PROGESS){ this.utils.ipcSend(`bs-download.${DownloadEventType.PROGESS}`, parseFloat(out[1])); }
else if(out[0] === DownloadEventType.FINISH){ this.utils.ipcSend(`bs-download.${DownloadEventType.FINISH}`); this.downloadProcess.kill(); }
else if(out[0] === DownloadEventType.ERROR){ this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`); this.downloadProcess.kill(); }
else if(out[0] === DownloadEventType.ERROR){
console.log("ERROR");
this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`);
this.downloadProcess.kill('SIGINT');
}
})
this.downloadProcess.stdout.on('error', err => {
@@ -0,0 +1,28 @@
import { ModalExitCode, ModalResponse } from "../../../services/modale.service";
import { useState } from "react";
import BeatConflict from "../../../../../assets/beat-conflict.png"
export function GuardModal({resolver}: {resolver: (x: ModalResponse) => void}) {
const [guardCode, setGuardCode] = useState('');
const loggin = () => resolver({exitCode: ModalExitCode.COMPLETED, data: guardCode});
const cancel = () => resolver({exitCode: ModalExitCode.CANCELED});
return (
<form className="p-4 bg-main-color-2 text-gray-200 overflow-hidden rounded-md shadow-lg shadow-black">
<h1 className="w-full text-center font-bold text-2xl">Steam Guard</h1>
<div className="w-full flex justify-center content-center items-center">
<img className="aspect-square object-cover w-28" src={BeatConflict} />
</div>
<div className="flex flex-col">
<label className="font-bold" htmlFor="guard">Guard Code</label>
<input className="bg-main-color-3 p-1 pr-2 pl-2 rounded-md" onChange={e => setGuardCode(e.target.value)} value={guardCode} type="guard" name="guard" id="guard" placeholder="Enter your Guard code"/>
</div>
<div className="w-full flex justify-center items-center content-center">
<button onClick={cancel} className="mr-4">Cancel</button>
<button onClick={loggin}>LogIn</button>
</div>
</form>
)
}
@@ -4,6 +4,7 @@ import { useEffect, useState } from "react"
import { distinctUntilChanged } from "rxjs";
import { LoginModal } from "./modal-types/login-modal.component";
import { GuardModal } from "./modal-types/guard-modal.component";
export function Modal() {
@@ -23,6 +24,7 @@ export function Modal() {
<span onClick={() => modalSevice.resolve({exitCode: ModalExitCode.NO_CHOICE})} className={`absolute top-0 bottom-0 right-0 left-0 transition-opacity bg-black ${modalType? "opacity-40" : "opacity-0"}`}></span>
<div className={`absolute transition-transform ${modalType ? "translate-y-0" : "translate-y-full"}`}>
{modalType === ModalType.STEAM_LOGIN && <LoginModal resolver={modalSevice.getResolver()}/>}
{modalType === ModalType.GUARD_CODE && <GuardModal resolver={modalSevice.getResolver()}/>}
</div>
</div>
)
@@ -9,11 +9,18 @@ export class BsDownloaderService{
private readonly modalService: ModalService = ModalService.getInsance();
private constructor(){
window.electron.ipcRenderer.on('bs-download.not-connected', async (bsVersion: BSVersion) => {
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; }
window.electron.ipcRenderer.sendMessage('bs-download.start', {bsVersion: bsVersion, username: res.data.username, password: res.data.password, stay: res.data.stay} as DownloadInfo)
});
window.electron.ipcRenderer.on(`bs-download.[Guard]`, async () => {
console.log("GUARD");
const res = await this.modalService.openModal(ModalType.GUARD_CODE);
if(res.exitCode != ModalExitCode.COMPLETED){ return; }
window.electron.ipcRenderer.sendMessage(`bs-download.[Guard]`, res.data);
});
}
public static getInstance(){
+1
View File
@@ -42,6 +42,7 @@ export class ModalService{
export enum ModalType {
STEAM_LOGIN = "STEAM_LOGIN",
GUARD_CODE = "GUARD_CODE",
}
export enum ModalExitCode {