[chore] rework advanced launch

This commit is contained in:
MathieuG-P
2024-12-21 17:46:34 +01:00
parent 8776b036af
commit 3efcd40cdc
15 changed files with 221 additions and 87 deletions
@@ -7,6 +7,7 @@ import { sToMs } from "../../../shared/helpers/time.helpers";
import { LinuxService } from "../linux.service";
import { bsmSpawn } from "main/helpers/os.helpers";
import { IS_FLATPAK } from "main/constants";
import { LaunchMods } from "shared/models/bs-launch/launch-option.interface";
export abstract class AbstractLauncherService {
@@ -24,14 +25,14 @@ export abstract class AbstractLauncherService {
if(!launchOptions.version.steam && !launchOptions.version.oculus){
launchArgs.push("--no-yeet")
}
if (launchOptions.oculus) {
if (launchOptions.launchMods?.includes(LaunchMods.OCULUS)) {
launchArgs.push("-vrmode");
launchArgs.push("oculus");
}
if (launchOptions.desktop) {
if (launchOptions.launchMods?.includes(LaunchMods.FPFC)) {
launchArgs.push("fpfc");
}
if (launchOptions.debug) {
if (launchOptions.launchMods?.includes(LaunchMods.DEBUG)) {
launchArgs.push("--verbose");
}
if (launchOptions.additionalArgs) {
@@ -20,6 +20,7 @@ import { SteamLauncherService } from "./steam-launcher.service";
import { OculusLauncherService } from "./oculus-launcher.service";
import { BSVersion } from "shared/bs-version.interface";
import { BsStore } from "../../../shared/models/bs-store.enum";
import { LaunchMod, LaunchMods } from "shared/models/bs-launch/launch-option.interface";
export class BSLauncherService {
private static instance: BSLauncherService;
@@ -94,6 +95,14 @@ export class BSLauncherService {
}
private shortcutParamsToLaunchOption(params: ShortcutParams): LaunchOption{
const launchMods: LaunchMod[] = [];
if(params.oculusMode === "true"){ launchMods.push(LaunchMods.OCULUS); }
if(params.desktopMode === "true"){ launchMods.push(LaunchMods.FPFC); }
if(params.debug === "true"){ launchMods.push(LaunchMods.DEBUG); }
if(params.skipSteam === "true"){ launchMods.push(LaunchMods.SKIP_STEAM); }
const res: LaunchOption = {
version: {
BSVersion: params.version,
@@ -102,11 +111,8 @@ export class BSLauncherService {
oculus: params.versionOculus === "true",
ino: +params.versionIno
},
oculus: params.oculusMode === "true",
desktop: params.desktopMode === "true",
debug: params.debug === "true",
additionalArgs: params.additionalArgs,
skipSteam: params.skipSteam === "true",
launchMods,
};
return res;
@@ -120,11 +126,11 @@ export class BSLauncherService {
if(launchOptions.version.oculus){ res.versionOculus = `${launchOptions.version.oculus}`; }
if(launchOptions.version.ino){ res.versionIno = `${launchOptions.version.ino}`; }
if(launchOptions.oculus){ res.oculusMode = "true"; }
if(launchOptions.desktop){ res.desktopMode = "true"; }
if(launchOptions.debug){ res.debug = "true"; }
if(launchOptions.launchMods?.includes(LaunchMods.OCULUS)){ res.oculusMode = "true"; }
if(launchOptions.launchMods?.includes(LaunchMods.FPFC)){ res.desktopMode = "true"; }
if(launchOptions.launchMods?.includes(LaunchMods.DEBUG)){ res.debug = "true"; }
if(launchOptions.additionalArgs){ res.additionalArgs = launchOptions.additionalArgs; }
if(launchOptions.skipSteam){ res.skipSteam = "true"; }
if(launchOptions.launchMods?.includes(LaunchMods.SKIP_STEAM)){ res.skipSteam = "true"; }
return res;
}
@@ -10,6 +10,7 @@ import { AbstractLauncherService } from "./abstract-launcher.service";
import { CustomError } from "../../../shared/models/exceptions/custom-error.class";
import { UtilsService } from "../utils.service";
import { exec } from "child_process";
import { LaunchMods } from "shared/models/bs-launch/launch-option.interface";
export class SteamLauncherService extends AbstractLauncherService implements StoreLauncherInterface{
@@ -73,7 +74,7 @@ export class SteamLauncherService extends AbstractLauncherService implements Sto
throw CustomError.fromError(new Error(`Path not exist : ${bsExePath}`), BSLaunchError.BS_NOT_FOUND);
}
const skipSteam: boolean = launchOptions.skipSteam ?? false;
const skipSteam: boolean = launchOptions.launchMods?.includes(LaunchMods.SKIP_STEAM) ?? false;
// Open Steam if not running
if(!skipSteam && !(await this.steam.isSteamRunning())){
@@ -87,12 +88,12 @@ export class SteamLauncherService extends AbstractLauncherService implements Sto
obs.next({type: BSLaunchWarning.UNABLE_TO_LAUNCH_STEAM});
});
}
else if (launchOptions.skipSteam) {
else {
obs.next({ type: BSLaunchEvent.SKIPPING_STEAM_LAUNCH});
}
// Backup SteamVR when desktop mode is enabled
if(launchOptions.desktop){
if(launchOptions.launchMods?.includes(LaunchMods.FPFC)){
await this.backupSteamVR().catch(() => {
return this.restoreSteamVR();
});