mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +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);
|
const unlockedAchievements = parseAchievementFile(file.filePath, file.type);
|
||||||
|
|
||||||
if (unlockedAchievements.length) {
|
if (unlockedAchievements.length) {
|
||||||
return mergeAchievements(
|
return mergeAchievements(game, unlockedAchievements, true);
|
||||||
game.objectID,
|
|
||||||
game.shop,
|
|
||||||
unlockedAchievements,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -187,12 +182,7 @@ export class AchievementWatcherManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mergeAchievements(
|
return mergeAchievements(game, unlockedAchievements, false);
|
||||||
game.objectID,
|
|
||||||
"steam",
|
|
||||||
unlockedAchievements,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private static preSearchAchievementsWindows = async () => {
|
private static preSearchAchievementsWindows = async () => {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import {
|
import {
|
||||||
gameAchievementRepository,
|
gameAchievementRepository,
|
||||||
gameRepository,
|
|
||||||
userPreferencesRepository,
|
userPreferencesRepository,
|
||||||
} from "@main/repository";
|
} from "@main/repository";
|
||||||
import type { AchievementData, GameShop, UnlockedAchievement } from "@types";
|
import type { AchievementData, GameShop, UnlockedAchievement } from "@types";
|
||||||
import { WindowManager } from "../window-manager";
|
import { WindowManager } from "../window-manager";
|
||||||
import { HydraApi } from "../hydra-api";
|
import { HydraApi } from "../hydra-api";
|
||||||
import { getUnlockedAchievements } from "@main/events/user/get-unlocked-achievements";
|
import { getUnlockedAchievements } from "@main/events/user/get-unlocked-achievements";
|
||||||
|
import { Game } from "@main/entity";
|
||||||
|
|
||||||
const saveAchievementsOnLocal = async (
|
const saveAchievementsOnLocal = async (
|
||||||
objectId: string,
|
objectId: string,
|
||||||
|
@ -38,22 +38,15 @@ const saveAchievementsOnLocal = async (
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mergeAchievements = async (
|
export const mergeAchievements = async (
|
||||||
objectId: string,
|
game: Game,
|
||||||
shop: GameShop,
|
|
||||||
achievements: UnlockedAchievement[],
|
achievements: UnlockedAchievement[],
|
||||||
publishNotification: boolean
|
publishNotification: boolean
|
||||||
) => {
|
) => {
|
||||||
const game = await gameRepository.findOne({
|
|
||||||
where: { objectID: objectId, shop: shop },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!game) return;
|
|
||||||
|
|
||||||
const [localGameAchievement, userPreferences] = await Promise.all([
|
const [localGameAchievement, userPreferences] = await Promise.all([
|
||||||
gameAchievementRepository.findOne({
|
gameAchievementRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
objectId,
|
objectId: game.objectID,
|
||||||
shop,
|
shop: game.shop,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
userPreferencesRepository.findOne({ where: { id: 1 } }),
|
userPreferencesRepository.findOne({ where: { id: 1 } }),
|
||||||
|
@ -115,8 +108,8 @@ export const mergeAchievements = async (
|
||||||
|
|
||||||
WindowManager.notificationWindow?.webContents.send(
|
WindowManager.notificationWindow?.webContents.send(
|
||||||
"on-achievement-unlocked",
|
"on-achievement-unlocked",
|
||||||
objectId,
|
game.objectID,
|
||||||
shop,
|
game.shop,
|
||||||
achievementsInfo
|
achievementsInfo
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -142,8 +135,8 @@ export const mergeAchievements = async (
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
return saveAchievementsOnLocal(
|
return saveAchievementsOnLocal(
|
||||||
objectId,
|
game.objectID,
|
||||||
shop,
|
game.shop,
|
||||||
mergedLocalAchievements,
|
mergedLocalAchievements,
|
||||||
publishNotification
|
publishNotification
|
||||||
);
|
);
|
||||||
|
@ -151,8 +144,8 @@ export const mergeAchievements = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
return saveAchievementsOnLocal(
|
return saveAchievementsOnLocal(
|
||||||
objectId,
|
game.objectID,
|
||||||
shop,
|
game.shop,
|
||||||
mergedLocalAchievements,
|
mergedLocalAchievements,
|
||||||
publishNotification
|
publishNotification
|
||||||
);
|
);
|
||||||
|
|
|
@ -28,5 +28,5 @@ export const updateLocalUnlockedAchivements = async (game: Game) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeAchievements(game.objectID, "steam", unlockedAchievements, false);
|
mergeAchievements(game, unlockedAchievements, false);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue