feat: add custom launch options to game

This commit is contained in:
Davi Souto 2024-12-26 20:43:16 -03:00
parent 83e662f633
commit 520eb91a55
15 changed files with 155 additions and 8 deletions

View file

@ -2,18 +2,37 @@ import { gameRepository } from "@main/repository";
import { registerEvent } from "../register-event";
import { shell } from "electron";
import { exec } from "child_process";
import { parseExecutablePath } from "../helpers/parse-executable-path";
import { parseLaunchOptions } from "../helpers/parse-launch-options";
import { logger } from "@main/services";
const openGame = async (
_event: Electron.IpcMainInvokeEvent,
gameId: number,
executablePath: string
executablePath: string,
launchOptions: string | null
) => {
const parsedPath = parseExecutablePath(executablePath);
const parsedParams = parseLaunchOptions(launchOptions);
const executeCommand = `"${parsedPath}" ${parsedParams}`;
await gameRepository.update({ id: gameId }, { executablePath: parsedPath });
shell.openPath(parsedPath);
if (process.platform === "linux" || process.platform === "darwin") {
shell.openPath(parsedPath);
}
if (process.platform === "win32") {
exec(executeCommand.trim(), (err) => {
if (err) {
logger.error(
`Error opening game #${gameId} with command ${executeCommand}`,
err
);
}
});
}
};
registerEvent("openGame", openGame);