diff --git a/src/main/ipcs/bs-download-ipcs.ts b/src/main/ipcs/bs-download-ipcs.ts index 2ec0bcfa..a870104f 100644 --- a/src/main/ipcs/bs-download-ipcs.ts +++ b/src/main/ipcs/bs-download-ipcs.ts @@ -1,5 +1,5 @@ import { ipcMain } from 'electron'; -import { BSVersion } from '../services/bs-version-lib.service'; +import { BSVersion } from 'shared/bs-version.interface'; import { BSInstallerService, DownloadEventType } from '../services/bs-installer.service'; import { IpcRequest } from 'shared/models/ipc'; import { InstallationLocationService } from '../services/installation-location.service'; diff --git a/src/main/ipcs/bs-launcher-ipcs.ts b/src/main/ipcs/bs-launcher-ipcs.ts index 6fda31c7..c0f95581 100644 --- a/src/main/ipcs/bs-launcher-ipcs.ts +++ b/src/main/ipcs/bs-launcher-ipcs.ts @@ -1,6 +1,6 @@ import { ipcMain } from 'electron'; import { UtilsService } from '../services/utils.service' -import { LauchOption } from "../../shared/models/launch-models.model"; +import { LauchOption } from "shared/models/bs-launch"; import { BSLauncherService } from "../services/bs-launcher.service" import { IpcRequest } from 'shared/models/ipc'; diff --git a/src/main/ipcs/bs-uninstall-ipcs.ts b/src/main/ipcs/bs-uninstall-ipcs.ts index ceffd6d0..f28f8cfb 100644 --- a/src/main/ipcs/bs-uninstall-ipcs.ts +++ b/src/main/ipcs/bs-uninstall-ipcs.ts @@ -1,5 +1,5 @@ import { ipcMain } from "electron"; -import { BSVersion } from "main/services/bs-version-lib.service"; +import { BSVersion } from 'shared/bs-version.interface'; import { UtilsService } from "../services/utils.service"; import { IpcRequest } from "shared/models/ipc"; import { BSLocalVersionService } from "../services/bs-local-version.service"; diff --git a/src/main/ipcs/bs-version-ipcs.ts b/src/main/ipcs/bs-version-ipcs.ts index c5e518cc..1073c48d 100644 --- a/src/main/ipcs/bs-version-ipcs.ts +++ b/src/main/ipcs/bs-version-ipcs.ts @@ -1,7 +1,7 @@ import { ipcMain } from 'electron'; import { UtilsService } from '../services/utils.service'; import { BSVersionLibService } from '../services/bs-version-lib.service' -import { BSVersion } from "main/services/bs-version-lib.service"; +import { BSVersion } from 'shared/bs-version.interface'; import path from 'path'; import { exec } from 'child_process'; import { SteamService } from '../services/steam.service'; diff --git a/src/main/services/bs-installer.service.ts b/src/main/services/bs-installer.service.ts index 62a19178..422284d9 100644 --- a/src/main/services/bs-installer.service.ts +++ b/src/main/services/bs-installer.service.ts @@ -1,6 +1,7 @@ import { BS_APP_ID, BS_DEPOT } from "../constants"; import path from "path"; -import { BSVersion, BSVersionLibService } from "./bs-version-lib.service"; +import { BSVersionLibService } from "./bs-version-lib.service"; +import { BSVersion } from 'shared/bs-version.interface'; import { UtilsService } from "./utils.service"; import { ChildProcessWithoutNullStreams, spawn } from "child_process"; import log from "electron-log"; diff --git a/src/main/services/bs-launcher.service.ts b/src/main/services/bs-launcher.service.ts index d4219b22..312f5f10 100644 --- a/src/main/services/bs-launcher.service.ts +++ b/src/main/services/bs-launcher.service.ts @@ -1,6 +1,6 @@ import path from "path"; -import { BsLaunchResult, LauchOption } from "shared/models/launch-models.model"; -import { BSVersion } from "./bs-version-lib.service"; +import { LaunchResult, LauchOption } from "shared/models/bs-launch"; +import { BSVersion } from 'shared/bs-version.interface'; import { UtilsService } from "./utils.service"; import { BS_EXECUTABLE, BS_APP_ID } from "../constants"; import { ChildProcessWithoutNullStreams, spawn } from "child_process"; @@ -37,7 +37,7 @@ export class BSLauncherService{ return this.utilsService.pathExist(exePath); } - public async launch(launchOptions: LauchOption): Promise{ + public async launch(launchOptions: LauchOption): Promise{ if(!this.steamService.steamRunning()){ return "STEAM_NOT_RUNNING" } if(!this.isExeExist(launchOptions.version)){ return "EXE_NOT_FINDED"; } if(this.isBsRunning()){ return "BS_ALREADY_RUNNING" } diff --git a/src/main/services/bs-local-version.service.ts b/src/main/services/bs-local-version.service.ts index 33adfb5a..814ced44 100644 --- a/src/main/services/bs-local-version.service.ts +++ b/src/main/services/bs-local-version.service.ts @@ -1,4 +1,5 @@ -import { BSVersion, BSVersionLibService } from "./bs-version-lib.service"; +import { BSVersionLibService } from "./bs-version-lib.service"; +import { BSVersion } from 'shared/bs-version.interface'; import { InstallationLocationService } from "./installation-location.service"; import { SteamService } from "./steam.service"; import { UtilsService } from "./utils.service"; diff --git a/src/main/services/bs-version-lib.service.ts b/src/main/services/bs-version-lib.service.ts index ebf6ea8e..9e87f4b6 100644 --- a/src/main/services/bs-version-lib.service.ts +++ b/src/main/services/bs-version-lib.service.ts @@ -2,75 +2,73 @@ import { get } from 'https' import { UtilsService } from './utils.service'; import path from 'path'; import { writeFileSync } from 'fs'; +import { BSVersion } from 'shared/bs-version.interface'; export class BSVersionLibService{ - private readonly REMOTE_BS_VERSIONS_URL: string = "https://raw.githubusercontent.com/Zagrios/bs-manager/master/assets/jsons/bs-versions.json" - private readonly VERSIONS_FILE: string = "bs-versions.json"; + private readonly REMOTE_BS_VERSIONS_URL: string = "https://raw.githubusercontent.com/Zagrios/bs-manager/master/assets/jsons/bs-versions.json" + private readonly VERSIONS_FILE: string = "bs-versions.json"; - private static instance: BSVersionLibService; + private static instance: BSVersionLibService; - private utilsService: UtilsService; + private utilsService: UtilsService; - private bsVersions: BSVersion[] = []; + private bsVersions: BSVersion[] = []; - private constructor(){ - this.utilsService = UtilsService.getInstance(); - } + private constructor(){ + this.utilsService = UtilsService.getInstance(); + } - public static getInstance(): BSVersionLibService{ - if(!BSVersionLibService.instance){ BSVersionLibService.instance = new BSVersionLibService(); } - return BSVersionLibService.instance; - } + public static getInstance(): BSVersionLibService{ + if(!BSVersionLibService.instance){ BSVersionLibService.instance = new BSVersionLibService(); } + return BSVersionLibService.instance; + } - private getRemoteVersions(): Promise{ - return new Promise((resolve, reject) => { - let body = '' - get(this.REMOTE_BS_VERSIONS_URL, (res) => { - res.on('data', chunk => body += chunk); - res.on('end', () => { - this.bsVersions = JSON.parse(body); - resolve(this.bsVersions); - }); - res.on('error', (err) => reject(null)) + private getRemoteVersions(): Promise{ + return new Promise((resolve, reject) => { + let body = '' + get(this.REMOTE_BS_VERSIONS_URL, (res) => { + res.on('data', chunk => body += chunk); + res.on('end', () => { + this.bsVersions = JSON.parse(body); + resolve(this.bsVersions); + }); + res.on('error', (err) => reject(null)) + }) }) - }) - } + } - private async getLocalVersions(): Promise{ - const localVersionsPath = path.join(this.utilsService.getAssestsJsonsPath(), this.VERSIONS_FILE); - const rawVersion = (await this.utilsService.readFileAsync(localVersionsPath)).toString(); - return JSON.parse(rawVersion); - } + private async getLocalVersions(): Promise{ + const localVersionsPath = path.join(this.utilsService.getAssestsJsonsPath(), this.VERSIONS_FILE); + const rawVersion = (await this.utilsService.readFileAsync(localVersionsPath)).toString(); + return JSON.parse(rawVersion); + } - private async updateLocalVersions(versions: BSVersion[]): Promise{ - const localVersionsPath = path.join(this.utilsService.getAssestsJsonsPath(), this.VERSIONS_FILE); - writeFileSync(localVersionsPath, JSON.stringify(versions, null, "\t"), {encoding: 'utf-8', flag: 'w'}); - }; + private async updateLocalVersions(versions: BSVersion[]): Promise{ + const localVersionsPath = path.join(this.utilsService.getAssestsJsonsPath(), this.VERSIONS_FILE); + writeFileSync(localVersionsPath, JSON.stringify(versions, null, "\t"), {encoding: 'utf-8', flag: 'w'}); + }; - private async loadBsVersions(): Promise{ - const [localVersions, remoteVersions] = await Promise.all([ - this.getLocalVersions(), this.getRemoteVersions() - ]); - let resVersions = localVersions; - if(remoteVersions && remoteVersions.length){ resVersions = remoteVersions; this.updateLocalVersions(resVersions); } - this.bsVersions = resVersions; - return this.bsVersions; - } + private async loadBsVersions(): Promise{ + const [localVersions, remoteVersions] = await Promise.all([ + this.getLocalVersions(), this.getRemoteVersions() + ]); + let resVersions = localVersions; + if(remoteVersions && remoteVersions.length){ resVersions = remoteVersions; this.updateLocalVersions(resVersions); } + this.bsVersions = resVersions; + return this.bsVersions; + } - public async getAvailableVersions(): Promise{ - if(this.bsVersions && this.bsVersions.length){ return this.bsVersions; } - const bsVersions = await this.loadBsVersions(); - if(!bsVersions || !bsVersions.length){ return []; } - return bsVersions; - - } + public async getAvailableVersions(): Promise{ + if(this.bsVersions && this.bsVersions.length){ return this.bsVersions; } + const bsVersions = await this.loadBsVersions(); + if(!bsVersions || !bsVersions.length){ return []; } + return bsVersions; + } - public getVersionDetails(version: string): BSVersion{ - return this.bsVersions.find(v => v.BSVersion === version); - } + public getVersionDetails(version: string): BSVersion{ + return this.bsVersions.find(v => v.BSVersion === version); + } -} - -export interface BSVersion { BSVersion: string, BSManifest?: string, ReleaseURL?: string, ReleaseImg?: string, ReleaseDate?: string, year?: string, steam?: boolean } +} \ No newline at end of file diff --git a/src/renderer/components/available-versions/available-version-item.component.tsx b/src/renderer/components/available-versions/available-version-item.component.tsx index f865779f..c9072f36 100644 --- a/src/renderer/components/available-versions/available-version-item.component.tsx +++ b/src/renderer/components/available-versions/available-version-item.component.tsx @@ -1,4 +1,4 @@ -import { BSVersion } from "main/services/bs-version-lib.service"; +import { BSVersion } from 'shared/bs-version.interface'; import './available-version-item.component.css'; import { useEffect, useState, memo } from "react"; import { BsDownloaderService } from "renderer/services/bs-downloader.service"; diff --git a/src/renderer/components/available-versions/available-versions-slide.component.tsx b/src/renderer/components/available-versions/available-versions-slide.component.tsx index 08606c82..b319c585 100644 --- a/src/renderer/components/available-versions/available-versions-slide.component.tsx +++ b/src/renderer/components/available-versions/available-versions-slide.component.tsx @@ -1,4 +1,4 @@ -import { BSVersion } from "main/services/bs-version-lib.service"; +import { BSVersion } from 'shared/bs-version.interface'; import { useEffect, useState } from "react" import { BSVersionManagerService } from "renderer/services/bs-version-manager.service"; import { filter, take } from "rxjs"; diff --git a/src/renderer/components/modal/modal-types/uninstall-modal.component.tsx b/src/renderer/components/modal/modal-types/uninstall-modal.component.tsx index 828a1f9d..b820b4fb 100644 --- a/src/renderer/components/modal/modal-types/uninstall-modal.component.tsx +++ b/src/renderer/components/modal/modal-types/uninstall-modal.component.tsx @@ -1,6 +1,6 @@ import { ModalExitCode, ModalResponse, ModalService } from "../../../services/modale.service"; import BeatConflict from "../../../../../assets/images/apngs/beat-conflict.png" -import { BSVersion } from "main/services/bs-version-lib.service"; +import { BSVersion } from 'shared/bs-version.interface'; import { BsmButton } from "renderer/components/shared/bsm-button.component"; import { BsmImage } from "renderer/components/shared/bsm-image.component"; import { useTranslation } from "renderer/hooks/use-translation.hook"; diff --git a/src/renderer/components/nav-bar/bs-version-item.component.tsx b/src/renderer/components/nav-bar/bs-version-item.component.tsx index a2232d7a..ba13d588 100644 --- a/src/renderer/components/nav-bar/bs-version-item.component.tsx +++ b/src/renderer/components/nav-bar/bs-version-item.component.tsx @@ -1,4 +1,4 @@ -import { BSVersion } from "main/services/bs-version-lib.service"; +import { BSVersion } from 'shared/bs-version.interface'; import { Link, useLocation } from "react-router-dom"; import { BsDownloaderService } from "renderer/services/bs-downloader.service"; import { useEffect, useState } from "react"; diff --git a/src/renderer/pages/available-versions-list.components.tsx b/src/renderer/pages/available-versions-list.components.tsx index c3367d32..d8061965 100644 --- a/src/renderer/pages/available-versions-list.components.tsx +++ b/src/renderer/pages/available-versions-list.components.tsx @@ -2,7 +2,7 @@ import { AvailableVersionsSlider } from "../components/available-versions/availa import { BsDownloaderService } from "../services/bs-downloader.service"; import { Slideshow } from "renderer/components/slideshow/slideshow.component"; import { useEffect, useState } from "react"; -import { BSVersion } from "main/services/bs-version-lib.service"; +import { BSVersion } from 'shared/bs-version.interface'; import { BsmButton } from "renderer/components/shared/bsm-button.component"; import { AnimatePresence, motion } from "framer-motion"; import { useTranslation } from "renderer/hooks/use-translation.hook"; diff --git a/src/renderer/pages/version-viewer.component.tsx b/src/renderer/pages/version-viewer.component.tsx index 6e71ac4e..94123e31 100644 --- a/src/renderer/pages/version-viewer.component.tsx +++ b/src/renderer/pages/version-viewer.component.tsx @@ -1,4 +1,4 @@ -import { BSVersion } from '../../main/services/bs-version-lib.service'; +import { BSVersion } from 'shared/bs-version.interface'; import { useEffect, useState } from 'react'; import { useLocation, useNavigate } from 'react-router-dom'; import BSLogo from '../../../assets/images/apngs/bs-logo.png'; diff --git a/src/renderer/services/bs-downloader.service.ts b/src/renderer/services/bs-downloader.service.ts index 56de10cf..76d104e5 100644 --- a/src/renderer/services/bs-downloader.service.ts +++ b/src/renderer/services/bs-downloader.service.ts @@ -1,7 +1,7 @@ import { DownloadEvent } from 'main/services/bs-installer.service'; import { BehaviorSubject, distinctUntilChanged, filter, debounceTime } from 'rxjs'; import { IpcResponse } from 'shared/models/ipc'; -import { BSVersion } from '../../main/services/bs-version-lib.service' +import { BSVersion } from 'shared/bs-version.interface'; import { AuthUserService } from './auth-user.service'; import { BSVersionManagerService } from './bs-version-manager.service'; import { IpcService } from './ipc.service'; diff --git a/src/renderer/services/bs-launcher.service.ts b/src/renderer/services/bs-launcher.service.ts index c973c871..b882da12 100644 --- a/src/renderer/services/bs-launcher.service.ts +++ b/src/renderer/services/bs-launcher.service.ts @@ -1,7 +1,6 @@ -import { LauchOption } from "../../shared/models/launch-models.model"; -import { BSVersion } from "../../main/services/bs-version-lib.service"; +import { LauchOption, LaunchResult } from "shared/models/bs-launch"; +import { BSVersion } from 'shared/bs-version.interface'; import { IpcService } from "./ipc.service"; -import { BsLaunchResult } from "../../shared/models/launch-models.model"; import { NotificationResult, NotificationService } from "./notification.service"; import { BsDownloaderService } from "./bs-downloader.service"; @@ -26,7 +25,7 @@ export class BSLauncherService{ public launch(version: BSVersion, oculus: boolean, desktop: boolean, debug: boolean): Promise{ const lauchOption: LauchOption = {debug, oculus, desktop, version}; - return this.ipcService.send("bs-launch.launch", {args: lauchOption}).then(res => { + return this.ipcService.send("bs-launch.launch", {args: lauchOption}).then(res => { if(!res.success){ return this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.UNABLE_TO_LAUNCH", desc: res.error.title}); } if(res.data === "EXE_NOT_FINDED"){ this.notificationService.notifyError({title: "notifications.bs-launch.errors.titles.EXE_NOT_FINDED", desc: "notifications.bs-launch.errors.msg.EXE_NOT_FINDED", actions: [{id: "0", title:"misc.verify"}]}).then(res => { diff --git a/src/renderer/services/bs-uninstaller.service.ts b/src/renderer/services/bs-uninstaller.service.ts index 373ea4f4..7e8476df 100644 --- a/src/renderer/services/bs-uninstaller.service.ts +++ b/src/renderer/services/bs-uninstaller.service.ts @@ -1,4 +1,4 @@ -import { BSVersion } from "main/services/bs-version-lib.service"; +import { BSVersion } from 'shared/bs-version.interface'; import { IpcService } from "./ipc.service"; export class BSUninstallerService{ diff --git a/src/renderer/services/bs-version-manager.service.ts b/src/renderer/services/bs-version-manager.service.ts index 263d3cd1..97a15e37 100644 --- a/src/renderer/services/bs-version-manager.service.ts +++ b/src/renderer/services/bs-version-manager.service.ts @@ -1,4 +1,4 @@ -import { BSVersion } from "../../main/services/bs-version-lib.service"; +import { BSVersion } from 'shared/bs-version.interface'; import { BehaviorSubject } from "rxjs"; import { IpcService } from "./ipc.service"; diff --git a/src/shared/bs-version.interface.ts b/src/shared/bs-version.interface.ts new file mode 100644 index 00000000..81bcfefc --- /dev/null +++ b/src/shared/bs-version.interface.ts @@ -0,0 +1,9 @@ +export interface BSVersion { + BSVersion: string, + BSManifest?: string, + ReleaseURL?: string, + ReleaseImg?: string, + ReleaseDate?: string, + year?: string, + steam?: boolean +} \ No newline at end of file diff --git a/src/shared/models/bs-launch/index.ts b/src/shared/models/bs-launch/index.ts new file mode 100644 index 00000000..aec201cf --- /dev/null +++ b/src/shared/models/bs-launch/index.ts @@ -0,0 +1,2 @@ +export { LauchOption } from "./launch-option.interface" +export { LaunchResult } from "./launch-result.interface" \ No newline at end of file diff --git a/src/shared/models/bs-launch/launch-option.interface.ts b/src/shared/models/bs-launch/launch-option.interface.ts new file mode 100644 index 00000000..f19e9ba5 --- /dev/null +++ b/src/shared/models/bs-launch/launch-option.interface.ts @@ -0,0 +1,8 @@ +import { BSVersion } from "shared/bs-version.interface"; + +export interface LauchOption { + version: BSVersion, + oculus: boolean, + desktop: boolean, + debug: boolean +} \ No newline at end of file diff --git a/src/shared/models/bs-launch/launch-result.interface.ts b/src/shared/models/bs-launch/launch-result.interface.ts new file mode 100644 index 00000000..1d7cd1ef --- /dev/null +++ b/src/shared/models/bs-launch/launch-result.interface.ts @@ -0,0 +1,6 @@ +export type LaunchResult = ( + "LAUNCHED"| + "STEAM_NOT_RUNNING"| + "EXE_NOT_FINDED"| + "BS_ALREADY_RUNNING" +) \ No newline at end of file diff --git a/src/shared/models/launch-models.model.ts b/src/shared/models/launch-models.model.ts deleted file mode 100644 index cf906981..00000000 --- a/src/shared/models/launch-models.model.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { BSVersion } from "main/services/bs-version-lib.service"; - -export interface LauchOption { - version: BSVersion, - oculus: boolean, - desktop: boolean, - debug: boolean -} - -export type BsLaunchResult = "LAUNCHED" | "STEAM_NOT_RUNNING" | "EXE_NOT_FINDED" | "BS_ALREADY_RUNNING"; \ No newline at end of file