mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-22 18:33:56 +00:00
feat: update achievement audio and refactors
This commit is contained in:
@@ -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 || "[]"
|
||||
|
||||
@@ -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);
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user