diff --git a/src/renderer/pages/settings-page.component.tsx b/src/renderer/pages/settings-page.component.tsx index ea059fa7..1cea476e 100644 --- a/src/renderer/pages/settings-page.component.tsx +++ b/src/renderer/pages/settings-page.component.tsx @@ -48,6 +48,7 @@ import { SettingToogleSwitchGrid } from "renderer/components/settings/setting-to import { BasicModal } from "renderer/components/modal/basic-modal.component"; import { StaticConfigurationService } from "renderer/services/static-configuration.service"; import { tryit } from "shared/helpers/error.helpers"; +import { InstallationLocationService } from "renderer/services/installation-location.service"; export function SettingsPage() { @@ -68,6 +69,7 @@ export function SettingsPage() { const versionLinker = useService(VersionFolderLinkerService); const autoUpdater = useService(AutoUpdaterService); const staticConfig = useService(StaticConfigurationService); + const installationLocationService = useService(InstallationLocationService); const { firstColor, secondColor } = useThemeColor(); @@ -124,7 +126,7 @@ export function SettingsPage() { }; const loadInstallationFolder = () => { - steamDownloader.getInstallationFolder().then(res => { + installationLocationService.getInstallationFolder().then(res => { setInstallationFolder(res); }); }; @@ -202,7 +204,7 @@ export function SettingsPage() { notificationService.notifySuccess({ title: "notifications.settings.move-folder.success.titles.transfer-started", desc: "notifications.settings.move-folder.success.descs.transfer-started" }); - lastValueFrom(steamDownloader.setInstallationFolder(fileChooserRes.filePaths[0])).then(res => { + lastValueFrom(installationLocationService.setInstallationFolder(fileChooserRes.filePaths[0])).then(res => { progressBarService.complete(); progressBarService.hide(true); diff --git a/src/renderer/services/bs-version-download/steam-downloader.service.ts b/src/renderer/services/bs-version-download/steam-downloader.service.ts index 7e10de70..313a1e4a 100644 --- a/src/renderer/services/bs-version-download/steam-downloader.service.ts +++ b/src/renderer/services/bs-version-download/steam-downloader.service.ts @@ -47,16 +47,6 @@ export class SteamDownloaderService extends AbstractBsDownloaderService implemen public deleteSteamSession(): void { localStorage.removeItem(this.STEAM_SESSION_USERNAME_KEY); } public sessionExist(): boolean { return !!localStorage.getItem(this.STEAM_SESSION_USERNAME_KEY); } - // TODO: Move to another service in the future - public async getInstallationFolder(): Promise { - return lastValueFrom(this.ipcService.sendV2("bs-installer.install-path")); - } - - // TODO: Move to another service in the future - public setInstallationFolder(path: string): Observable { - return this.ipcService.sendV2("bs-installer.set-install-path", path); - } - // ### Downloading private handleInfoEvents(events$: Observable): Subscription[] { diff --git a/src/renderer/services/installation-location.service.ts b/src/renderer/services/installation-location.service.ts new file mode 100644 index 00000000..db1d01ad --- /dev/null +++ b/src/renderer/services/installation-location.service.ts @@ -0,0 +1,29 @@ +import { Observable, lastValueFrom } from "rxjs"; +import { IpcService } from "./ipc.service"; + + +export class InstallationLocationService { + + private static instance: InstallationLocationService; + + private readonly ipcService: IpcService; + + public static getInstance(): InstallationLocationService { + if (!InstallationLocationService.instance) { + InstallationLocationService.instance = new InstallationLocationService(); + } + return InstallationLocationService.instance; + } + + private constructor() { + this.ipcService = IpcService.getInstance(); + } + + public async getInstallationFolder(): Promise { + return lastValueFrom(this.ipcService.sendV2("bs-installer.install-path")); + } + + public setInstallationFolder(path: string): Observable { + return this.ipcService.sendV2("bs-installer.set-install-path", path); + } +} diff --git a/src/renderer/services/setup.service.ts b/src/renderer/services/setup.service.ts index e2d105d1..c88f3c97 100644 --- a/src/renderer/services/setup.service.ts +++ b/src/renderer/services/setup.service.ts @@ -2,9 +2,9 @@ import { lastValueFrom } from "rxjs"; import { logRenderError } from "renderer"; import { BSVersionManagerService } from "./bs-version-manager.service"; +import { InstallationLocationService } from "./installation-location.service"; import { IpcService } from "./ipc.service"; import { ModalService } from "./modale.service"; -import { SteamDownloaderService } from "./bs-version-download/steam-downloader.service"; import { AskInstallPathModal } from "renderer/components/modal/modal-types/ask-install-path.component"; @@ -12,15 +12,15 @@ import { AskInstallPathModal } from "renderer/components/modal/modal-types/ask-i export class SetupService { private static instance: SetupService; + private readonly installationLocationService: InstallationLocationService; private readonly ipcService: IpcService; private readonly modalService: ModalService; - private readonly steamDownloaderService: SteamDownloaderService; private readonly versionManagerService: BSVersionManagerService; private constructor() { + this.installationLocationService = InstallationLocationService.getInstance(); this.ipcService = IpcService.getInstance(); this.modalService = ModalService.getInstance(); - this.steamDownloaderService = SteamDownloaderService.getInstance(); this.versionManagerService = BSVersionManagerService.getInstance(); } @@ -52,7 +52,7 @@ export class SetupService { { closable: false } ); - await lastValueFrom(this.steamDownloaderService.setInstallationFolder(modalResponse.data.installPath)); + await lastValueFrom(this.installationLocationService.setInstallationFolder(modalResponse.data.installPath)); // Refresh the versions tab await this.versionManagerService.askInstalledVersions();