Merge branch 'feat/improving-sources' of github.com:hydralauncher/hydra into feat/improving-sources

This commit is contained in:
Chubby Granny Chaser
2025-10-21 04:22:17 +01:00
5 changed files with 26 additions and 32 deletions

View File

@@ -5,15 +5,18 @@ import { logger } from "../logger";
import { db, gameAchievementsSublevel, levelKeys } from "@main/level";
import { AxiosError } from "axios";
const LOCAL_CACHE_EXPIRATION = 1000 * 60 * 60; // 1 hour
const getModifiedSinceHeader = (
cachedAchievements: GameAchievement | undefined
cachedAchievements: GameAchievement | undefined,
userLanguage: string
): Date | undefined => {
if (!cachedAchievements) {
return undefined;
}
if (userLanguage != cachedAchievements.language) {
return undefined;
}
return cachedAchievements.updatedAt
? new Date(cachedAchievements.updatedAt)
: undefined;
@@ -28,13 +31,7 @@ export const getGameAchievementData = async (
const cachedAchievements = await gameAchievementsSublevel.get(gameKey);
if (cachedAchievements?.achievements && useCachedData)
return cachedAchievements.achievements;
if (
cachedAchievements?.achievements &&
Date.now() < (cachedAchievements.updatedAt ?? 0) + LOCAL_CACHE_EXPIRATION
) {
if (cachedAchievements?.achievements && useCachedData) {
return cachedAchievements.achievements;
}
@@ -50,14 +47,15 @@ export const getGameAchievementData = async (
language,
},
{
ifModifiedSince: getModifiedSinceHeader(cachedAchievements),
ifModifiedSince: getModifiedSinceHeader(cachedAchievements, language),
}
)
.then(async (achievements) => {
await gameAchievementsSublevel.put(gameKey, {
unlockedAchievements: cachedAchievements?.unlockedAchievements ?? [],
achievements,
updatedAt: Date.now() + LOCAL_CACHE_EXPIRATION,
updatedAt: Date.now(),
language,
});
return achievements;

View File

@@ -37,6 +37,7 @@ const saveAchievementsOnLocal = async (
achievements: gameAchievement?.achievements ?? [],
unlockedAchievements: unlockedAchievements,
updatedAt: gameAchievement?.updatedAt,
language: gameAchievement?.language,
});
if (!sendUpdateEvent) return;

View File

@@ -66,10 +66,7 @@ export function UserProfileContextProvider({
const isMe = userDetails?.id === userProfile?.id;
const getHeroBackgroundFromImageUrl = async (imageUrl: string) => {
const output = await average(imageUrl, {
amount: 1,
format: "hex",
});
const output = await average(imageUrl, { amount: 1, format: "hex" });
return `linear-gradient(135deg, ${darkenColor(output as string, 0.5)}, ${darkenColor(output as string, 0.6, 0.5)})`;
};
@@ -135,28 +132,25 @@ export function UserProfileContextProvider({
getUserLibraryGames();
return window.electron.hydraApi
.get<UserProfile | null>(`/users/${userId}`)
.get<UserProfile>(`/users/${userId}`)
.then((userProfile) => {
if (userProfile) {
setUserProfile(userProfile);
setUserProfile(userProfile);
if (userProfile.profileImageUrl) {
getHeroBackgroundFromImageUrl(userProfile.profileImageUrl).then(
(color) => setHeroBackground(color)
);
}
} else {
showErrorToast(t("user_not_found"));
navigate(-1);
if (userProfile.profileImageUrl) {
getHeroBackgroundFromImageUrl(userProfile.profileImageUrl).then(
(color) => setHeroBackground(color)
);
}
})
.catch(() => {
showErrorToast(t("user_not_found"));
navigate(-1);
});
}, [navigate, getUserStats, getUserLibraryGames, showErrorToast, userId, t]);
const getBadges = useCallback(async () => {
const language = i18n.language.split("-")[0];
const params = new URLSearchParams({
locale: language,
});
const params = new URLSearchParams({ locale: language });
const badges = await window.electron.hydraApi.get<Badge[]>(
`/badges?${params.toString()}`,

View File

@@ -83,6 +83,7 @@ export interface GameAchievement {
achievements: SteamAchievement[];
unlockedAchievements: UnlockedAchievement[];
updatedAt: number | undefined;
language: string | undefined;
}
export type AchievementCustomNotificationPosition =

View File

@@ -1047,9 +1047,9 @@
optionalDependencies:
global-agent "^3.0.0"
"@electron/node-gyp@git+https://github.com/electron/node-gyp.git#06b29aafb7708acef8b3669835c8a7857ebc92d2":
"@electron/node-gyp@https://github.com/electron/node-gyp#06b29aafb7708acef8b3669835c8a7857ebc92d2":
version "10.2.0-electron.1"
resolved "git+https://github.com/electron/node-gyp.git#06b29aafb7708acef8b3669835c8a7857ebc92d2"
resolved "https://github.com/electron/node-gyp#06b29aafb7708acef8b3669835c8a7857ebc92d2"
dependencies:
env-paths "^2.2.0"
exponential-backoff "^3.1.1"