From 15603edaa8f17fe3a98d22d59140d2b4f2a3a269 Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Sat, 25 Jun 2022 03:50:51 +0200 Subject: [PATCH] add setting to change default installations location --- .../pages/settings-page.component.tsx | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/renderer/pages/settings-page.component.tsx b/src/renderer/pages/settings-page.component.tsx index f1ac8303..f1aedb3a 100644 --- a/src/renderer/pages/settings-page.component.tsx +++ b/src/renderer/pages/settings-page.component.tsx @@ -4,21 +4,29 @@ import { SettingContainer } from "renderer/components/settings/setting-container import { RadioItem, SettingRadioArray } from "renderer/components/settings/setting-radio-array.component"; import { BsmButton } from "renderer/components/shared/bsm-button.component"; import { DefaultConfigKey } from "renderer/config/default-configuration.config"; +import { BsDownloaderService } from "renderer/services/bs-downloader.service"; import { ConfigurationService } from "renderer/services/configuration.service" +import { IpcService } from "renderer/services/ipc.service"; +import { ModalExitCode, ModalService, ModalType } from "renderer/services/modale.service"; export function SettingsPage() { const configService = ConfigurationService.getInstance(); + const ipcService = IpcService.getInstance(); + const modalService = ModalService.getInsance(); + const downloaderService = BsDownloaderService.getInstance(); const [firstColor, setFirstColor] = useState("#fff"); const [secondColor, setSecondColor] = useState("#fff"); - const[themeIdSelected, setThemeIdSelected]= useState(0); + const [installationFolder, setInstallationFolder] = useState(null); useEffect(() => { const [fColorObs, sColorObs] = [configService.watch("first-color"), configService.watch("second-color")]; const fColorSub = fColorObs.subscribe(color => setFirstColor(color)); const sColorSub = sColorObs.subscribe(color => setSecondColor(color)); + + loadInstallationFolder(); return () => { configService.stopWatch("first-color" as DefaultConfigKey, fColorObs); @@ -39,17 +47,34 @@ export function SettingsPage() { configService.delete("second-color" as DefaultConfigKey); } + const loadInstallationFolder = () => { + downloaderService.getInstallationFolder().then(res => setInstallationFolder(res)); + } + const setFirstColorSetting = (hex: string) => configService.set("first-color", hex); const setSecondColorSetting = (hex: string) => configService.set("second-color", hex); + const setDefaultInstallationFolder = () => { + 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"); + if(fileChooserRes.success && !fileChooserRes.data.canceled && fileChooserRes.data.filePaths?.length){ + downloaderService.setInstallationFolder(fileChooserRes.data.filePaths[0]).then(res => { + if(res.success){ setInstallationFolder(res.data); } + }); + } + + }) + } return (
-
+
- + @@ -57,15 +82,22 @@ export function SettingsPage() {
-
- +
+
- + setThemeIdSelected(id)}/> + +
+ {installationFolder} + +
+
+