Skip to content

Commit

Permalink
feat(launcher): read shortcut links on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
prostarz committed Jan 7, 2025
1 parent dcc33aa commit 29b30be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions backend/handlers/launcher/gameProcessLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import windoww from "../../utils/window";
import { AchievementItem } from "../achievements/item";
import { logger } from "../logging";
import { gamesLaunched } from "./games_launched";
import { spawnSync } from "./utils";
import { getRealPath, spawnSync } from "./utils";

interface Options {
game_path: string;
Expand Down Expand Up @@ -50,7 +50,7 @@ class GameProcessLauncher {
throw new Error(`Invalid game path: ${game_path}`);
}

this.gamePath = game_path;
this.gamePath = getRealPath(game_path);
this.gameId = game_id;
this.gameArgs = game_args;
this.gameCommand = game_command;
Expand Down
16 changes: 13 additions & 3 deletions backend/handlers/launcher/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import child_process from "child_process";
import { shell } from "electron";
import path from "path";

export function spawnSync(
export const spawnSync = (
command: string,
programPath: string,
args: string[],
options: child_process.SpawnOptions
) {
) => {
let cmd = programPath;

if (typeof options.cwd === "string") {
Expand All @@ -19,4 +20,13 @@ export function spawnSync(
// @ts-expect-error
env: { ...process.env, WINEDEBUG: "fixme-all" },
});
}
};

export const getRealPath = (path: string) => {
try {
if (process.platform !== "win32" && !path.endsWith(".lnk")) return path;
return shell.readShortcutLink(path).target;
} catch (error) {
return path;
}
};

0 comments on commit 29b30be

Please sign in to comment.