mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: update achievement audio and refactors
This commit is contained in:
parent
084b7f5b9c
commit
c18c41ac95
13 changed files with 99 additions and 55 deletions
|
|
@ -7,23 +7,18 @@ import {
|
|||
userPreferencesRepository,
|
||||
} from "@main/repository";
|
||||
import { UserNotLoggedInError } from "@shared";
|
||||
import { Game } from "@main/entity";
|
||||
|
||||
const getGameAchievements = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
const getAchievementsDataFromApi = async (
|
||||
objectId: string,
|
||||
shop: GameShop
|
||||
): Promise<GameAchievement[]> => {
|
||||
const [game, cachedAchievements, userPreferences] = await Promise.all([
|
||||
gameRepository.findOne({
|
||||
where: { objectID: objectId, shop },
|
||||
}),
|
||||
gameAchievementRepository.findOne({ where: { objectId, shop } }),
|
||||
userPreferencesRepository.findOne({
|
||||
where: { id: 1 },
|
||||
}),
|
||||
]);
|
||||
shop: string,
|
||||
game: Game | null
|
||||
) => {
|
||||
const userPreferences = await userPreferencesRepository.findOne({
|
||||
where: { id: 1 },
|
||||
});
|
||||
|
||||
const apiAchievement = HydraApi.get("/games/achievements", {
|
||||
return HydraApi.get("/games/achievements", {
|
||||
objectId,
|
||||
shop,
|
||||
language: userPreferences?.language || "en",
|
||||
|
|
@ -46,10 +41,23 @@ const getGameAchievements = async (
|
|||
if (err instanceof UserNotLoggedInError) throw err;
|
||||
return [];
|
||||
});
|
||||
};
|
||||
|
||||
const getGameAchievements = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
objectId: string,
|
||||
shop: GameShop
|
||||
): Promise<GameAchievement[]> => {
|
||||
const [game, cachedAchievements] = await Promise.all([
|
||||
gameRepository.findOne({
|
||||
where: { objectID: objectId, shop },
|
||||
}),
|
||||
gameAchievementRepository.findOne({ where: { objectId, shop } }),
|
||||
]);
|
||||
|
||||
const gameAchievements = cachedAchievements?.achievements
|
||||
? JSON.parse(cachedAchievements.achievements)
|
||||
: await apiAchievement;
|
||||
: await getAchievementsDataFromApi(objectId, shop, game);
|
||||
|
||||
const unlockedAchievements = JSON.parse(
|
||||
cachedAchievements?.unlockedAchievements || "[]"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
import { registerEvent } from "../register-event";
|
||||
import { updateLocalUnlockedAchivements } from "@main/services/achievements/update-local-unlocked-achivements";
|
||||
|
||||
const updateGameUnlockedAchievements = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
objectId: string
|
||||
) => {
|
||||
return updateLocalUnlockedAchivements(false, objectId);
|
||||
};
|
||||
|
||||
registerEvent("updateGameUnlockedAchievements", updateGameUnlockedAchievements);
|
||||
|
|
@ -10,6 +10,7 @@ import "./catalogue/search-games";
|
|||
import "./catalogue/get-game-stats";
|
||||
import "./catalogue/get-trending-games";
|
||||
import "./catalogue/get-game-achievements";
|
||||
import "./catalogue/update-game-unlocked-achievements";
|
||||
import "./hardware/get-disk-free-space";
|
||||
import "./library/add-game-to-library";
|
||||
import "./library/create-game-shortcut";
|
||||
|
|
|
|||
|
|
@ -62,29 +62,35 @@ export const mergeAchievements = async (
|
|||
};
|
||||
});
|
||||
|
||||
if (newAchievements.length) {
|
||||
const achievement = newAchievements.at(-1)!;
|
||||
const achievementInfo = JSON.parse(
|
||||
localGameAchievement?.achievements || "[]"
|
||||
).find((steamAchievement) => {
|
||||
return achievement.name === steamAchievement.name;
|
||||
});
|
||||
if (newAchievements.length && publishNotification) {
|
||||
const achievementsInfo = newAchievements
|
||||
.map((achievement) => {
|
||||
return JSON.parse(localGameAchievement?.achievements || "[]").find(
|
||||
(steamAchievement) => {
|
||||
return achievement.name === steamAchievement.name;
|
||||
}
|
||||
);
|
||||
})
|
||||
.filter((achievement) => achievement)
|
||||
.map((achievement) => {
|
||||
return {
|
||||
displayName: achievement.displayName,
|
||||
iconUrl: achievement.icon,
|
||||
};
|
||||
});
|
||||
|
||||
if (publishNotification) {
|
||||
WindowManager.notificationWindow?.webContents.send(
|
||||
"on-achievement-unlocked",
|
||||
objectId,
|
||||
shop,
|
||||
achievementInfo.displayName,
|
||||
achievementInfo.icon
|
||||
);
|
||||
WindowManager.notificationWindow?.webContents.send(
|
||||
"on-achievement-unlocked",
|
||||
objectId,
|
||||
shop,
|
||||
achievementsInfo
|
||||
);
|
||||
|
||||
WindowManager.notificationWindow?.setBounds({ y: 50 });
|
||||
WindowManager.notificationWindow?.setBounds({ y: 50 });
|
||||
|
||||
setTimeout(() => {
|
||||
WindowManager.notificationWindow?.setBounds({ y: -9999 });
|
||||
}, 4000);
|
||||
}
|
||||
setTimeout(() => {
|
||||
WindowManager.notificationWindow?.setBounds({ y: -9999 });
|
||||
}, 4000);
|
||||
}
|
||||
|
||||
const mergedLocalAchievements = unlockedAchievements.concat(newAchievements);
|
||||
|
|
|
|||
|
|
@ -29,12 +29,12 @@ export const watchProcesses = async () => {
|
|||
if (games.length === 0) return;
|
||||
const processes = await PythonInstance.getProcessList();
|
||||
|
||||
const processSet = new Set(processes.map((process) => process.exe));
|
||||
|
||||
for (const game of games) {
|
||||
const executablePath = game.executablePath!;
|
||||
|
||||
const gameProcess = processes.find((runningProcess) => {
|
||||
return executablePath == runningProcess.exe;
|
||||
});
|
||||
const gameProcess = processSet.has(executablePath);
|
||||
|
||||
if (gameProcess) {
|
||||
if (gamesPlaytime.has(game.id)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue