feat: update achievement audio and refactors

This commit is contained in:
Zamitto
2024-10-01 18:29:50 -03:00
parent 084b7f5b9c
commit c18c41ac95
13 changed files with 99 additions and 55 deletions

View File

@@ -7,23 +7,18 @@ import {
userPreferencesRepository,
} from "@main/repository";
import { UserNotLoggedInError } from "@shared";
import { Game } from "@main/entity";
const getGameAchievements = async (
_event: Electron.IpcMainInvokeEvent,
const getAchievementsDataFromApi = async (
objectId: string,
shop: GameShop
): Promise<GameAchievement[]> => {
const [game, cachedAchievements, userPreferences] = await Promise.all([
gameRepository.findOne({
where: { objectID: objectId, shop },
}),
gameAchievementRepository.findOne({ where: { objectId, shop } }),
userPreferencesRepository.findOne({
where: { id: 1 },
}),
]);
shop: string,
game: Game | null
) => {
const userPreferences = await userPreferencesRepository.findOne({
where: { id: 1 },
});
const apiAchievement = HydraApi.get("/games/achievements", {
return HydraApi.get("/games/achievements", {
objectId,
shop,
language: userPreferences?.language || "en",
@@ -46,10 +41,23 @@ const getGameAchievements = async (
if (err instanceof UserNotLoggedInError) throw err;
return [];
});
};
const getGameAchievements = async (
_event: Electron.IpcMainInvokeEvent,
objectId: string,
shop: GameShop
): Promise<GameAchievement[]> => {
const [game, cachedAchievements] = await Promise.all([
gameRepository.findOne({
where: { objectID: objectId, shop },
}),
gameAchievementRepository.findOne({ where: { objectId, shop } }),
]);
const gameAchievements = cachedAchievements?.achievements
? JSON.parse(cachedAchievements.achievements)
: await apiAchievement;
: await getAchievementsDataFromApi(objectId, shop, game);
const unlockedAchievements = JSON.parse(
cachedAchievements?.unlockedAchievements || "[]"

View File

@@ -0,0 +1,11 @@
import { registerEvent } from "../register-event";
import { updateLocalUnlockedAchivements } from "@main/services/achievements/update-local-unlocked-achivements";
const updateGameUnlockedAchievements = async (
_event: Electron.IpcMainInvokeEvent,
objectId: string
) => {
return updateLocalUnlockedAchivements(false, objectId);
};
registerEvent("updateGameUnlockedAchievements", updateGameUnlockedAchievements);

View File

@@ -10,6 +10,7 @@ import "./catalogue/search-games";
import "./catalogue/get-game-stats";
import "./catalogue/get-trending-games";
import "./catalogue/get-game-achievements";
import "./catalogue/update-game-unlocked-achievements";
import "./hardware/get-disk-free-space";
import "./library/add-game-to-library";
import "./library/create-game-shortcut";