mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
Modals repared
This commit is contained in:
@@ -16,6 +16,7 @@ import MenuBuilder from './menu';
|
||||
import { resolveHtmlPath } from './util';
|
||||
import './ipcs/custom-ipcs';
|
||||
import { UtilsService } from './services/utils.service';
|
||||
import { DownloadEventType } from './services/bs-installer.service';
|
||||
|
||||
export default class AppUpdater {
|
||||
constructor() {
|
||||
@@ -152,3 +153,10 @@ app
|
||||
});
|
||||
})
|
||||
.catch(console.log);
|
||||
|
||||
// setInterval(() => {
|
||||
// console.log("allo");
|
||||
// mainWindow.webContents.send(`bs-download.${DownloadEventType.GUARD_CODE}`);
|
||||
// }, 5000)
|
||||
|
||||
console.log("*** RELOAD MAIN ***");
|
||||
|
||||
@@ -75,13 +75,13 @@ export class BSInstallerService{
|
||||
this.utils.createFolderIfNotExist(this.getBSInstallationFolder());
|
||||
console.log(this.getDepotDownloaderExePath())
|
||||
this.downloadProcess = spawn(
|
||||
this.getDepotDownloaderExePath(),
|
||||
this.getDepotDownloaderExePath(),
|
||||
[
|
||||
`-app ${BS_APP_ID}`,
|
||||
`-depot ${BS_DEPOT}`,
|
||||
`-manifest ${bsVersion.BSManifest}`,
|
||||
`-username ${downloadInfos.username}`,
|
||||
`-dir ${bsVersion.BSVersion}`,
|
||||
`-depot ${BS_DEPOT}`,
|
||||
`-manifest ${bsVersion.BSManifest}`,
|
||||
`-username ${downloadInfos.username}`,
|
||||
`-dir ${bsVersion.BSVersion}`,
|
||||
`-remember-password`
|
||||
],
|
||||
{shell: true, cwd: this.getBSInstallationFolder()}
|
||||
@@ -89,38 +89,41 @@ export class BSInstallerService{
|
||||
console.log("oui");
|
||||
|
||||
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){ 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){
|
||||
const out = data.toString() as string;
|
||||
console.log(out);
|
||||
if(out.includes(DownloadEventType.NOT_LOGGED_IN) && downloadInfos.password){ setTimeout(() => {this.sendInputProcess(downloadInfos.password); console.log("*** LOGIN ***")}, 5000) }
|
||||
else if(out.includes(DownloadEventType.NOT_LOGGED_IN)){ this.downloadProcess.kill(); this.utils.ipcSend(`bs-download.${DownloadEventType.NOT_LOGGED_IN}`); }
|
||||
else if(out.includes(DownloadEventType.GUARD_CODE)){
|
||||
console.log("SEND GUARD");
|
||||
this.utils.ipcSend(`bs-download.${DownloadEventType.GUARD_CODE}`);
|
||||
}
|
||||
else if(out.includes(DownloadEventType.TWO_FA_CODE)){ this.utils.ipcSend(`bs-download.${DownloadEventType.TWO_FA_CODE}`); }
|
||||
else if(out.includes(DownloadEventType.PROGESS)){ this.utils.ipcSend(`bs-download.${DownloadEventType.PROGESS}`, parseFloat(out[1])); }
|
||||
else if(out.includes(DownloadEventType.FINISH)){ this.utils.ipcSend(`bs-download.${DownloadEventType.FINISH}`); this.downloadProcess.kill(); }
|
||||
else if(out.includes(DownloadEventType.ERROR)){
|
||||
console.log("ERROR");
|
||||
this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`);
|
||||
this.downloadProcess.kill('SIGINT');
|
||||
this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`);
|
||||
this.downloadProcess.kill('SIGINT');
|
||||
}
|
||||
})
|
||||
|
||||
this.downloadProcess.stdout.on('error', err => {
|
||||
console.log(err.toString());
|
||||
this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`);
|
||||
this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`);
|
||||
this.downloadProcess.kill();
|
||||
})
|
||||
|
||||
this.downloadProcess.stderr.on('data', err => {
|
||||
console.log(err.toString());
|
||||
console.log("a");
|
||||
this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`);
|
||||
this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`);
|
||||
this.downloadProcess.kill();
|
||||
})
|
||||
|
||||
this.downloadProcess.stderr.on('error', err => {
|
||||
console.log(err.toString());
|
||||
console.log("b");
|
||||
this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`);
|
||||
this.utils.ipcSend(`bs-download.${DownloadEventType.ERROR}`);
|
||||
this.downloadProcess.kill();
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,8 +6,14 @@ 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});
|
||||
const loggin = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
resolver({exitCode: ModalExitCode.COMPLETED, data: guardCode});
|
||||
}
|
||||
const cancel = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
resolver({exitCode: ModalExitCode.CANCELED});
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="p-4 bg-main-color-2 text-gray-200 overflow-hidden rounded-md shadow-lg shadow-black">
|
||||
@@ -20,8 +26,8 @@ export function GuardModal({resolver}: {resolver: (x: ModalResponse) => void}) {
|
||||
<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>
|
||||
<button onClick={e => cancel(e)} className="mr-4">Cancel</button>
|
||||
<button onClick={e =>loggin(e)}>LogIn</button>
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
|
||||
@@ -12,12 +12,16 @@ export function Modal() {
|
||||
|
||||
const modalSevice = ModalService.getInsance();
|
||||
|
||||
console.log(`modal type: ${modalType}`);
|
||||
|
||||
useEffect(() => {
|
||||
modalSevice.modalType$.pipe(distinctUntilChanged()).subscribe(type => {
|
||||
setModalType(type)
|
||||
modalSevice.modalType$.subscribe(type => {
|
||||
setModalType(type);
|
||||
console.log("*** open modal ***");
|
||||
console.log("*** open type: "+type+" ***")
|
||||
})
|
||||
}, [])
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className={`absolute w-screen h-screen flex content-center items-center justify-center z-50 ${modalType ? "top-0" : "top-[calc(100%+50px)]"}`}>
|
||||
|
||||
@@ -15,11 +15,12 @@ export class BsDownloaderService{
|
||||
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");
|
||||
window.electron.ipcRenderer.on("bs-download.[Guard]", async () => {
|
||||
console.log("*** GUARD ***");
|
||||
const res = await this.modalService.openModal(ModalType.GUARD_CODE);
|
||||
console.log(`***** res : ${res.exitCode}`);
|
||||
if(res.exitCode != ModalExitCode.COMPLETED){ return; }
|
||||
window.electron.ipcRenderer.sendMessage(`bs-download.[Guard]`, res.data);
|
||||
window.electron.ipcRenderer.sendMessage("bs-download.[Guard]", res.data);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -41,4 +42,4 @@ export class BsDownloaderService{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
import { BehaviorSubject, timeout } from "rxjs";
|
||||
|
||||
export class ModalService{
|
||||
|
||||
@@ -14,6 +14,8 @@ export class ModalService{
|
||||
}
|
||||
|
||||
private close(){
|
||||
console.log("*** CLOSE ***")
|
||||
if(this.resolver){ this.resolve({exitCode: ModalExitCode.NO_CHOICE}); }
|
||||
this.modalType$.next(null);
|
||||
}
|
||||
|
||||
@@ -29,15 +31,15 @@ export class ModalService{
|
||||
this.resolver(data);
|
||||
}
|
||||
|
||||
public openModal(modalType: ModalType): Promise<ModalResponse>{
|
||||
if(this.resolver){ this.resolver(ModalExitCode.NO_CHOICE); }
|
||||
let resolver, rejecter;
|
||||
const promise = new Promise<ModalResponse>((resolve, reject) => { resolver = resolve; rejecter = reject; });
|
||||
this.modalType$.next(modalType);
|
||||
public async openModal(modalType: ModalType): Promise<ModalResponse>{
|
||||
this.close();
|
||||
await timeout(100); //Must wait resolve
|
||||
const promise = new Promise<ModalResponse>((resolve) => { this.resolver = resolve; });
|
||||
promise.then(() => this.close());
|
||||
this.resolver = resolver;
|
||||
return promise;
|
||||
this.modalType$.next(modalType);
|
||||
return await promise;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export enum ModalType {
|
||||
@@ -55,4 +57,4 @@ export enum ModalExitCode {
|
||||
export interface ModalResponse {
|
||||
exitCode: ModalExitCode,
|
||||
data?: any
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user