mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
# Conflicts: # src/main/events/library/open-game.ts # src/main/events/user-preferences/update-user-preferences.ts # src/main/index.ts # src/main/main.ts # src/main/services/achievements/achievement-watcher-manager.ts # src/main/services/achievements/get-game-achievement-data.ts # src/main/services/notifications/index.ts # src/renderer/src/pages/downloads/download-group.tsx
39 lines
1 KiB
TypeScript
39 lines
1 KiB
TypeScript
import { registerEvent } from "../register-event";
|
|
import { shell } from "electron";
|
|
import { spawn } from "child_process";
|
|
import { parseExecutablePath } from "../helpers/parse-executable-path";
|
|
import { gamesSublevel, levelKeys } from "@main/level";
|
|
import { GameShop } from "@types";
|
|
import { parseLaunchOptions } from "../helpers/parse-launch-options";
|
|
|
|
const openGame = async (
|
|
_event: Electron.IpcMainInvokeEvent,
|
|
shop: GameShop,
|
|
objectId: string,
|
|
executablePath: string,
|
|
launchOptions?: string | null
|
|
) => {
|
|
const parsedPath = parseExecutablePath(executablePath);
|
|
const parsedParams = parseLaunchOptions(launchOptions);
|
|
|
|
const gameKey = levelKeys.game(shop, objectId);
|
|
|
|
const game = await gamesSublevel.get(gameKey);
|
|
|
|
if (!game) return;
|
|
|
|
await gamesSublevel.put(gameKey, {
|
|
...game,
|
|
executablePath: parsedPath,
|
|
launchOptions,
|
|
});
|
|
|
|
if (parsedParams.length === 0) {
|
|
shell.openPath(parsedPath);
|
|
return;
|
|
}
|
|
|
|
spawn(parsedPath, parsedParams, { shell: false, detached: true });
|
|
};
|
|
|
|
registerEvent("openGame", openGame);
|