mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
chore: merge with main
This commit is contained in:
commit
5b74ef512a
6 changed files with 91 additions and 72 deletions
|
|
@ -1,29 +1,40 @@
|
|||
import { shuffle } from "lodash-es";
|
||||
|
||||
import { getRandomSteam250List } from "@main/services";
|
||||
import { Steam250Game, getSteam250List } from "@main/services";
|
||||
|
||||
import { registerEvent } from "../register-event";
|
||||
import { searchGames, searchRepacks } from "../helpers/search-games";
|
||||
import { formatName } from "@main/helpers";
|
||||
|
||||
const getRandomGame = async () => {
|
||||
return getRandomSteam250List().then(async (games) => {
|
||||
const shuffledList = shuffle(games);
|
||||
const state = { games: Array<Steam250Game>(), index: 0 };
|
||||
|
||||
for (const game of shuffledList) {
|
||||
const repacks = searchRepacks(formatName(game.title));
|
||||
const getRandomGame = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
if (state.games.length == 0) {
|
||||
const steam250List = await getSteam250List();
|
||||
|
||||
if (repacks.length) {
|
||||
const results = await searchGames({ query: game.title });
|
||||
const filteredSteam250List = steam250List.filter((game) => {
|
||||
const repacks = searchRepacks(game.title);
|
||||
const catalogue = searchGames({ query: game.title });
|
||||
|
||||
if (results.length) {
|
||||
return results[0].objectID;
|
||||
}
|
||||
}
|
||||
}
|
||||
return repacks.length && catalogue.length;
|
||||
});
|
||||
|
||||
return null;
|
||||
});
|
||||
state.games = shuffle(filteredSteam250List);
|
||||
}
|
||||
|
||||
if (state.games.length == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const resultObjectId = state.games[state.index].objectID;
|
||||
|
||||
state.index += 1;
|
||||
|
||||
if (state.index == state.games.length) {
|
||||
state.index = 0;
|
||||
state.games = shuffle(state.games);
|
||||
}
|
||||
|
||||
return resultObjectId;
|
||||
};
|
||||
|
||||
registerEvent(getRandomGame, {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
import { registerEvent } from "../register-event";
|
||||
import { searchGames } from "../helpers/search-games";
|
||||
import { CatalogueEntry } from "@types";
|
||||
|
||||
registerEvent(
|
||||
(_event: Electron.IpcMainInvokeEvent, query: string) =>
|
||||
searchGames({ query, take: 12 }),
|
||||
{
|
||||
name: "searchGames",
|
||||
memoize: true,
|
||||
}
|
||||
);
|
||||
const searchGamesEvent = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
query: string
|
||||
): Promise<CatalogueEntry[]> => {
|
||||
return searchGames({ query, take: 12 });
|
||||
};
|
||||
|
||||
registerEvent(searchGamesEvent, {
|
||||
name: "searchGames",
|
||||
memoize: true,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -42,11 +42,11 @@ export interface SearchGamesArgs {
|
|||
skip?: number;
|
||||
}
|
||||
|
||||
export const searchGames = async ({
|
||||
export const searchGames = ({
|
||||
query,
|
||||
take,
|
||||
skip,
|
||||
}: SearchGamesArgs): Promise<CatalogueEntry[]> => {
|
||||
}: SearchGamesArgs): CatalogueEntry[] => {
|
||||
const results = steamGamesIndex
|
||||
.search(formatName(query || ""), { limit: take, offset: skip })
|
||||
.map((index) => {
|
||||
|
|
@ -61,11 +61,9 @@ export const searchGames = async ({
|
|||
};
|
||||
});
|
||||
|
||||
return Promise.all(results).then((resultsWithRepacks) =>
|
||||
orderBy(
|
||||
resultsWithRepacks,
|
||||
[({ repacks }) => repacks.length, "repacks"],
|
||||
["desc"]
|
||||
)
|
||||
return orderBy(
|
||||
results,
|
||||
[({ repacks }) => repacks.length, "repacks"],
|
||||
["desc"]
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue