Skip to content

Commit

Permalink
Merge pull request #1008 from hydralauncher/fix/migrate-repacks-from-…
Browse files Browse the repository at this point in the history
…sqlite-to-dexie

 Fix/migrate repacks from sqlite to dexie
  • Loading branch information
thegrannychaseroperation authored Sep 27, 2024
2 parents d57980e + 43e9919 commit 37111c1
Show file tree
Hide file tree
Showing 48 changed files with 695 additions and 638 deletions.
2 changes: 1 addition & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
appId: site.hydralauncher.hydra
appId: gg.hydralauncher.hydra
productName: Hydra
directories:
buildResources: build
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"color.js": "^1.2.0",
"create-desktop-shortcuts": "^1.11.0",
"date-fns": "^3.6.0",
"dexie": "^4.0.8",
"electron-log": "^5.1.4",
"electron-updater": "^6.1.8",
"fetch-cookie": "^3.0.1",
Expand Down
9 changes: 2 additions & 7 deletions src/main/events/catalogue/get-catalogue.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { GameShop } from "@types";

import { registerEvent } from "../register-event";
import { HydraApi, RepacksManager } from "@main/services";
import { CatalogueCategory, formatName, steamUrlBuilder } from "@shared";
import { HydraApi } from "@main/services";
import { CatalogueCategory, steamUrlBuilder } from "@shared";
import { steamGamesWorker } from "@main/workers";

const getCatalogue = async (
Expand All @@ -26,14 +26,9 @@ const getCatalogue = async (
name: "getById",
});

const repacks = RepacksManager.search({
query: formatName(steamGame.name),
});

return {
title: steamGame.name,
shop: game.shop,
repacks,
cover: steamUrlBuilder.library(game.objectId),
objectID: game.objectId,
};
Expand Down
20 changes: 11 additions & 9 deletions src/main/events/catalogue/get-game-shop-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ const getGameShopDetails = async (

const appDetails = getLocalizedSteamAppDetails(objectID, language).then(
(result) => {
gameShopCacheRepository.upsert(
{
objectID,
shop: "steam",
language,
serializedData: JSON.stringify(result),
},
["objectID"]
);
if (result) {
gameShopCacheRepository.upsert(
{
objectID,
shop: "steam",
language,
serializedData: JSON.stringify(result),
},
["objectID"]
);
}

return result;
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/events/catalogue/get-games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import type { CatalogueEntry } from "@types";

import { registerEvent } from "../register-event";
import { steamGamesWorker } from "@main/workers";
import { convertSteamGameToCatalogueEntry } from "../helpers/search-games";
import { RepacksManager } from "@main/services";
import { steamUrlBuilder } from "@shared";

const getGames = async (
_event: Electron.IpcMainInvokeEvent,
Expand All @@ -15,13 +14,14 @@ const getGames = async (
{ name: "list" }
);

const entries = RepacksManager.findRepacksForCatalogueEntries(
steamGames.map((game) => convertSteamGameToCatalogueEntry(game))
);

return {
results: entries,
cursor: cursor + entries.length,
results: steamGames.map((steamGame) => ({
title: steamGame.name,
shop: "steam",
cover: steamUrlBuilder.library(steamGame.id),
objectID: steamGame.id,
})),
cursor: cursor + steamGames.length,
};
};

Expand Down
19 changes: 1 addition & 18 deletions src/main/events/catalogue/get-random-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,15 @@ import { shuffle } from "lodash-es";
import { getSteam250List } from "@main/services";

import { registerEvent } from "../register-event";
import { getSteamGameById } from "../helpers/search-games";
import type { Steam250Game } from "@types";

const state = { games: Array<Steam250Game>(), index: 0 };

const filterGames = async (games: Steam250Game[]) => {
const results: Steam250Game[] = [];

for (const game of games) {
const steamGame = await getSteamGameById(game.objectID);

if (steamGame?.repacks.length) {
results.push(game);
}
}

return results;
};

const getRandomGame = async (_event: Electron.IpcMainInvokeEvent) => {
if (state.games.length == 0) {
const steam250List = await getSteam250List();

const filteredSteam250List = await filterGames(steam250List);

state.games = shuffle(filteredSteam250List);
state.games = shuffle(steam250List);
}

if (state.games.length == 0) {
Expand Down
9 changes: 0 additions & 9 deletions src/main/events/catalogue/search-game-repacks.ts

This file was deleted.

6 changes: 2 additions & 4 deletions src/main/events/catalogue/search-games.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { registerEvent } from "../register-event";
import { convertSteamGameToCatalogueEntry } from "../helpers/search-games";
import { CatalogueEntry } from "@types";
import { HydraApi, RepacksManager } from "@main/services";
import { HydraApi } from "@main/services";

const searchGamesEvent = async (
_event: Electron.IpcMainInvokeEvent,
Expand All @@ -11,15 +11,13 @@ const searchGamesEvent = async (
{ objectId: string; title: string; shop: string }[]
>("/games/search", { title: query, take: 12, skip: 0 }, { needsAuth: false });

const steamGames = games.map((game) => {
return games.map((game) => {
return convertSteamGameToCatalogueEntry({
id: Number(game.objectId),
name: game.title,
clientIcon: null,
});
});

return RepacksManager.findRepacksForCatalogueEntries(steamGames);
};

registerEvent("searchGames", searchGamesEvent);
42 changes: 0 additions & 42 deletions src/main/events/download-sources/add-download-source.ts

This file was deleted.

9 changes: 9 additions & 0 deletions src/main/events/download-sources/delete-download-source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { registerEvent } from "../register-event";
import { knexClient } from "@main/knex-client";

const deleteDownloadSource = async (
_event: Electron.IpcMainInvokeEvent,
id: number
) => knexClient("download_source").where({ id }).delete();

registerEvent("deleteDownloadSource", deleteDownloadSource);
8 changes: 2 additions & 6 deletions src/main/events/download-sources/get-download-sources.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { downloadSourceRepository } from "@main/repository";
import { registerEvent } from "../register-event";
import { knexClient } from "@main/knex-client";

const getDownloadSources = async (_event: Electron.IpcMainInvokeEvent) =>
downloadSourceRepository.find({
order: {
createdAt: "DESC",
},
});
knexClient.select("*").from("download_source");

registerEvent("getDownloadSources", getDownloadSources);
13 changes: 0 additions & 13 deletions src/main/events/download-sources/remove-download-source.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/events/download-sources/sync-download-sources.ts

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/events/download-sources/validate-download-source.ts

This file was deleted.

8 changes: 1 addition & 7 deletions src/main/events/helpers/search-games.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { GameShop, CatalogueEntry, SteamGame } from "@types";

import { steamGamesWorker } from "@main/workers";
import { RepacksManager } from "@main/services";
import { steamUrlBuilder } from "@shared";

export interface SearchGamesArgs {
Expand All @@ -17,7 +16,6 @@ export const convertSteamGameToCatalogueEntry = (
title: game.name,
shop: "steam" as GameShop,
cover: steamUrlBuilder.library(String(game.id)),
repacks: [],
});

export const getSteamGameById = async (
Expand All @@ -29,9 +27,5 @@ export const getSteamGameById = async (

if (!steamGame) return null;

const catalogueEntry = convertSteamGameToCatalogueEntry(steamGame);

const result = RepacksManager.findRepacksForCatalogueEntry(catalogueEntry);

return result;
return convertSteamGameToCatalogueEntry(steamGame);
};
13 changes: 0 additions & 13 deletions src/main/events/helpers/validators.ts

This file was deleted.

7 changes: 2 additions & 5 deletions src/main/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "./catalogue/get-games";
import "./catalogue/get-how-long-to-beat";
import "./catalogue/get-random-game";
import "./catalogue/search-games";
import "./catalogue/search-game-repacks";
import "./catalogue/get-game-stats";
import "./catalogue/get-trending-games";
import "./hardware/get-disk-free-space";
Expand Down Expand Up @@ -37,11 +36,8 @@ import "./user-preferences/auto-launch";
import "./autoupdater/check-for-updates";
import "./autoupdater/restart-and-install-update";
import "./user-preferences/authenticate-real-debrid";
import "./download-sources/delete-download-source";
import "./download-sources/get-download-sources";
import "./download-sources/validate-download-source";
import "./download-sources/add-download-source";
import "./download-sources/remove-download-source";
import "./download-sources/sync-download-sources";
import "./auth/sign-out";
import "./auth/open-auth-window";
import "./auth/get-session-hash";
Expand All @@ -60,6 +56,7 @@ import "./profile/update-profile";
import "./profile/process-profile-image";
import "./profile/send-friend-request";
import "./profile/sync-friend-requests";
import "./notifications/publish-new-repacks-notification";
import { isPortableVersion } from "@main/helpers";

ipcMain.handle("ping", () => "pong");
Expand Down
21 changes: 6 additions & 15 deletions src/main/events/library/add-game-to-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { gameRepository } from "@main/repository";
import { registerEvent } from "../register-event";

import type { GameShop } from "@types";
import { getFileBase64 } from "@main/helpers";

import { steamGamesWorker } from "@main/workers";
import { createGame } from "@main/services/library-sync";
Expand Down Expand Up @@ -36,20 +35,12 @@ const addGameToLibrary = async (
? steamUrlBuilder.icon(objectID, steamGame.clientIcon)
: null;

await gameRepository
.insert({
title,
iconUrl,
objectID,
shop,
})
.then(() => {
if (iconUrl) {
getFileBase64(iconUrl).then((base64) =>
gameRepository.update({ objectID }, { iconUrl: base64 })
);
}
});
await gameRepository.insert({
title,
iconUrl,
objectID,
shop,
});
}

const game = await gameRepository.findOne({ where: { objectID } });
Expand Down
Loading

0 comments on commit 37111c1

Please sign in to comment.