mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-19 01:03:57 +00:00
feat: ensure playtime is not lost when hydra closes
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user