mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-23 19:01:02 +00:00
Merge remote-tracking branch 'origin/main' into feat/add-select-folder-modal-in-game-installation
This commit is contained in:
@@ -1,29 +1,39 @@
|
||||
import type { CatalogueEntry } from "@types";
|
||||
import type { CatalogueEntry, GameShop } from "@types";
|
||||
|
||||
import { registerEvent } from "../register-event";
|
||||
import { searchGames } from "../helpers/search-games";
|
||||
import slice from "lodash/slice";
|
||||
import { searchRepacks } from "../helpers/search-games";
|
||||
import { stateManager } from "@main/state-manager";
|
||||
import { getSteamAppAsset } from "@main/helpers";
|
||||
|
||||
const steamGames = stateManager.getValue("steamGames");
|
||||
|
||||
const getGames = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
take?: number,
|
||||
prevCursor = 0
|
||||
cursor = 0
|
||||
): Promise<{ results: CatalogueEntry[]; cursor: number }> => {
|
||||
let results: CatalogueEntry[] = [];
|
||||
let i = 0;
|
||||
const results: CatalogueEntry[] = [];
|
||||
|
||||
const batchSize = 100;
|
||||
let i = 0 + cursor;
|
||||
|
||||
while (results.length < take) {
|
||||
const games = await searchGames({
|
||||
take: batchSize,
|
||||
skip: (i + prevCursor) * batchSize,
|
||||
});
|
||||
results = [...results, ...games.filter((game) => game.repacks.length)];
|
||||
const game = steamGames[i];
|
||||
const repacks = searchRepacks(game.name);
|
||||
|
||||
if (repacks.length) {
|
||||
results.push({
|
||||
objectID: String(game.id),
|
||||
title: game.name,
|
||||
shop: "steam" as GameShop,
|
||||
cover: getSteamAppAsset("library", String(game.id)),
|
||||
repacks,
|
||||
});
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return { results: slice(results, 0, take), cursor: prevCursor + i };
|
||||
return { results, cursor: i };
|
||||
};
|
||||
|
||||
registerEvent(getGames, {
|
||||
|
||||
@@ -5,14 +5,13 @@ import type { GameRepack, GameShop, CatalogueEntry } from "@types";
|
||||
|
||||
import { formatName, getSteamAppAsset, repackerFormatter } from "@main/helpers";
|
||||
import { stateManager } from "@main/state-manager";
|
||||
import { steamGameRepository } from "@main/repository";
|
||||
import { FindManyOptions, Like } from "typeorm";
|
||||
import { SteamGame } from "@main/entity";
|
||||
|
||||
const { Index } = flexSearch;
|
||||
const repacksIndex = new Index();
|
||||
const steamGamesIndex = new Index({ tokenize: "reverse" });
|
||||
|
||||
const repacks = stateManager.getValue("repacks");
|
||||
const steamGames = stateManager.getValue("steamGames");
|
||||
|
||||
for (let i = 0; i < repacks.length; i++) {
|
||||
const repack = repacks[i];
|
||||
@@ -22,9 +21,12 @@ for (let i = 0; i < repacks.length; i++) {
|
||||
repacksIndex.add(i, formatName(formatter(repack.title)));
|
||||
}
|
||||
|
||||
export const searchRepacks = (title: string): GameRepack[] => {
|
||||
const repacks = stateManager.getValue("repacks");
|
||||
for (let i = 0; i < steamGames.length; i++) {
|
||||
const steamGame = steamGames[i];
|
||||
steamGamesIndex.add(i, formatName(steamGame.name));
|
||||
}
|
||||
|
||||
export const searchRepacks = (title: string): GameRepack[] => {
|
||||
return orderBy(
|
||||
repacksIndex
|
||||
.search(formatName(title))
|
||||
@@ -45,34 +47,21 @@ export const searchGames = async ({
|
||||
take,
|
||||
skip,
|
||||
}: SearchGamesArgs): Promise<CatalogueEntry[]> => {
|
||||
const options: FindManyOptions<SteamGame> = {};
|
||||
const results = steamGamesIndex
|
||||
.search(formatName(query || ""), { limit: take, offset: skip })
|
||||
.map((index) => {
|
||||
const result = steamGames.at(index as number)!;
|
||||
|
||||
if (query) {
|
||||
options.where = {
|
||||
name: query ? Like(`%${formatName(query)}%`) : undefined,
|
||||
};
|
||||
}
|
||||
return {
|
||||
objectID: String(result.id),
|
||||
title: result.name,
|
||||
shop: "steam" as GameShop,
|
||||
cover: getSteamAppAsset("library", String(result.id)),
|
||||
repacks: searchRepacks(result.name),
|
||||
};
|
||||
});
|
||||
|
||||
const steamResults = await steamGameRepository.find({
|
||||
...options,
|
||||
take,
|
||||
skip,
|
||||
order: { name: "ASC" },
|
||||
});
|
||||
|
||||
const results = steamResults.map((result) => ({
|
||||
objectID: String(result.id),
|
||||
title: result.name,
|
||||
shop: "steam" as GameShop,
|
||||
cover: getSteamAppAsset("library", String(result.id)),
|
||||
}));
|
||||
|
||||
return Promise.all(
|
||||
results.map(async (result) => ({
|
||||
...result,
|
||||
repacks: searchRepacks(result.title),
|
||||
}))
|
||||
).then((resultsWithRepacks) =>
|
||||
return Promise.all(results).then((resultsWithRepacks) =>
|
||||
orderBy(
|
||||
resultsWithRepacks,
|
||||
[({ repacks }) => repacks.length, "repacks"],
|
||||
|
||||
@@ -10,7 +10,8 @@ const addGameToLibrary = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
objectID: string,
|
||||
title: string,
|
||||
gameShop: GameShop
|
||||
gameShop: GameShop,
|
||||
executablePath: string
|
||||
) => {
|
||||
const iconUrl = await getImageBase64(await getSteamGameIconUrl(objectID));
|
||||
|
||||
@@ -19,6 +20,7 @@ const addGameToLibrary = async (
|
||||
iconUrl,
|
||||
objectID,
|
||||
shop: gameShop,
|
||||
executablePath,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user