Skip to content

Commit

Permalink
feat: add optional game params back
Browse files Browse the repository at this point in the history
  • Loading branch information
zamitto committed Jan 5, 2025
1 parent 99364df commit 0adcc73
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
7 changes: 7 additions & 0 deletions src/main/events/helpers/parse-launch-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const parseLaunchOptions = (params: string | null): string[] => {
if (!params) {
return [];
}

return params.split(" ");
};
11 changes: 9 additions & 2 deletions src/main/events/library/open-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@ import { gameRepository } from "@main/repository";

import { registerEvent } from "../register-event";
import { shell } from "electron";
import { spawn } from "child_process";
import { parseExecutablePath } from "../helpers/parse-executable-path";
import { parseLaunchOptions } from "../helpers/parse-launch-options";

const openGame = async (
_event: Electron.IpcMainInvokeEvent,
gameId: number,
executablePath: string,
launchOptions: string | null
) => {
// TODO: revisit this for launchOptions
const parsedPath = parseExecutablePath(executablePath);
const parsedParams = parseLaunchOptions(launchOptions);

await gameRepository.update(
{ id: gameId },
{ executablePath: parsedPath, launchOptions }
);

shell.openPath(parsedPath);
if (parsedParams.length === 0) {
shell.openPath(parsedPath);
return;
}

spawn(parsedPath, parsedParams, { shell: false, detached: true });
};

registerEvent("openGame", openGame);
33 changes: 16 additions & 17 deletions src/renderer/src/pages/game-details/modals/game-options-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ export function GameOptionsModal({
}
};

const shouldShowLaunchOptionsConfiguration = false;

return (
<>
<DeleteGameModal
Expand Down Expand Up @@ -285,27 +283,28 @@ export function GameOptionsModal({
</div>
)}

{shouldShowLaunchOptionsConfiguration && (
<div className={styles.optionsContainer}>
<div className={styles.gameOptionHeader}>
<h2>{t("launch_options")}</h2>
<h4 className={styles.gameOptionHeaderDescription}>
{t("launch_options_description")}
</h4>
<TextField
value={launchOptions}
theme="dark"
placeholder={t("launch_options_placeholder")}
onChange={handleChangeLaunchOptions}
rightContent={
game.launchOptions && (
<Button onClick={handleClearLaunchOptions} theme="outline">
{t("clear")}
</Button>
)
}
/>
</div>
)}

<TextField
value={launchOptions}
theme="dark"
placeholder={t("launch_options_placeholder")}
onChange={handleChangeLaunchOptions}
rightContent={
game.launchOptions && (
<Button onClick={handleClearLaunchOptions} theme="outline">
{t("clear")}
</Button>
)
}
/>
</div>

<div className={styles.gameOptionHeader}>
<h2>{t("downloads_secion_title")}</h2>
Expand Down

0 comments on commit 0adcc73

Please sign in to comment.