feat: refactor

This commit is contained in:
Zamitto 2024-10-21 04:40:04 -03:00
parent 27e8a0820f
commit 0bcf005365
3 changed files with 13 additions and 30 deletions

View file

@ -135,12 +135,7 @@ const processAchievementFileDiff = async (
const unlockedAchievements = parseAchievementFile(file.filePath, file.type);
if (unlockedAchievements.length) {
return mergeAchievements(
game.objectID,
game.shop,
unlockedAchievements,
true
);
return mergeAchievements(game, unlockedAchievements, true);
}
};
@ -187,12 +182,7 @@ export class AchievementWatcherManager {
}
}
return mergeAchievements(
game.objectID,
"steam",
unlockedAchievements,
false
);
return mergeAchievements(game, unlockedAchievements, false);
};
private static preSearchAchievementsWindows = async () => {

View file

@ -1,12 +1,12 @@
import {
gameAchievementRepository,
gameRepository,
userPreferencesRepository,
} from "@main/repository";
import type { AchievementData, GameShop, UnlockedAchievement } from "@types";
import { WindowManager } from "../window-manager";
import { HydraApi } from "../hydra-api";
import { getUnlockedAchievements } from "@main/events/user/get-unlocked-achievements";
import { Game } from "@main/entity";
const saveAchievementsOnLocal = async (
objectId: string,
@ -38,22 +38,15 @@ const saveAchievementsOnLocal = async (
};
export const mergeAchievements = async (
objectId: string,
shop: GameShop,
game: Game,
achievements: UnlockedAchievement[],
publishNotification: boolean
) => {
const game = await gameRepository.findOne({
where: { objectID: objectId, shop: shop },
});
if (!game) return;
const [localGameAchievement, userPreferences] = await Promise.all([
gameAchievementRepository.findOne({
where: {
objectId,
shop,
objectId: game.objectID,
shop: game.shop,
},
}),
userPreferencesRepository.findOne({ where: { id: 1 } }),
@ -115,8 +108,8 @@ export const mergeAchievements = async (
WindowManager.notificationWindow?.webContents.send(
"on-achievement-unlocked",
objectId,
shop,
game.objectID,
game.shop,
achievementsInfo
);
}
@ -142,8 +135,8 @@ export const mergeAchievements = async (
})
.catch(() => {
return saveAchievementsOnLocal(
objectId,
shop,
game.objectID,
game.shop,
mergedLocalAchievements,
publishNotification
);
@ -151,8 +144,8 @@ export const mergeAchievements = async (
}
return saveAchievementsOnLocal(
objectId,
shop,
game.objectID,
game.shop,
mergedLocalAchievements,
publishNotification
);

View file

@ -28,5 +28,5 @@ export const updateLocalUnlockedAchivements = async (game: Game) => {
}
}
mergeAchievements(game.objectID, "steam", unlockedAchievements, false);
mergeAchievements(game, unlockedAchievements, false);
};