mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-18 08:43:57 +00:00
Merge branch 'main' into feat/add-wine-lutris-integration
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { formatName, getSteamAppAsset, repackerFormatter } from "@main/helpers";
|
||||
import { formatName, repackerFormatter } from "@main/helpers";
|
||||
import { getTrendingGames } from "@main/services";
|
||||
import type { CatalogueCategory, CatalogueEntry, GameShop } from "@types";
|
||||
import type { CatalogueCategory, CatalogueEntry } from "@types";
|
||||
|
||||
import { stateManager } from "@main/state-manager";
|
||||
import { searchGames, searchRepacks } from "../helpers/search-games";
|
||||
import { searchGames } from "../helpers/search-games";
|
||||
import { registerEvent } from "../register-event";
|
||||
|
||||
const repacks = stateManager.getValue("repacks");
|
||||
@@ -12,7 +12,14 @@ const getCatalogue = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
category: CatalogueCategory
|
||||
) => {
|
||||
const trendingGames = await getTrendingGames();
|
||||
|
||||
let i = 0;
|
||||
const results: CatalogueEntry[] = [];
|
||||
|
||||
const getStringForLookup = (index: number) => {
|
||||
if (category === "trending") return trendingGames[index];
|
||||
|
||||
const repack = repacks[index];
|
||||
const formatter =
|
||||
repackerFormatter[repack.repacker as keyof typeof repackerFormatter];
|
||||
@@ -23,56 +30,10 @@ const getCatalogue = async (
|
||||
if (!repacks.length) return [];
|
||||
|
||||
const resultSize = 12;
|
||||
const requestSize = resultSize;
|
||||
|
||||
if (category === "trending") {
|
||||
return searchTrending(resultSize);
|
||||
} else {
|
||||
return searchRecentlyAdded(resultSize, requestSize, getStringForLookup);
|
||||
}
|
||||
};
|
||||
|
||||
const searchTrending = async (
|
||||
resultSize: number
|
||||
): Promise<CatalogueEntry[]> => {
|
||||
const results: CatalogueEntry[] = [];
|
||||
const trendingGames = await getTrendingGames();
|
||||
for (
|
||||
let i = 0;
|
||||
i < trendingGames.length && results.length < resultSize;
|
||||
i++
|
||||
) {
|
||||
if (!trendingGames[i]) continue;
|
||||
|
||||
const { title, objectID } = trendingGames[i];
|
||||
const repacks = searchRepacks(title);
|
||||
|
||||
if (title && repacks.length) {
|
||||
const catalogueEntry = {
|
||||
objectID,
|
||||
title,
|
||||
shop: "steam" as GameShop,
|
||||
cover: getSteamAppAsset("library", objectID),
|
||||
};
|
||||
repacks.sort(
|
||||
(a, b) =>
|
||||
new Date(a.updatedAt).getTime() - new Date(b.updatedAt).getTime()
|
||||
);
|
||||
results.push({ ...catalogueEntry, repacks });
|
||||
}
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
const searchRecentlyAdded = async (
|
||||
resultSize: number,
|
||||
requestSize: number,
|
||||
getStringForLookup: { (index: number): any; (arg0: any): any }
|
||||
): Promise<CatalogueEntry[]> => {
|
||||
const requestSize = resultSize * 2;
|
||||
let lookupRequest = [];
|
||||
const results: CatalogueEntry[] = [];
|
||||
|
||||
for (let i = 0; results.length < resultSize; i++) {
|
||||
while (results.length < resultSize) {
|
||||
const stringForLookup = getStringForLookup(i);
|
||||
|
||||
if (!stringForLookup) {
|
||||
@@ -82,6 +43,8 @@ const searchRecentlyAdded = async (
|
||||
|
||||
lookupRequest.push(searchGames(stringForLookup));
|
||||
|
||||
i++;
|
||||
|
||||
if (lookupRequest.length < requestSize) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -19,14 +19,7 @@ export const getTrendingGames = async () => {
|
||||
const { document } = window;
|
||||
|
||||
return Array.from(document.querySelectorAll(".appline .title a")).map(
|
||||
($title: HTMLAnchorElement) => {
|
||||
const steamGameUrld = $title.href;
|
||||
if (!steamGameUrld) return null;
|
||||
return {
|
||||
title: $title.textContent,
|
||||
objectID: steamGameUrld.split("/").pop(),
|
||||
};
|
||||
}
|
||||
($title) => $title.textContent!
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user