mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-22 02:13:59 +00:00
feat: adding steam client icon cache
This commit is contained in:
40
src/main/scripts/get-games-icon-hash.ts
Normal file
40
src/main/scripts/get-games-icon-hash.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
|
||||
import { getSteamGameClientIcon, logger } from "@main/services";
|
||||
import { chunk } from "lodash-es";
|
||||
import { seedsPath } from "@main/constants";
|
||||
|
||||
import type { SteamGame } from "@types";
|
||||
|
||||
const steamGamesPath = path.join(seedsPath, "steam-games.json");
|
||||
|
||||
const steamGames = JSON.parse(
|
||||
fs.readFileSync(steamGamesPath, "utf-8")
|
||||
) as SteamGame[];
|
||||
|
||||
const chunks = chunk(steamGames, 1500);
|
||||
|
||||
for (const chunk of chunks) {
|
||||
await Promise.all(
|
||||
chunk.map(async (steamGame) => {
|
||||
if (steamGame.clientIcon) return;
|
||||
|
||||
const index = steamGames.findIndex((game) => game.id === steamGame.id);
|
||||
|
||||
try {
|
||||
const clientIcon = await getSteamGameClientIcon(String(steamGame.id));
|
||||
|
||||
steamGames[index].clientIcon = clientIcon;
|
||||
|
||||
logger.log("info", `Set ${steamGame.name} client icon`);
|
||||
} catch (err) {
|
||||
steamGames[index].clientIcon = null;
|
||||
logger.log("info", `Could not set icon for ${steamGame.name}`);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
fs.writeFileSync(steamGamesPath, JSON.stringify(steamGames));
|
||||
logger.log("info", "Updated steam games");
|
||||
}
|
||||
Reference in New Issue
Block a user