feat: ensure playtime is not lost when hydra closes

This commit is contained in:
Zamitto
2025-05-22 13:12:45 -03:00
parent 772aea69a9
commit eab9f92b3e
2 changed files with 23 additions and 3 deletions

View File

@@ -143,9 +143,17 @@ app.on("window-all-closed", () => {
WindowManager.mainWindow = null;
});
app.on("before-quit", () => {
/* Disconnects libtorrent */
PythonRPC.kill();
let canAppBeClose = false;
app.on("before-quit", async (e) => {
if (!canAppBeClose) {
e.preventDefault();
/* Disconnects libtorrent */
PythonRPC.kill();
await clearGamesPlaytime();
canAppBeClose = true;
app.quit();
}
});
app.on("activate", () => {

View File

@@ -340,3 +340,15 @@ const onCloseGame = (game: Game) => {
return createGame(game).catch(() => {});
}
};
export const clearGamesPlaytime = async () => {
for (const game of gamesPlaytime.keys()) {
const gameData = await gamesSublevel.get(game);
if (gameData) {
await onCloseGame(gameData);
}
}
gamesPlaytime.clear();
};