Modals repared

This commit is contained in:
MathieuG-P
2022-05-21 23:09:12 +02:00
parent e8621c257d
commit d30f3eff5d
7 changed files with 74 additions and 50 deletions
+11 -11
View File
@@ -2562,7 +2562,7 @@
},
"async": {
"version": "3.2.3",
"resolved": "https://registry.npmjs.org/async/-/async-3.2.3.tgz",
"resolved": "https://npm.zone51.tf/async/-/async-3.2.3.tgz",
"integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==",
"dev": true
},
@@ -4457,7 +4457,7 @@
},
"ejs": {
"version": "3.1.8",
"resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.8.tgz",
"resolved": "https://npm.zone51.tf/ejs/-/ejs-3.1.8.tgz",
"integrity": "sha512-/sXZeMlhS0ArkfX2Aw780gJzXSMPnKjtspYZv+f3NiKLlubezAHDU5+9xz6gd3/NhG3txQCo6xlglmTS+oTGEQ==",
"dev": true,
"requires": {
@@ -6235,7 +6235,7 @@
},
"filelist": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz",
"resolved": "https://npm.zone51.tf/filelist/-/filelist-1.0.4.tgz",
"integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==",
"dev": true,
"requires": {
@@ -6244,7 +6244,7 @@
"dependencies": {
"brace-expansion": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
"resolved": "https://npm.zone51.tf/brace-expansion/-/brace-expansion-2.0.1.tgz",
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
"dev": true,
"requires": {
@@ -6253,7 +6253,7 @@
},
"minimatch": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.0.tgz",
"resolved": "https://npm.zone51.tf/minimatch/-/minimatch-5.1.0.tgz",
"integrity": "sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==",
"dev": true,
"requires": {
@@ -7126,7 +7126,7 @@
},
"is-bigint": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.4.tgz",
"resolved": "https://npm.zone51.tf/is-bigint/-/is-bigint-1.0.4.tgz",
"integrity": "sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==",
"dev": true,
"requires": {
@@ -7144,7 +7144,7 @@
},
"is-boolean-object": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz",
"resolved": "https://npm.zone51.tf/is-boolean-object/-/is-boolean-object-1.1.2.tgz",
"integrity": "sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==",
"dev": true,
"requires": {
@@ -7260,7 +7260,7 @@
},
"is-number-object": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.7.tgz",
"resolved": "https://npm.zone51.tf/is-number-object/-/is-number-object-1.0.7.tgz",
"integrity": "sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==",
"dev": true,
"requires": {
@@ -7472,7 +7472,7 @@
},
"jake": {
"version": "10.8.5",
"resolved": "https://registry.npmjs.org/jake/-/jake-10.8.5.tgz",
"resolved": "https://npm.zone51.tf/jake/-/jake-10.8.5.tgz",
"integrity": "sha512-sVpxYeuAhWt0OTWITwT98oyV0GsXyMlXCF+3L1SuafBVUIr/uILGRB+NqwkzhgXKvoJpDIpQvqkUALgdmQsQxw==",
"dev": true,
"requires": {
@@ -9516,7 +9516,7 @@
"dependencies": {
"async": {
"version": "2.6.4",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz",
"resolved": "https://npm.zone51.tf/async/-/async-2.6.4.tgz",
"integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==",
"dev": true,
"requires": {
@@ -12446,7 +12446,7 @@
},
"which-boxed-primitive": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz",
"resolved": "https://npm.zone51.tf/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz",
"integrity": "sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==",
"dev": true,
"requires": {
+8
View File
@@ -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 ***");
+22 -19
View File
@@ -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{
}
}
}
}
+11 -9
View File
@@ -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
}
}