feat: make it possible to select shortcuts (.lnk)

This commit is contained in:
Zamitto 2024-06-27 18:05:07 -03:00
parent 82f72071f9
commit 7be626b3dd
5 changed files with 27 additions and 5 deletions

View File

@ -0,0 +1,10 @@
import { shell } from "electron";
export const parseExecutablePath = (path: string) => {
if (process.platform === "win32" && path.endsWith(".lnk")) {
const { target } = shell.readShortcutLink(path);
return target;
}
return path;
};

View File

@ -2,15 +2,18 @@ import { gameRepository } from "@main/repository";
import { registerEvent } from "../register-event";
import { shell } from "electron";
import { parseExecutablePath } from "../helpers/parse-executable-path";
const openGame = async (
_event: Electron.IpcMainInvokeEvent,
gameId: number,
executablePath: string
) => {
await gameRepository.update({ id: gameId }, { executablePath });
const parsedPath = parseExecutablePath(executablePath);
shell.openPath(executablePath);
await gameRepository.update({ id: gameId }, { executablePath: parsedPath });
shell.openPath(parsedPath);
};
registerEvent("openGame", openGame);

View File

@ -1,6 +1,7 @@
import { gameRepository } from "@main/repository";
import { registerEvent } from "../register-event";
import { parseExecutablePath } from "../helpers/parse-executable-path";
const updateExecutablePath = async (
_event: Electron.IpcMainInvokeEvent,
@ -12,7 +13,7 @@ const updateExecutablePath = async (
id,
},
{
executablePath,
executablePath: parseExecutablePath(executablePath),
}
);
};

View File

@ -11,7 +11,15 @@ export const getProcesses = async () => {
if (process.platform == "win32") {
const binaryPath = app.isPackaged
? path.join(process.resourcesPath, "fastlist.exe")
: path.join(__dirname, "..", "..", "fastlist.exe");
: path.join(
__dirname,
"..",
"..",
"node_modules",
"ps-list",
"vendor",
"fastlist-0.3.0-x64.exe"
);
const { stdout } = await execFile(binaryPath, {
maxBuffer: TEN_MEGABYTES,

View File

@ -140,7 +140,7 @@ export function GameDetailsContextProvider({
filters: [
{
name: "Game executable",
extensions: ["exe"],
extensions: ["exe", "lnk"],
},
],
})