mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-26 12:21:03 +00:00
feat: notifications
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
import { gameAchievementRepository } from "@main/repository";
|
||||
import { gameAchievementRepository, gameRepository } from "@main/repository";
|
||||
import { UnlockedAchievement } from "./types";
|
||||
import { publishNewAchievementNotification } from "../notifications";
|
||||
import { GameShop } from "@types";
|
||||
|
||||
export const mergeAchievements = async (
|
||||
objectId: string,
|
||||
shop: string,
|
||||
achievements: UnlockedAchievement[]
|
||||
) => {
|
||||
const game = await gameRepository.findOne({
|
||||
where: { objectID: objectId, shop: shop as GameShop },
|
||||
});
|
||||
|
||||
const localGameAchievement = await gameAchievementRepository.findOne({
|
||||
where: {
|
||||
objectId,
|
||||
@@ -17,16 +23,30 @@ export const mergeAchievements = async (
|
||||
localGameAchievement?.unlockedAchievements || "[]"
|
||||
);
|
||||
|
||||
console.log("file achievemets:", achievements);
|
||||
const newAchievements = achievements.filter((achievement) => {
|
||||
return !unlockedAchievements.some((localAchievement) => {
|
||||
return localAchievement.name === achievement.name;
|
||||
});
|
||||
});
|
||||
|
||||
for (const achievement of newAchievements) {
|
||||
const completeAchievement = JSON.parse(
|
||||
localGameAchievement?.achievements || "[]"
|
||||
).find((steamAchievement) => {
|
||||
return achievement.name === steamAchievement.name;
|
||||
});
|
||||
|
||||
if (completeAchievement) {
|
||||
publishNewAchievementNotification(
|
||||
game?.title || " ",
|
||||
completeAchievement.displayName,
|
||||
completeAchievement.icon
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mergedAchievements = unlockedAchievements.concat(newAchievements);
|
||||
|
||||
console.log("merged achievemetns", mergedAchievements);
|
||||
gameAchievementRepository.upsert(
|
||||
{
|
||||
objectId,
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { gameAchievementRepository, gameRepository } from "@main/repository";
|
||||
import {
|
||||
gameAchievementRepository,
|
||||
gameRepository,
|
||||
userPreferencesRepository,
|
||||
} from "@main/repository";
|
||||
import { steamFindGameAchievementFiles } from "./steam/steam-find-game-achivement-files";
|
||||
import { parseAchievementFile } from "./util/parseAchievementFile";
|
||||
import { HydraApi } from "@main/services";
|
||||
@@ -7,6 +11,10 @@ import { mergeAchievements } from "./merge-achievements";
|
||||
import { UnlockedAchievement } from "./types";
|
||||
|
||||
export const saveAllLocalSteamAchivements = async () => {
|
||||
const userPreferences = await userPreferencesRepository.findOne({
|
||||
where: { id: 1 },
|
||||
});
|
||||
|
||||
const gameAchievementFiles = steamFindGameAchievementFiles();
|
||||
|
||||
for (const objectId of Object.keys(gameAchievementFiles)) {
|
||||
@@ -22,11 +30,12 @@ export const saveAllLocalSteamAchivements = async () => {
|
||||
if (!game) continue;
|
||||
|
||||
if (!localAchievements || !localAchievements.achievements) {
|
||||
HydraApi.get(
|
||||
await HydraApi.get(
|
||||
"/games/achievements",
|
||||
{
|
||||
shop: "steam",
|
||||
objectId,
|
||||
language: userPreferences?.language || "en",
|
||||
},
|
||||
{ needsAuth: false }
|
||||
)
|
||||
@@ -50,11 +59,14 @@ export const saveAllLocalSteamAchivements = async () => {
|
||||
achievementFile.filePath
|
||||
);
|
||||
|
||||
console.log(achievementFile.filePath);
|
||||
|
||||
unlockedAchievements.push(
|
||||
...checkUnlockedAchievements(achievementFile.type, localAchievementFile)
|
||||
);
|
||||
if (localAchievementFile) {
|
||||
unlockedAchievements.push(
|
||||
...checkUnlockedAchievements(
|
||||
achievementFile.type,
|
||||
localAchievementFile
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mergeAchievements(objectId, "steam", unlockedAchievements);
|
||||
|
||||
Reference in New Issue
Block a user