mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-30 22:31:03 +00:00
feat: adding shortcut for all users
This commit is contained in:
@@ -5,7 +5,7 @@ import {
|
|||||||
composeSteamShortcut,
|
composeSteamShortcut,
|
||||||
getSteamLocation,
|
getSteamLocation,
|
||||||
getSteamShortcuts,
|
getSteamShortcuts,
|
||||||
getSteamUserId,
|
getSteamUsersIds,
|
||||||
HydraApi,
|
HydraApi,
|
||||||
logger,
|
logger,
|
||||||
SystemPath,
|
SystemPath,
|
||||||
@@ -54,77 +54,79 @@ const createSteamShortcut = async (
|
|||||||
`/games/stats?objectId=${objectId}&shop=${shop}`
|
`/games/stats?objectId=${objectId}&shop=${shop}`
|
||||||
);
|
);
|
||||||
|
|
||||||
const steamUserId = await getSteamUserId();
|
const steamUserIds = await getSteamUsersIds();
|
||||||
|
|
||||||
if (!steamUserId) {
|
if (!steamUserIds.length) {
|
||||||
logger.error("No Steam user ID found");
|
logger.error("No Steam user ID found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Got Steam user id", steamUserId);
|
for (const steamUserId of steamUserIds) {
|
||||||
|
logger.info("Adding shortcut for Steam user", steamUserId);
|
||||||
|
|
||||||
const steamShortcuts = await getSteamShortcuts(steamUserId);
|
const steamShortcuts = await getSteamShortcuts(steamUserId);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
steamShortcuts.some(
|
steamShortcuts.some(
|
||||||
(shortcut) =>
|
(shortcut) =>
|
||||||
shortcut.Exe === game.executablePath &&
|
shortcut.Exe === game.executablePath &&
|
||||||
shortcut.appname === game.title
|
shortcut.appname === game.title
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return;
|
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",
|
||||||
|
steamUserId.toString(),
|
||||||
|
"config",
|
||||||
|
"grid"
|
||||||
|
);
|
||||||
|
|
||||||
|
fs.mkdirSync(gridPath, { recursive: true });
|
||||||
|
|
||||||
|
await Promise.allSettled([
|
||||||
|
downloadAsset(
|
||||||
|
path.join(gridPath, `${newShortcut.appid}_hero.jpg`),
|
||||||
|
assets?.libraryHeroImageUrl
|
||||||
|
),
|
||||||
|
downloadAsset(
|
||||||
|
path.join(gridPath, `${newShortcut.appid}_logo.png`),
|
||||||
|
assets?.logoImageUrl
|
||||||
|
),
|
||||||
|
downloadAsset(
|
||||||
|
path.join(gridPath, `${newShortcut.appid}p.jpg`),
|
||||||
|
assets?.coverImageUrl
|
||||||
|
),
|
||||||
|
downloadAsset(
|
||||||
|
path.join(gridPath, `${newShortcut.appid}.jpg`),
|
||||||
|
assets?.libraryImageUrl
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
|
steamShortcuts.push(newShortcut);
|
||||||
|
|
||||||
|
logger.info(newShortcut);
|
||||||
|
logger.info("Writing Steam shortcuts", steamShortcuts);
|
||||||
|
|
||||||
|
await writeSteamShortcuts(steamUserId, steamShortcuts);
|
||||||
}
|
}
|
||||||
|
|
||||||
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",
|
|
||||||
steamUserId.toString(),
|
|
||||||
"config",
|
|
||||||
"grid"
|
|
||||||
);
|
|
||||||
|
|
||||||
fs.mkdirSync(gridPath, { recursive: true });
|
|
||||||
|
|
||||||
await Promise.allSettled([
|
|
||||||
downloadAsset(
|
|
||||||
path.join(gridPath, `${newShortcut.appid}_hero.jpg`),
|
|
||||||
assets?.libraryHeroImageUrl
|
|
||||||
),
|
|
||||||
downloadAsset(
|
|
||||||
path.join(gridPath, `${newShortcut.appid}_logo.png`),
|
|
||||||
assets?.logoImageUrl
|
|
||||||
),
|
|
||||||
downloadAsset(
|
|
||||||
path.join(gridPath, `${newShortcut.appid}p.jpg`),
|
|
||||||
assets?.coverImageUrl
|
|
||||||
),
|
|
||||||
downloadAsset(
|
|
||||||
path.join(gridPath, `${newShortcut.appid}.jpg`),
|
|
||||||
assets?.libraryImageUrl
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
steamShortcuts.push(newShortcut);
|
|
||||||
|
|
||||||
logger.info(newShortcut);
|
|
||||||
logger.info("Writing Steam shortcuts", steamShortcuts);
|
|
||||||
|
|
||||||
return writeSteamShortcuts(steamUserId, steamShortcuts);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -77,34 +77,33 @@ export const getSteamAppDetails = async (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSteamUserId = async () => {
|
export const getSteamUsersIds = async () => {
|
||||||
const userDataPath = await getSteamLocation();
|
const userDataPath = await getSteamLocation();
|
||||||
|
|
||||||
const userIds = fs.readdirSync(path.join(userDataPath, "userdata"), {
|
const userIds = fs.readdirSync(path.join(userDataPath, "userdata"), {
|
||||||
withFileTypes: true,
|
withFileTypes: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [steamUserId] = userIds.filter((dir) => dir.isDirectory());
|
return userIds
|
||||||
if (!steamUserId) {
|
.filter((dir) => dir.isDirectory())
|
||||||
return null;
|
.map((dir) => Number(dir.name));
|
||||||
}
|
|
||||||
|
|
||||||
return Number(steamUserId.name);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSteamShortcuts = async (steamUserId: number) => {
|
export const getSteamShortcuts = async (steamUserId: number) => {
|
||||||
const shortcuts = parseBuffer(
|
const shortcutsPath = path.join(
|
||||||
fs.readFileSync(
|
await getSteamLocation(),
|
||||||
path.join(
|
"userdata",
|
||||||
await getSteamLocation(),
|
steamUserId.toString(),
|
||||||
"userdata",
|
"config",
|
||||||
steamUserId.toString(),
|
"shortcuts.vdf"
|
||||||
"config",
|
|
||||||
"shortcuts.vdf"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!fs.existsSync(shortcutsPath)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const shortcuts = parseBuffer(fs.readFileSync(shortcutsPath));
|
||||||
|
|
||||||
return shortcuts.shortcuts as SteamShortcut[];
|
return shortcuts.shortcuts as SteamShortcut[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -126,8 +125,8 @@ export const composeSteamShortcut = (
|
|||||||
return {
|
return {
|
||||||
appid: generateSteamShortcutAppId(executablePath, title),
|
appid: generateSteamShortcutAppId(executablePath, title),
|
||||||
appname: title,
|
appname: title,
|
||||||
Exe: executablePath,
|
Exe: `"${executablePath}"`,
|
||||||
StartDir: path.dirname(executablePath),
|
StartDir: `"${path.dirname(executablePath)}"`,
|
||||||
icon: iconPath ?? "",
|
icon: iconPath ?? "",
|
||||||
ShortcutPath: "",
|
ShortcutPath: "",
|
||||||
LaunchOptions: "",
|
LaunchOptions: "",
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export function GameOptionsModal({
|
|||||||
const [automaticCloudSync, setAutomaticCloudSync] = useState(
|
const [automaticCloudSync, setAutomaticCloudSync] = useState(
|
||||||
game.automaticCloudSync ?? false
|
game.automaticCloudSync ?? false
|
||||||
);
|
);
|
||||||
|
const [creatingSteamShortcut, setCreatingSteamShortcut] = useState(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
removeGameInstaller,
|
removeGameInstaller,
|
||||||
@@ -111,6 +112,7 @@ export function GameOptionsModal({
|
|||||||
|
|
||||||
const handleCreateSteamShortcut = async () => {
|
const handleCreateSteamShortcut = async () => {
|
||||||
try {
|
try {
|
||||||
|
setCreatingSteamShortcut(true);
|
||||||
await window.electron.createSteamShortcut(game.shop, game.objectId);
|
await window.electron.createSteamShortcut(game.shop, game.objectId);
|
||||||
|
|
||||||
showSuccessToast(
|
showSuccessToast(
|
||||||
@@ -120,6 +122,8 @@ export function GameOptionsModal({
|
|||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
logger.error("Failed to create Steam shortcut", error);
|
logger.error("Failed to create Steam shortcut", error);
|
||||||
showErrorToast(t("create_shortcut_error"));
|
showErrorToast(t("create_shortcut_error"));
|
||||||
|
} finally {
|
||||||
|
setCreatingSteamShortcut(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user