mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-22 02:13:59 +00:00
feat: add custom launch options to game
This commit is contained in:
9
src/main/events/helpers/parse-launch-options.ts
Normal file
9
src/main/events/helpers/parse-launch-options.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export const parseLaunchOptions = (params: string | null): string[] => {
|
||||
if (params == null || params == "") {
|
||||
return [];
|
||||
}
|
||||
|
||||
const paramsSplit = params.split(" ");
|
||||
|
||||
return paramsSplit;
|
||||
};
|
||||
@@ -22,6 +22,7 @@ import "./library/open-game-executable-path";
|
||||
import "./library/open-game-installer";
|
||||
import "./library/open-game-installer-path";
|
||||
import "./library/update-executable-path";
|
||||
import "./library/update-launch-options";
|
||||
import "./library/verify-executable-path";
|
||||
import "./library/remove-game";
|
||||
import "./library/remove-game-from-library";
|
||||
|
||||
@@ -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);
|
||||
|
||||
19
src/main/events/library/update-launch-options.ts
Normal file
19
src/main/events/library/update-launch-options.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { gameRepository } from "@main/repository";
|
||||
import { registerEvent } from "../register-event";
|
||||
|
||||
const updateLaunchOptions = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
id: number,
|
||||
launchOptions: string | null
|
||||
) => {
|
||||
return gameRepository.update(
|
||||
{
|
||||
id,
|
||||
},
|
||||
{
|
||||
launchOptions: launchOptions?.trim() != "" ? launchOptions : null,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
registerEvent("updateLaunchOptions", updateLaunchOptions);
|
||||
Reference in New Issue
Block a user