mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-25 20:01:03 +00:00
feat: dispatching event when remote games are fetched
This commit is contained in:
@@ -10,7 +10,7 @@ import { fetchDownloadSourcesAndUpdate } from "./helpers";
|
||||
import { publishNewRepacksNotifications } from "./services/notifications";
|
||||
import { MoreThan } from "typeorm";
|
||||
import { HydraApi } from "./services/hydra-api";
|
||||
import { getRemoteGames, uploadBatchGames } from "./services/library-sync";
|
||||
import { uploadGamesBatch } from "./services/library-sync";
|
||||
|
||||
startMainLoop();
|
||||
|
||||
@@ -23,10 +23,7 @@ const loadState = async (userPreferences: UserPreferences | null) => {
|
||||
RealDebridClient.authorize(userPreferences?.realDebridApiToken);
|
||||
|
||||
HydraApi.setupApi().then(async () => {
|
||||
if (HydraApi.isLoggedIn()) {
|
||||
await uploadBatchGames();
|
||||
getRemoteGames();
|
||||
}
|
||||
if (HydraApi.isLoggedIn()) uploadGamesBatch();
|
||||
});
|
||||
|
||||
const [nextQueueItem] = await downloadQueueRepository.find({
|
||||
|
||||
@@ -2,7 +2,7 @@ import { userAuthRepository } from "@main/repository";
|
||||
import axios, { AxiosError, AxiosInstance } from "axios";
|
||||
import { WindowManager } from "./window-manager";
|
||||
import url from "url";
|
||||
import { getRemoteGames, uploadBatchGames } from "./library-sync";
|
||||
import { uploadGamesBatch } from "./library-sync";
|
||||
|
||||
export class HydraApi {
|
||||
private static instance: AxiosInstance;
|
||||
@@ -50,9 +50,7 @@ export class HydraApi {
|
||||
|
||||
if (WindowManager.mainWindow) {
|
||||
WindowManager.mainWindow.webContents.send("on-signin");
|
||||
|
||||
await uploadBatchGames();
|
||||
await getRemoteGames();
|
||||
uploadGamesBatch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from "./get-remote-games";
|
||||
export * from "./upload-batch-games";
|
||||
export * from "./merge-with-remote-games";
|
||||
export * from "./upload-games-batch";
|
||||
export * from "./update-game-playtime";
|
||||
export * from "./create-game";
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getSteamAppAsset } from "@main/helpers";
|
||||
import { logger } from "../logger";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
export const getRemoteGames = async () => {
|
||||
export const mergeWithRemoteGames = async () => {
|
||||
try {
|
||||
const games = await HydraApi.get("/games");
|
||||
|
||||
@@ -5,13 +5,17 @@ import { HydraApi } from "../hydra-api";
|
||||
import { logger } from "../logger";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
export const uploadBatchGames = async () => {
|
||||
import { mergeWithRemoteGames } from "./merge-with-remote-games";
|
||||
import { WindowManager } from "../window-manager";
|
||||
|
||||
export const uploadGamesBatch = async () => {
|
||||
try {
|
||||
const games = await gameRepository.find({
|
||||
where: { remoteId: IsNull(), isDeleted: false },
|
||||
});
|
||||
|
||||
const gamesChunks = chunk(games, 200);
|
||||
|
||||
for (const chunk of gamesChunks) {
|
||||
await HydraApi.post(
|
||||
"/games/batch",
|
||||
@@ -25,11 +29,16 @@ export const uploadBatchGames = async () => {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
await mergeWithRemoteGames();
|
||||
|
||||
if (WindowManager.mainWindow)
|
||||
WindowManager.mainWindow.webContents.send("on-library-batch-complete");
|
||||
} catch (err) {
|
||||
if (err instanceof AxiosError) {
|
||||
logger.error("uploadBatchGames", err.response, err.message);
|
||||
logger.error("uploadGamesBatch", err.response, err.message);
|
||||
} else {
|
||||
logger.error("uploadBatchGames", err);
|
||||
logger.error("uploadGamesBatch", err);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user