mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-19 01:03:57 +00:00
feat: add custom launch options to game
This commit is contained in:
@@ -37,6 +37,9 @@ export class Game {
|
||||
@Column("text", { nullable: true })
|
||||
executablePath: string | null;
|
||||
|
||||
@Column("text", { nullable: true })
|
||||
launchOptions: string | null;
|
||||
|
||||
@Column("text", { nullable: true })
|
||||
winePrefixPath: string | null;
|
||||
|
||||
|
||||
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);
|
||||
@@ -16,6 +16,7 @@ import { AddDisableNsfwAlertColumn } from "./migrations/20241106053733_add_disab
|
||||
import { AddShouldSeedColumn } from "./migrations/20241108200154_add_should_seed_colum";
|
||||
import { AddSeedAfterDownloadColumn } from "./migrations/20241108201806_add_seed_after_download";
|
||||
import { AddHiddenAchievementDescriptionColumn } from "./migrations/20241216140633_add_hidden_achievement_description_column ";
|
||||
import { AddLaunchOptionsColumnToGame } from "./migrations/20241226044022_add_launch_options_column_to_game";
|
||||
|
||||
export type HydraMigration = Knex.Migration & { name: string };
|
||||
|
||||
@@ -37,6 +38,7 @@ class MigrationSource implements Knex.MigrationSource<HydraMigration> {
|
||||
AddShouldSeedColumn,
|
||||
AddSeedAfterDownloadColumn,
|
||||
AddHiddenAchievementDescriptionColumn,
|
||||
AddLaunchOptionsColumnToGame,
|
||||
]);
|
||||
}
|
||||
getMigrationName(migration: HydraMigration): string {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { HydraMigration } from "@main/knex-client";
|
||||
import type { Knex } from "knex";
|
||||
|
||||
export const AddLaunchOptionsColumnToGame: HydraMigration = {
|
||||
name: "AddLaunchOptionsColumnToGame",
|
||||
up: (knex: Knex) => {
|
||||
return knex.schema.alterTable("game", (table) => {
|
||||
return table.string("launchOptions").nullable();
|
||||
});
|
||||
},
|
||||
|
||||
down: async (knex: Knex) => {
|
||||
return knex.schema.alterTable("game", (table) => {
|
||||
return table.dropColumn("launchOptions");
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user