This commit is contained in:
lilezek
2024-04-30 10:01:52 +02:00
156 changed files with 2841 additions and 7759 deletions

View File

@@ -9,7 +9,7 @@ const steamGames = stateManager.getValue("steamGames");
const getGames = async (
_event: Electron.IpcMainInvokeEvent,
take?: number,
take = 12,
cursor = 0
): Promise<{ results: CatalogueEntry[]; cursor: number }> => {
const results: CatalogueEntry[] = [];

View File

@@ -1,27 +1,40 @@
import shuffle from "lodash/shuffle";
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 state = { games: Array<Steam250Game>(), index: 0 };
const getRandomGame = async (_event: Electron.IpcMainInvokeEvent) => {
return getRandomSteam250List().then(async (games) => {
const shuffledList = shuffle(games);
if (state.games.length == 0) {
const steam250List = await getSteam250List();
for (const game of shuffledList) {
const repacks = searchRepacks(formatName(game.title));
const filteredSteam250List = steam250List.filter((game) => {
const repacks = searchRepacks(game.title);
const catalogue = searchGames({ query: game.title });
if (repacks.length) {
const results = await searchGames({ query: game.title });
return repacks.length && catalogue.length;
});
if (results.length) {
return results[0].objectID;
}
}
}
});
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, {

View File

@@ -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,
});

View File

@@ -1,5 +1,5 @@
import flexSearch from "flexsearch";
import orderBy from "lodash/orderBy";
import { orderBy } from "lodash-es";
import type { GameRepack, GameShop, CatalogueEntry } from "@types";
@@ -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"]
);
};

View File

@@ -10,12 +10,13 @@ import "./catalogue/search-games";
import "./hardware/get-disk-free-space";
import "./library/add-game-to-library";
import "./library/close-game";
import "./torrenting/delete-game-folder";
import "./library/delete-game-folder";
import "./library/get-game-by-object-id";
import "./library/get-library";
import "./library/get-repackers-friendly-names";
import "./library/open-game";
import "./library/open-game-installer";
import "./library/remove-game";
import "./library/remove-game-from-library";
import "./misc/get-or-cache-image";
import "./misc/open-external";
@@ -24,7 +25,6 @@ import "./torrenting/cancel-game-download";
import "./torrenting/pause-game-download";
import "./torrenting/resume-game-download";
import "./torrenting/start-game-download";
import "./torrenting/remove-game-from-download";
import "./user-preferences/get-user-preferences";
import "./user-preferences/update-user-preferences";

View File

@@ -1,9 +1,9 @@
import path from "node:path";
import { gameRepository } from "@main/repository";
import { getProcesses } from "@main/helpers";
import { registerEvent } from "../register-event";
import { getProcesses } from "@main/helpers";
const closeGame = async (
_event: Electron.IpcMainInvokeEvent,
@@ -12,13 +12,17 @@ const closeGame = async (
const processes = await getProcesses();
const game = await gameRepository.findOne({ where: { id: gameId } });
const gameProcess = processes.find((runningProcess) => {
const basename = path.win32.basename(game.executablePath);
const basenameWithoutExtension = path.win32.basename(
game.executablePath,
path.extname(game.executablePath)
);
if (!game) return false;
const executablePath = game.executablePath!;
const basename = path.win32.basename(executablePath);
const basenameWithoutExtension = path.win32.basename(
executablePath,
path.extname(executablePath)
);
const gameProcess = processes.find((runningProcess) => {
if (process.platform === "win32") {
return runningProcess.name === basename;
}

View File

@@ -2,10 +2,10 @@ import { gameRepository } from "@main/repository";
import { searchRepacks } from "../helpers/search-games";
import { registerEvent } from "../register-event";
import sortBy from "lodash/sortBy";
import { GameStatus } from "@globals";
import { sortBy } from "lodash-es";
const getLibrary = async (_event: Electron.IpcMainInvokeEvent) =>
const getLibrary = async () =>
gameRepository
.find({
where: {

View File

@@ -1,7 +1,7 @@
import { registerEvent } from "../register-event";
import { stateManager } from "@main/state-manager";
const getRepackersFriendlyNames = async (_event: Electron.IpcMainInvokeEvent) =>
const getRepackersFriendlyNames = async () =>
stateManager.getValue("repackersFriendlyNames").reduce((prev, next) => {
return { ...prev, [next.name]: next.friendlyName };
}, {});

View File

@@ -1,25 +1,16 @@
import { GameStatus } from "@globals";
import { gameRepository } from "@main/repository";
import { registerEvent } from "../register-event";
import { gameRepository } from "../../repository";
import { GameStatus } from "@globals";
const removeGameFromDownload = async (
const removeGame = async (
_event: Electron.IpcMainInvokeEvent,
gameId: number
) => {
const game = await gameRepository.findOne({
where: {
await gameRepository.update(
{
id: gameId,
status: GameStatus.Cancelled,
},
});
if (!game) return;
gameRepository.update(
{
id: game.id,
},
{
status: null,
downloadPath: null,
@@ -29,6 +20,6 @@ const removeGameFromDownload = async (
);
};
registerEvent(removeGameFromDownload, {
name: "removeGameFromDownload",
registerEvent(removeGame, {
name: "removeGame",
});

View File

@@ -25,7 +25,7 @@ const pauseGameDownload = async (
.then((result) => {
if (result.affected) {
Downloader.pauseDownload();
WindowManager.mainWindow.setProgressBar(-1);
WindowManager.mainWindow?.setProgressBar(-1);
}
});
};

View File

@@ -1,7 +1,7 @@
import { userPreferencesRepository } from "@main/repository";
import { registerEvent } from "../register-event";
const getUserPreferences = async (_event: Electron.IpcMainInvokeEvent) =>
const getUserPreferences = async () =>
userPreferencesRepository.findOne({
where: { id: 1 },
});