From 5d848859e5da1721315df2fc988df4bede29fbc9 Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Sun, 31 Jul 2022 18:12:24 +0200 Subject: [PATCH] no other operation when an operation is running --- assets/jsons/translations/en.json | 10 ++++++++++ assets/jsons/translations/es.json | 10 ++++++++++ assets/jsons/translations/fr.json | 10 ++++++++++ src/main/services/bs-installer.service.ts | 3 +-- src/main/services/installation-location.service.ts | 2 +- src/renderer/pages/settings-page.component.tsx | 5 +++++ src/renderer/services/bs-downloader.service.ts | 13 +++++++++---- src/renderer/services/bs-version-manager.service.ts | 4 ++++ src/renderer/services/progress-bar.service.ts | 1 + 9 files changed, 51 insertions(+), 7 deletions(-) diff --git a/assets/jsons/translations/en.json b/assets/jsons/translations/en.json index 63d2ba44..82f63ca3 100644 --- a/assets/jsons/translations/en.json +++ b/assets/jsons/translations/en.json @@ -72,6 +72,16 @@ "warning": "⚠️ Warning", "success": "🎉 Success" }, + "shared":{ + "errors":{ + "titles":{ + "operation-running": "Operation running" + }, + "msg":{ + "operation-running": "Wait for the end of the current operation then start again." + } + } + }, "bs-download":{ "success":{ "titles":{ diff --git a/assets/jsons/translations/es.json b/assets/jsons/translations/es.json index 320f6534..99e99e48 100644 --- a/assets/jsons/translations/es.json +++ b/assets/jsons/translations/es.json @@ -73,6 +73,16 @@ "warning": "⚠️ Advertencia", "success": "🎉 Éxito" }, + "shared":{ + "errors":{ + "titles":{ + "operation-running": "Operación en curso" + }, + "msg":{ + "operation-running": "Espere a que termine la operación actual y vuelva a empezar." + } + } + }, "bs-download":{ "success":{ "titles":{ diff --git a/assets/jsons/translations/fr.json b/assets/jsons/translations/fr.json index 6b2df819..2b9ea0fe 100644 --- a/assets/jsons/translations/fr.json +++ b/assets/jsons/translations/fr.json @@ -72,6 +72,16 @@ "warning": "⚠️ Attention", "success": "🎉 Succès" }, + "shared":{ + "errors":{ + "titles":{ + "operation-running": "Opération en cours" + }, + "msg":{ + "operation-running": "Attend la fin de l'opération en cours puis recommences." + } + } + }, "bs-download":{ "success":{ "titles":{ diff --git a/src/main/services/bs-installer.service.ts b/src/main/services/bs-installer.service.ts index 8ca720cb..01de6cbc 100644 --- a/src/main/services/bs-installer.service.ts +++ b/src/main/services/bs-installer.service.ts @@ -139,8 +139,7 @@ export class BSInstallerService{ reject(err); }); - this.downloadProcess.on('close', (code) => reject({type: "[Exit]", data: code})); - + this.downloadProcess.on('close', () => reject()); }) } diff --git a/src/main/services/installation-location.service.ts b/src/main/services/installation-location.service.ts index 7ec99f56..4503d552 100644 --- a/src/main/services/installation-location.service.ts +++ b/src/main/services/installation-location.service.ts @@ -43,7 +43,7 @@ export class InstallationLocationService { const oldDir = this.installationDirectory; const newDest = path.join(newDir, this.INSTALLATION_FOLDER); return new Promise((resolve, reject) => { - if(!this.utilsService.folderExist(oldDir)){ this.utilsService.createFolderIfNotExist(oldDir); } + if(!this.utilsService.pathExist(oldDir)){ this.utilsService.createFolderIfNotExist(oldDir); } fs.move(oldDir, newDest, { overwrite: true }).then(() => { this._installationDirectory = newDir; this.configService.store.set(this.STORE_INSTALLATION_PATH_KEY, newDir); diff --git a/src/renderer/pages/settings-page.component.tsx b/src/renderer/pages/settings-page.component.tsx index c098c429..4cb90178 100644 --- a/src/renderer/pages/settings-page.component.tsx +++ b/src/renderer/pages/settings-page.component.tsx @@ -74,6 +74,11 @@ export function SettingsPage() { } const setDefaultInstallationFolder = () => { + if(progressBarService.isVisible){ + notificationService.notifyError({title: "notifications.shared.errors.titles.operation-running", desc: "notifications.shared.errors.msg.operation-running", duration: 3000}); + return; + } + modalService.openModal(ModalType.INSTALLATION_FOLDER).then(async res => { if(res.exitCode !== ModalExitCode.COMPLETED){ return; } const fileChooserRes = await ipcService.send<{canceled: boolean, filePaths: string[]}>("choose-folder"); diff --git a/src/renderer/services/bs-downloader.service.ts b/src/renderer/services/bs-downloader.service.ts index a3efacf1..3c8211cd 100644 --- a/src/renderer/services/bs-downloader.service.ts +++ b/src/renderer/services/bs-downloader.service.ts @@ -82,7 +82,12 @@ export class BsDownloaderService{ return this.ipcService.send("bs-download.kill"); } - public async download(bsVersion: BSVersion, isVerification?: boolean): Promise>{ + public async download(bsVersion: BSVersion, isVerification?: boolean, isFirstCall: boolean = true): Promise>{ + if(isFirstCall && this.progressBarService.isVisible){ + this.notificationService.notifyError({title: "notifications.shared.errors.titles.operation-running", desc: "notifications.shared.errors.msg.operation-running", duration: 3000}); + return {success: false}; + } + this.progressBarService.show(this.downloadProgress$); this._isVerification = !!isVerification; @@ -104,15 +109,15 @@ export class BsDownloaderService{ let res = await promise; - if(res.data.type === "[Password]"){ + if(res.data?.type === "[Password]"){ this.authService.deleteSteamSession(); - res = await this.download(bsVersion); + res = await this.download(bsVersion, isVerification, false); } this.progressBarService.hide(true); this.resetDownload(); if(res.success){ this.notificationService.notifySuccess({title: `notifications.bs-download.success.titles.${isVerification ? "verification-finished" : "download-success"}`, duration: 3000}); } - else{ this.notificationService.notifyError({title: `notifications.bs-download.errors.titles.${res.data}`, duration: 3000}); } + else if(res.data){ this.notificationService.notifyError({title: `notifications.bs-download.errors.titles.${res.data}`, duration: 3000}); } return res; } diff --git a/src/renderer/services/bs-version-manager.service.ts b/src/renderer/services/bs-version-manager.service.ts index 79fe7f86..915400bf 100644 --- a/src/renderer/services/bs-version-manager.service.ts +++ b/src/renderer/services/bs-version-manager.service.ts @@ -88,6 +88,10 @@ export class BSVersionManagerService { } public async cloneVersion(version: BSVersion): Promise{ + if(this.progressBarService.isVisible){ + this.notificationService.notifyError({title: "notifications.shared.errors.titles.operation-running", desc: "notifications.shared.errors.msg.operation-running", duration: 3000}); + return null; + } const modalRes = await this.modalService.openModal<{name: string, color: string}>(ModalType.CLONE_VERSION, version); if(modalRes.exitCode !== ModalExitCode.COMPLETED){ return null; } if(modalRes.data.name?.length < 2){ return null; } diff --git a/src/renderer/services/progress-bar.service.ts b/src/renderer/services/progress-bar.service.ts index 87339999..f807cab4 100644 --- a/src/renderer/services/progress-bar.service.ts +++ b/src/renderer/services/progress-bar.service.ts @@ -70,6 +70,7 @@ export class ProgressBarService{ public get progression$(): BehaviorSubject{ return this._progression$; } public get visible$(): BehaviorSubject{ return this._visible$; } + public get isVisible(): boolean{ return this._visible$.value; }