feat: adjustments

This commit is contained in:
Zamitto 2024-04-27 19:54:37 -03:00
parent 523d711b49
commit 330dd9c218
2 changed files with 10 additions and 10 deletions

View file

@ -6,7 +6,7 @@ import { registerEvent } from "../register-event";
import { searchGames, searchRepacks } from "../helpers/search-games";
import { formatName } from "@main/helpers";
let gamesList = new Array<Steam250Game>();
let gamesList: Steam250Game[] = [];
let nextGameIndex = 0;
const getRandomGame = async (_event: Electron.IpcMainInvokeEvent) => {
@ -24,15 +24,15 @@ const getRandomGame = async (_event: Electron.IpcMainInvokeEvent) => {
const repacks = searchRepacks(formatName(game.title));
if (repacks.length) {
const results = await searchGames({ query: game.title });
const catalogueResults = await searchGames({ query: game.title });
if (results.length) {
resultObjectId = results[0].objectID;
if (catalogueResults.length) {
resultObjectId = catalogueResults[0].objectID;
}
}
nextGameIndex += 1;
if (nextGameIndex == gamesList.length - 1) {
if (nextGameIndex == gamesList.length) {
nextGameIndex = 0;
gamesList = shuffle(gamesList);
}

View file

@ -11,17 +11,17 @@ export const requestSteam250 = async (path: string) => {
const { window } = new JSDOM(response.data);
const { document } = window;
return Array.from(document.querySelectorAll(".appline .title a")).map(
($title: HTMLAnchorElement) => {
return Array.from(document.querySelectorAll(".appline .title a"))
.map(($title: HTMLAnchorElement) => {
const steamGameUrl = $title.href;
if (!steamGameUrl) return null;
return {
title: $title.textContent,
objectID: steamGameUrl.split("/").pop(),
};
}
);
} as Steam250Game;
})
.filter((game) => game != null);
});
};