mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 08:43:48 +03:00
feat: accumulate ticks when request to update playtime fails
This commit is contained in:
parent
f439b6809c
commit
608a53e8df
@ -54,7 +54,7 @@ const addGameToLibrary = async (
|
|||||||
|
|
||||||
const game = await gameRepository.findOne({ where: { objectID } });
|
const game = await gameRepository.findOne({ where: { objectID } });
|
||||||
|
|
||||||
createGame(game!);
|
createGame(game!).catch(() => {});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ const startGameDownload = async (
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
createGame(updatedGame!);
|
createGame(updatedGame!).catch(() => {});
|
||||||
|
|
||||||
await downloadQueueRepository.delete({ game: { id: updatedGame!.id } });
|
await downloadQueueRepository.delete({ game: { id: updatedGame!.id } });
|
||||||
await downloadQueueRepository.insert({ game: { id: updatedGame!.id } });
|
await downloadQueueRepository.insert({ game: { id: updatedGame!.id } });
|
||||||
|
@ -15,19 +15,17 @@ export const createGame = async (game: Game) => {
|
|||||||
logger.error("Failed to create game download", err);
|
logger.error("Failed to create game download", err);
|
||||||
});
|
});
|
||||||
|
|
||||||
HydraApi.post(`/profile/games`, {
|
return HydraApi.post(`/profile/games`, {
|
||||||
objectId: game.objectID,
|
objectId: game.objectID,
|
||||||
playTimeInMilliseconds: Math.trunc(game.playTimeInMilliseconds),
|
playTimeInMilliseconds: Math.trunc(game.playTimeInMilliseconds),
|
||||||
shop: game.shop,
|
shop: game.shop,
|
||||||
lastTimePlayed: game.lastTimePlayed,
|
lastTimePlayed: game.lastTimePlayed,
|
||||||
})
|
}).then((response) => {
|
||||||
.then((response) => {
|
|
||||||
const { id: remoteId, playTimeInMilliseconds, lastTimePlayed } = response;
|
const { id: remoteId, playTimeInMilliseconds, lastTimePlayed } = response;
|
||||||
|
|
||||||
gameRepository.update(
|
gameRepository.update(
|
||||||
{ objectID: game.objectID },
|
{ objectID: game.objectID },
|
||||||
{ remoteId, playTimeInMilliseconds, lastTimePlayed }
|
{ remoteId, playTimeInMilliseconds, lastTimePlayed }
|
||||||
);
|
);
|
||||||
})
|
});
|
||||||
.catch(() => {});
|
|
||||||
};
|
};
|
||||||
|
@ -6,8 +6,8 @@ export const updateGamePlaytime = async (
|
|||||||
deltaInMillis: number,
|
deltaInMillis: number,
|
||||||
lastTimePlayed: Date
|
lastTimePlayed: Date
|
||||||
) => {
|
) => {
|
||||||
HydraApi.put(`/profile/games/${game.remoteId}`, {
|
return HydraApi.put(`/profile/games/${game.remoteId}`, {
|
||||||
playTimeDeltaInSeconds: Math.trunc(deltaInMillis / 1000),
|
playTimeDeltaInSeconds: Math.trunc(deltaInMillis / 1000),
|
||||||
lastTimePlayed,
|
lastTimePlayed,
|
||||||
}).catch(() => {});
|
});
|
||||||
};
|
};
|
||||||
|
@ -70,9 +70,9 @@ function onOpenGame(game: Game) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (game.remoteId) {
|
if (game.remoteId) {
|
||||||
updateGamePlaytime(game, 0, new Date());
|
updateGamePlaytime(game, 0, new Date()).catch(() => {});
|
||||||
} else {
|
} else {
|
||||||
createGame({ ...game, lastTimePlayed: new Date() });
|
createGame({ ...game, lastTimePlayed: new Date() }).catch(() => {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,20 +93,22 @@ function onTickGame(game: Game) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (currentTick % TICKS_TO_UPDATE_API === 0) {
|
if (currentTick % TICKS_TO_UPDATE_API === 0) {
|
||||||
if (game.remoteId) {
|
const gamePromise = game.remoteId
|
||||||
updateGamePlaytime(
|
? updateGamePlaytime(
|
||||||
game,
|
game,
|
||||||
now - gamePlaytime.lastSyncTick,
|
now - gamePlaytime.lastSyncTick,
|
||||||
game.lastTimePlayed!
|
game.lastTimePlayed!
|
||||||
);
|
)
|
||||||
} else {
|
: createGame(game);
|
||||||
createGame(game);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
gamePromise
|
||||||
|
.then(() => {
|
||||||
gamesPlaytime.set(game.id, {
|
gamesPlaytime.set(game.id, {
|
||||||
...gamePlaytime,
|
...gamePlaytime,
|
||||||
lastSyncTick: now,
|
lastSyncTick: now,
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,8 +121,8 @@ const onCloseGame = (game: Game) => {
|
|||||||
game,
|
game,
|
||||||
performance.now() - gamePlaytime.firstTick,
|
performance.now() - gamePlaytime.firstTick,
|
||||||
game.lastTimePlayed!
|
game.lastTimePlayed!
|
||||||
);
|
).catch(() => {});
|
||||||
} else {
|
} else {
|
||||||
createGame(game);
|
createGame(game).catch(() => {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user