mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
29 lines
923 B
TypeScript
29 lines
923 B
TypeScript
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
|
|
) => {
|
|
const parsedPath = parseExecutablePath(executablePath);
|
|
const parsedParams = parseLaunchOptions(launchOptions);
|
|
|
|
await gameRepository.update({ id: gameId }, { executablePath: parsedPath, launchOptions });
|
|
|
|
if (process.platform === "linux" || process.platform === "darwin") {
|
|
shell.openPath(parsedPath);
|
|
}
|
|
|
|
if (process.platform === "win32") {
|
|
spawn(parsedPath, parsedParams, { shell: false });
|
|
}
|
|
};
|
|
|
|
registerEvent("openGame", openGame);
|