Merge branch 'feature/sync-library' of github.com:hydralauncher/hydra into feature/sync-library

This commit is contained in:
Chubby Granny Chaser 2024-06-19 02:16:18 +01:00
commit ca81281f1f
No known key found for this signature in database
6 changed files with 26 additions and 4 deletions

View file

@ -1,6 +1,7 @@
import { registerEvent } from "../register-event";
import { gameRepository } from "../../repository";
import { HydraApi } from "@main/services/hydra-api";
import { logger } from "@main/services";
const removeGameFromLibrary = async (
_event: Electron.IpcMainInvokeEvent,
@ -11,6 +12,12 @@ const removeGameFromLibrary = async (
{ isDeleted: true, executablePath: null }
);
removeRemoveGameFromLibrary(gameId).catch((err) => {
logger.error("removeRemoveGameFromLibrary", err);
});
};
const removeRemoveGameFromLibrary = async (gameId: number) => {
const game = await gameRepository.findOne({ where: { id: gameId } });
if (game?.remoteId) {

View file

@ -12,6 +12,7 @@ import { DownloadManager } from "@main/services";
import { Not } from "typeorm";
import { steamGamesWorker } from "@main/workers";
import { createGame } from "@main/services/library-sync";
const startGameDownload = async (
_event: Electron.IpcMainInvokeEvent,
@ -94,6 +95,19 @@ const startGameDownload = async (
},
});
createGame(updatedGame!).then((response) => {
const {
id: remoteId,
playTimeInMilliseconds,
lastTimePlayed,
} = response.data;
gameRepository.update(
{ objectID },
{ remoteId, playTimeInMilliseconds, lastTimePlayed }
);
});
await downloadQueueRepository.delete({ game: { id: updatedGame!.id } });
await downloadQueueRepository.insert({ game: { id: updatedGame!.id } });

View file

@ -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 } from "./services/library-sync";
import { getRemoteGames, uploadBatchGames } from "./services/library-sync";
startMainLoop();
@ -24,6 +24,7 @@ const loadState = async (userPreferences: UserPreferences | null) => {
HydraApi.setupApi().then(async () => {
if (HydraApi.isLoggedIn()) {
await uploadBatchGames();
getRemoteGames();
}
});

View file

@ -4,7 +4,7 @@ import { HydraApi } from "../hydra-api";
export const createGame = async (game: Game) => {
return HydraApi.post(`/games`, {
objectId: game.objectID,
playTimeInMilliseconds: Math.round(game.playTimeInMilliseconds),
playTimeInMilliseconds: Math.trunc(game.playTimeInMilliseconds),
shop: game.shop,
lastTimePlayed: game.lastTimePlayed,
});

View file

@ -7,7 +7,7 @@ export const updateGamePlaytime = async (
lastTimePlayed: Date
) => {
return HydraApi.put(`/games/${game.remoteId}`, {
playTimeDeltaInSeconds: delta,
playTimeDeltaInSeconds: Math.trunc(delta),
lastTimePlayed,
});
};

View file

@ -18,7 +18,7 @@ export const uploadBatchGames = async () => {
chunk.map((game) => {
return {
objectId: game.objectID,
playTimeInMilliseconds: Math.round(game.playTimeInMilliseconds),
playTimeInMilliseconds: Math.trunc(game.playTimeInMilliseconds),
shop: game.shop,
lastTimePlayed: game.lastTimePlayed,
};