feat: automatically adding wine prefix

This commit is contained in:
Chubby Granny Chaser
2025-05-14 00:50:30 +01:00
parent ca7ac73836
commit 521d9faa0c
3 changed files with 43 additions and 28 deletions

View File

@@ -61,36 +61,30 @@ const createSteamShortcut = async (
return;
}
const icon = await downloadAsset(
path.join(
SystemPath.getPath("userData"),
"Icons",
`${game.shop}-${game.objectId}.ico`
),
assets?.iconUrl
);
const newShortcut = composeSteamShortcut(
game.title,
game.executablePath,
icon
);
for (const steamUserId of steamUserIds) {
logger.info("Adding shortcut for Steam user", steamUserId);
const steamShortcuts = await getSteamShortcuts(steamUserId);
if (
steamShortcuts.some(
(shortcut) =>
shortcut.Exe === game.executablePath &&
shortcut.appname === game.title
)
) {
if (steamShortcuts.some((shortcut) => shortcut.appname === game.title)) {
continue;
}
const icon = await downloadAsset(
path.join(
SystemPath.getPath("userData"),
"Icons",
`${game.shop}-${game.objectId}.ico`
),
assets?.iconUrl
);
const newShortcut = composeSteamShortcut(
game.title,
game.executablePath,
icon
);
const gridPath = path.join(
await getSteamLocation(),
"userdata",
@@ -127,6 +121,26 @@ const createSteamShortcut = async (
await writeSteamShortcuts(steamUserId, steamShortcuts);
}
if (process.platform === "linux" && !game.winePrefixPath) {
const steamWinePrefixes = path.join(
SystemPath.getPath("home"),
".local",
"share",
"Steam",
"steamapps",
"compatdata"
);
await gamesSublevel.put(gameKey, {
...game,
winePrefixPath: path.join(
steamWinePrefixes,
newShortcut.appid.toString(),
"pfx"
),
});
}
}
};

View File

@@ -16,11 +16,7 @@ const getDefaultWinePrefixSelectionPath = async (
"compatdata"
);
if (fs.existsSync(steamWinePrefixes)) {
return fs.promises.realpath(steamWinePrefixes);
}
return null;
return await fs.promises.realpath(steamWinePrefixes);
} catch (err) {
logger.error("Failed to get default wine prefix selection path", err);

View File

@@ -119,6 +119,8 @@ export function GameOptionsModal({
t("create_shortcut_success"),
t("you_might_need_to_restart_steam")
);
updateGame();
} catch (error: unknown) {
logger.error("Failed to create Steam shortcut", error);
showErrorToast(t("create_shortcut_error"));
@@ -162,9 +164,12 @@ export function GameOptionsModal({
};
const handleChangeWinePrefixPath = async () => {
const defaultPath =
await window.electron.getDefaultWinePrefixSelectionPath();
const { filePaths } = await window.electron.showOpenDialog({
properties: ["openDirectory"],
defaultPath: await window.electron.getDefaultWinePrefixSelectionPath(),
defaultPath: defaultPath ?? game?.winePrefixPath ?? "",
});
if (filePaths && filePaths.length > 0) {