mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-14 20:22:10 +00:00
feat: refactor
This commit is contained in:
parent
27e8a0820f
commit
0bcf005365
3 changed files with 13 additions and 30 deletions
|
@ -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 () => {
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
|
|
@ -28,5 +28,5 @@ export const updateLocalUnlockedAchivements = async (game: Game) => {
|
|||
}
|
||||
}
|
||||
|
||||
mergeAchievements(game.objectID, "steam", unlockedAchievements, false);
|
||||
mergeAchievements(game, unlockedAchievements, false);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue