mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
Merge branch 'feature/sync-library' of github.com:hydralauncher/hydra into feature/sync-library
This commit is contained in:
commit
ca81281f1f
6 changed files with 26 additions and 4 deletions
|
@ -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) {
|
||||
|
|
|
@ -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 } });
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@ export const updateGamePlaytime = async (
|
|||
lastTimePlayed: Date
|
||||
) => {
|
||||
return HydraApi.put(`/games/${game.remoteId}`, {
|
||||
playTimeDeltaInSeconds: delta,
|
||||
playTimeDeltaInSeconds: Math.trunc(delta),
|
||||
lastTimePlayed,
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue