mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 13:34:54 +03:00
refactor: streamline resetGameAchievements with a single try catch
This commit is contained in:
parent
bfdc2787d4
commit
10766526c5
@ -10,6 +10,7 @@ const resetGameAchievements = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
gameId: number
|
||||
) => {
|
||||
try {
|
||||
const game = await gameRepository.findOne({ where: { id: gameId } });
|
||||
|
||||
if (!game) return;
|
||||
@ -17,15 +18,11 @@ const resetGameAchievements = async (
|
||||
const achievementFiles = findAchievementFiles(game);
|
||||
|
||||
if (achievementFiles.length) {
|
||||
try {
|
||||
await Promise.all(
|
||||
achievementFiles.map(async (achievementFile) => {
|
||||
await fs.promises.rm(achievementFile.filePath, { recursive: true });
|
||||
})
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
await gameAchievementRepository.update(
|
||||
@ -35,11 +32,7 @@ const resetGameAchievements = async (
|
||||
}
|
||||
);
|
||||
|
||||
try {
|
||||
await HydraApi.delete(`/profile/games/${game.remoteId}/achievements`);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
const gameAchievements = await getUnlockedAchievements(
|
||||
game.objectID,
|
||||
@ -51,6 +44,10 @@ const resetGameAchievements = async (
|
||||
`on-update-achievements-${game.objectID}-${game.shop}`,
|
||||
gameAchievements
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
registerEvent("resetGameAchievements", resetGameAchievements);
|
||||
|
Loading…
Reference in New Issue
Block a user