mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-24 03:11:03 +00:00
feat: remove notification spam
This commit is contained in:
@@ -25,7 +25,7 @@ const processAchievementFile = async (game: Game, file: AchievementFile) => {
|
||||
console.log(unlockedAchievements);
|
||||
|
||||
if (unlockedAchievements.length) {
|
||||
mergeAchievements(game.objectID, game.shop, unlockedAchievements);
|
||||
mergeAchievements(game.objectID, game.shop, unlockedAchievements, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
21
src/main/services/achievements/get-game-achievement-data.ts
Normal file
21
src/main/services/achievements/get-game-achievement-data.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { userPreferencesRepository } from "@main/repository";
|
||||
import { HydraApi } from "../hydra-api";
|
||||
|
||||
export const getGameAchievementData = async (
|
||||
objectId: string,
|
||||
shop: string
|
||||
) => {
|
||||
const userPreferences = await userPreferencesRepository.findOne({
|
||||
where: { id: 1 },
|
||||
});
|
||||
|
||||
return HydraApi.get(
|
||||
"/games/achievements",
|
||||
{
|
||||
shop,
|
||||
objectId,
|
||||
language: userPreferences?.language || "en",
|
||||
},
|
||||
{ needsAuth: false }
|
||||
);
|
||||
};
|
||||
@@ -22,12 +22,15 @@ const saveAchievementsOnLocal = async (
|
||||
export const mergeAchievements = async (
|
||||
objectId: string,
|
||||
shop: string,
|
||||
achievements: UnlockedAchievement[]
|
||||
achievements: UnlockedAchievement[],
|
||||
publishNotification: boolean
|
||||
) => {
|
||||
const game = await gameRepository.findOne({
|
||||
where: { objectID: objectId, shop: shop as GameShop },
|
||||
});
|
||||
|
||||
if (!game) return;
|
||||
|
||||
const localGameAchievement = await gameAchievementRepository.findOne({
|
||||
where: {
|
||||
objectId,
|
||||
@@ -53,20 +56,20 @@ export const mergeAchievements = async (
|
||||
);
|
||||
}
|
||||
|
||||
for (const achievement of newAchievements.slice(0, 3)) {
|
||||
const completeAchievement = JSON.parse(
|
||||
if (newAchievements.length > 0 && publishNotification) {
|
||||
const achievement = newAchievements.pop()!;
|
||||
const achievementInfo = JSON.parse(
|
||||
localGameAchievement?.achievements || "[]"
|
||||
).find((steamAchievement) => {
|
||||
return achievement.name === steamAchievement.name;
|
||||
});
|
||||
|
||||
if (completeAchievement) {
|
||||
publishNewAchievementNotification(
|
||||
game?.title || " ",
|
||||
completeAchievement.displayName,
|
||||
completeAchievement.icon
|
||||
);
|
||||
}
|
||||
publishNewAchievementNotification(
|
||||
game.title ?? "",
|
||||
achievementInfo.displayName,
|
||||
achievementInfo.icon,
|
||||
newAchievements.length
|
||||
);
|
||||
}
|
||||
|
||||
const mergedLocalAchievements = unlockedAchievements.concat(newAchievements);
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
import {
|
||||
gameAchievementRepository,
|
||||
gameRepository,
|
||||
userPreferencesRepository,
|
||||
} from "@main/repository";
|
||||
import { gameAchievementRepository, gameRepository } from "@main/repository";
|
||||
import { findSteamGameAchievementFiles } from "./find-steam-game-achivement-files";
|
||||
import { parseAchievementFile } from "./parse-achievement-file";
|
||||
import { HydraApi } from "@main/services";
|
||||
import { checkUnlockedAchievements } from "./check-unlocked-achievements";
|
||||
import { mergeAchievements } from "./merge-achievements";
|
||||
import type { UnlockedAchievement } from "@types";
|
||||
import { getGameAchievementData } from "./get-game-achievement-data";
|
||||
|
||||
export const saveAllLocalSteamAchivements = async () => {
|
||||
const userPreferences = await userPreferencesRepository.findOne({
|
||||
where: { id: 1 },
|
||||
});
|
||||
|
||||
const gameAchievementFiles = findSteamGameAchievementFiles();
|
||||
export const updateLocalUnlockedAchivements = async (
|
||||
publishNotification: boolean,
|
||||
objectId?: string
|
||||
) => {
|
||||
const gameAchievementFiles = findSteamGameAchievementFiles(objectId);
|
||||
|
||||
for (const objectId of gameAchievementFiles.keys()) {
|
||||
const [game, localAchievements] = await Promise.all([
|
||||
@@ -36,15 +31,7 @@ export const saveAllLocalSteamAchivements = async () => {
|
||||
);
|
||||
|
||||
if (!localAchievements || !localAchievements.achievements) {
|
||||
await HydraApi.get(
|
||||
"/games/achievements",
|
||||
{
|
||||
shop: "steam",
|
||||
objectId,
|
||||
language: userPreferences?.language || "en",
|
||||
},
|
||||
{ needsAuth: false }
|
||||
)
|
||||
await getGameAchievementData(objectId, "steam")
|
||||
.then((achievements) => {
|
||||
return gameAchievementRepository.upsert(
|
||||
{
|
||||
@@ -75,6 +62,11 @@ export const saveAllLocalSteamAchivements = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
mergeAchievements(objectId, "steam", unlockedAchievements);
|
||||
mergeAchievements(
|
||||
objectId,
|
||||
"steam",
|
||||
unlockedAchievements,
|
||||
publishNotification
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user