feat: add optional game params back

This commit is contained in:
Zamitto 2025-01-04 21:04:58 -03:00
parent 6a52cb3f52
commit b8dcd66cd2
3 changed files with 32 additions and 19 deletions

View File

@ -0,0 +1,7 @@
export const parseLaunchOptions = (params: string | null): string[] => {
if (!params) {
return [];
}
return params.split(" ");
};

View File

@ -2,7 +2,9 @@ import { gameRepository } from "@main/repository";
import { registerEvent } from "../register-event"; import { registerEvent } from "../register-event";
import { shell } from "electron"; import { shell } from "electron";
import { spawn } from "child_process";
import { parseExecutablePath } from "../helpers/parse-executable-path"; import { parseExecutablePath } from "../helpers/parse-executable-path";
import { parseLaunchOptions } from "../helpers/parse-launch-options";
const openGame = async ( const openGame = async (
_event: Electron.IpcMainInvokeEvent, _event: Electron.IpcMainInvokeEvent,
@ -10,15 +12,20 @@ const openGame = async (
executablePath: string, executablePath: string,
launchOptions: string | null launchOptions: string | null
) => { ) => {
// TODO: revisit this for launchOptions
const parsedPath = parseExecutablePath(executablePath); const parsedPath = parseExecutablePath(executablePath);
const parsedParams = parseLaunchOptions(launchOptions);
await gameRepository.update( await gameRepository.update(
{ id: gameId }, { id: gameId },
{ executablePath: parsedPath, launchOptions } { executablePath: parsedPath, launchOptions }
); );
if (parsedParams.length === 0) {
shell.openPath(parsedPath); shell.openPath(parsedPath);
return;
}
spawn(parsedPath, parsedParams, { shell: false, detached: true });
}; };
registerEvent("openGame", openGame); registerEvent("openGame", openGame);

View File

@ -169,8 +169,6 @@ export function GameOptionsModal({
} }
}; };
const shouldShowLaunchOptionsConfiguration = false;
return ( return (
<> <>
<DeleteGameModal <DeleteGameModal
@ -285,12 +283,14 @@ export function GameOptionsModal({
</div> </div>
)} )}
{shouldShowLaunchOptionsConfiguration && ( <div className={styles.optionsContainer}>
<div className={styles.gameOptionHeader}> <div className={styles.gameOptionHeader}>
<h2>{t("launch_options")}</h2> <h2>{t("launch_options")}</h2>
<h4 className={styles.gameOptionHeaderDescription}> <h4 className={styles.gameOptionHeaderDescription}>
{t("launch_options_description")} {t("launch_options_description")}
</h4> </h4>
</div>
<TextField <TextField
value={launchOptions} value={launchOptions}
theme="dark" theme="dark"
@ -305,7 +305,6 @@ export function GameOptionsModal({
} }
/> />
</div> </div>
)}
<div className={styles.gameOptionHeader}> <div className={styles.gameOptionHeader}>
<h2>{t("downloads_secion_title")}</h2> <h2>{t("downloads_secion_title")}</h2>