[refactor] created installation-location.service.ts on client side

This commit is contained in:
silentrald
2024-08-28 19:24:56 +08:00
parent 9c86adf2d4
commit 9734d714d7
4 changed files with 37 additions and 16 deletions
@@ -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);
@@ -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<string> {
return lastValueFrom(this.ipcService.sendV2("bs-installer.install-path"));
}
// TODO: Move to another service in the future
public setInstallationFolder(path: string): Observable<string> {
return this.ipcService.sendV2("bs-installer.set-install-path", path);
}
// ### Downloading
private handleInfoEvents(events$: Observable<DepotDownloaderEvent>): Subscription[] {
@@ -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<string> {
return lastValueFrom(this.ipcService.sendV2("bs-installer.install-path"));
}
public setInstallationFolder(path: string): Observable<string> {
return this.ipcService.sendV2("bs-installer.set-install-path", path);
}
}
+4 -4
View File
@@ -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();