mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
add guard code modal
This commit is contained in:
@@ -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
@@ -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: {
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user