mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: add lutris/wine integration to open game function
This commit is contained in:
parent
323e451d5a
commit
1b41b0bd0a
2 changed files with 51 additions and 1 deletions
|
@ -1,6 +1,9 @@
|
||||||
import { gameRepository } from "@main/repository";
|
import { gameRepository } from "@main/repository";
|
||||||
|
import { generateYML } from "../misc/generate-lutris-yaml";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
|
import { writeFile } from "node:fs/promises";
|
||||||
|
import { spawn, spawnSync } from "node:child_process";
|
||||||
|
|
||||||
import { registerEvent } from "../register-event";
|
import { registerEvent } from "../register-event";
|
||||||
import { shell } from "electron";
|
import { shell } from "electron";
|
||||||
|
@ -22,7 +25,23 @@ const openGame = async (
|
||||||
if (fs.existsSync(gamePath)) {
|
if (fs.existsSync(gamePath)) {
|
||||||
const setupPath = path.join(gamePath, "setup.exe");
|
const setupPath = path.join(gamePath, "setup.exe");
|
||||||
if (fs.existsSync(setupPath)) {
|
if (fs.existsSync(setupPath)) {
|
||||||
shell.openExternal(setupPath);
|
if (process.platform === "win32") {
|
||||||
|
shell.openExternal(setupPath);
|
||||||
|
}
|
||||||
|
if (process.platform === "linux") {
|
||||||
|
if (spawnSync('which', ['lutris']).status === 0) {
|
||||||
|
const ymlPath = path.join(gamePath, "setup.yml");
|
||||||
|
await writeFile(ymlPath, generateYML(game));
|
||||||
|
const subprocess = spawn(`lutris --install '${ymlPath}'`, {
|
||||||
|
shell: true,
|
||||||
|
detached: true,
|
||||||
|
stdio: 'ignore'
|
||||||
|
});
|
||||||
|
subprocess.unref();
|
||||||
|
} else {
|
||||||
|
spawn(`wine '${setupPath}'`, { shell: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
shell.openPath(gamePath);
|
shell.openPath(gamePath);
|
||||||
}
|
}
|
||||||
|
|
31
src/main/events/misc/generate-lutris-yaml.ts
Normal file
31
src/main/events/misc/generate-lutris-yaml.ts
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import { Document as YMLDocument } from 'yaml';
|
||||||
|
import { Game } from '@main/entity';
|
||||||
|
|
||||||
|
export function generateYML(game: Game) {
|
||||||
|
const slugfiedName = game.title.replace(/\s/g, '-').toLocaleLowerCase();
|
||||||
|
|
||||||
|
const doc = new YMLDocument({
|
||||||
|
name: game.title,
|
||||||
|
game_slug: slugfiedName,
|
||||||
|
slug: `${slugfiedName}-installer`,
|
||||||
|
version: 'Installer',
|
||||||
|
runner: 'wine',
|
||||||
|
script: {
|
||||||
|
installer: [{
|
||||||
|
task: {
|
||||||
|
name: "create_prefix",
|
||||||
|
arch: "win64",
|
||||||
|
prefix: "$GAMEDIR/prefix"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
task: {
|
||||||
|
executable: `${game.downloadPath}/${game.folderName}/setup.exe`,
|
||||||
|
name: "wineexec",
|
||||||
|
prefix: "$GAMEDIR/prefix"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return doc.toString();
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue