feat: add lutris/wine integration to open game function

This commit is contained in:
Fhilipe Coelho 2024-04-11 12:26:13 -03:00
parent 323e451d5a
commit 1b41b0bd0a
2 changed files with 51 additions and 1 deletions

View File

@ -1,6 +1,9 @@
import { gameRepository } from "@main/repository";
import { generateYML } from "../misc/generate-lutris-yaml";
import path from "node:path";
import fs from "node:fs";
import { writeFile } from "node:fs/promises";
import { spawn, spawnSync } from "node:child_process";
import { registerEvent } from "../register-event";
import { shell } from "electron";
@ -22,7 +25,23 @@ const openGame = async (
if (fs.existsSync(gamePath)) {
const setupPath = path.join(gamePath, "setup.exe");
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 {
shell.openPath(gamePath);
}

View 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();
}