Merge branch 'feature/profile-redesign' of github.com:hydralauncher/hydra into feature/profile-redesign

This commit is contained in:
Chubby Granny Chaser 2024-09-14 02:33:40 +01:00
commit 14b204b1c3
No known key found for this signature in database
8 changed files with 59 additions and 38 deletions

View File

@ -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(() => {});
}); });
}; };

View File

@ -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 } });

View File

@ -2,12 +2,13 @@ import knex, { Knex } from "knex";
import { databasePath } from "./constants"; import { databasePath } from "./constants";
import { Hydra2_0_3 } from "./migrations/20240830143811_Hydra_2_0_3"; import { Hydra2_0_3 } from "./migrations/20240830143811_Hydra_2_0_3";
import { RepackUris } from "./migrations/20240830143906_RepackUris"; import { RepackUris } from "./migrations/20240830143906_RepackUris";
import { UpdateUserLanguage } from "./migrations/20240913213944_update_user_language";
export type HydraMigration = Knex.Migration & { name: string }; export type HydraMigration = Knex.Migration & { name: string };
class MigrationSource implements Knex.MigrationSource<HydraMigration> { class MigrationSource implements Knex.MigrationSource<HydraMigration> {
getMigrations(): Promise<HydraMigration[]> { getMigrations(): Promise<HydraMigration[]> {
return Promise.resolve([Hydra2_0_3, RepackUris]); return Promise.resolve([Hydra2_0_3, RepackUris, UpdateUserLanguage]);
} }
getMigrationName(migration: HydraMigration): string { getMigrationName(migration: HydraMigration): string {
return migration.name; return migration.name;

View File

@ -0,0 +1,13 @@
import type { HydraMigration } from "@main/knex-client";
import type { Knex } from "knex";
export const UpdateUserLanguage: HydraMigration = {
name: "UpdateUserLanguage",
up: async (knex: Knex) => {
await knex("user_preferences")
.update("language", "pt-BR")
.where("language", "pt");
},
down: async (_knex: Knex) => {},
};

View File

@ -4,26 +4,28 @@ import { gameRepository } from "@main/repository";
import { logger } from "../logger"; import { logger } from "../logger";
export const createGame = async (game: Game) => { export const createGame = async (game: Game) => {
HydraApi.post("/games/download", { HydraApi.post(
objectId: game.objectID, "/games/download",
shop: game.shop, {
}).catch((err) => { objectId: game.objectID,
shop: game.shop,
},
{ needsAuth: false }
).catch((err) => {
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(() => {});
}; };

View File

@ -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(() => {}); });
}; };

View File

@ -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);
}
gamesPlaytime.set(game.id, { gamePromise
...gamePlaytime, .then(() => {
lastSyncTick: now, gamesPlaytime.set(game.id, {
}); ...gamePlaytime,
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(() => {});
} }
}; };

View File

@ -41,8 +41,11 @@ i18n
escapeValue: false, escapeValue: false,
}, },
}) })
.then(() => { .then(async () => {
window.electron.updateUserPreferences({ language: i18n.language }); const userPreferences = await window.electron.getUserPreferences();
if (!userPreferences?.language) {
window.electron.updateUserPreferences({ language: i18n.language });
}
}); });
ReactDOM.createRoot(document.getElementById("root")!).render( ReactDOM.createRoot(document.getElementById("root")!).render(