Skip to content

Commit

Permalink
fix: not saving unlocked achievements correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
zamitto committed Feb 3, 2025
1 parent 2c28286 commit 2ed1899
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/main/events/library/add-game-to-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Game, GameShop } from "@types";
import { steamGamesWorker } from "@main/workers";
import { createGame } from "@main/services/library-sync";
import { steamUrlBuilder } from "@shared";
import { updateLocalUnlockedAchivements } from "@main/services/achievements/update-local-unlocked-achivements";
import { updateLocalUnlockedAchievements } from "@main/services/achievements/update-local-unlocked-achivements";
import { downloadsSublevel, gamesSublevel, levelKeys } from "@main/level";

const addGameToLibrary = async (
Expand Down Expand Up @@ -46,9 +46,9 @@ const addGameToLibrary = async (

await gamesSublevel.put(levelKeys.game(shop, objectId), game);

updateLocalUnlockedAchivements(game);
await createGame(game).catch(() => {});

createGame(game).catch(() => {});
updateLocalUnlockedAchievements(game);
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/main/events/user/get-unlocked-achievements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const getUnlockedAchievements = async (

return achievementsData
.map((achievementData) => {
const unlockedAchiementData = unlockedAchievements.find(
const unlockedAchievementData = unlockedAchievements.find(
(localAchievement) => {
return (
localAchievement.name.toUpperCase() ==
Expand All @@ -45,11 +45,11 @@ export const getUnlockedAchievements = async (
? achievementData.icon
: achievementData.icongray;

if (unlockedAchiementData) {
if (unlockedAchievementData) {
return {
...achievementData,
unlocked: true,
unlockTime: unlockedAchiementData.unlockTime,
unlockTime: unlockedAchievementData.unlockTime,
};
}

Expand Down
30 changes: 14 additions & 16 deletions src/main/services/achievements/merge-achievements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,21 @@ const saveAchievementsOnLocal = async (
return gameAchievementsSublevel
.get(levelKey)
.then(async (gameAchievement) => {
if (gameAchievement) {
await gameAchievementsSublevel.put(levelKey, {
...gameAchievement,
unlockedAchievements: unlockedAchievements,
});
await gameAchievementsSublevel.put(levelKey, {
achievements: gameAchievement?.achievements ?? [],
unlockedAchievements: unlockedAchievements,
});

if (!sendUpdateEvent) return;
if (!sendUpdateEvent) return;

return getUnlockedAchievements(objectId, shop, true)
.then((achievements) => {
WindowManager.mainWindow?.webContents.send(
`on-update-achievements-${objectId}-${shop}`,
achievements
);
})
.catch(() => {});
}
return getUnlockedAchievements(objectId, shop, true)
.then((achievements) => {
WindowManager.mainWindow?.webContents.send(
`on-update-achievements-${objectId}-${shop}`,
achievements
);
})
.catch(() => {});
});
};

Expand Down Expand Up @@ -133,7 +131,7 @@ export const mergeAchievements = async (
);
})
.catch((err) => {
if (err! instanceof SubscriptionRequiredError) {
if (err instanceof SubscriptionRequiredError) {
achievementsLogger.log(
"Achievements not synchronized on API due to lack of subscription",
game.objectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { parseAchievementFile } from "./parse-achievement-file";
import { mergeAchievements } from "./merge-achievements";
import type { Game, UnlockedAchievement } from "@types";

export const updateLocalUnlockedAchivements = async (game: Game) => {
export const updateLocalUnlockedAchievements = async (game: Game) => {
const gameAchievementFiles = findAchievementFiles(game);

const achievementFileInsideDirectory =
Expand Down
4 changes: 2 additions & 2 deletions src/main/services/library-sync/merge-with-remote-games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const mergeWithRemoteGames = async () => {
? game.playTimeInMilliseconds
: localGame.playTimeInMilliseconds;

gamesSublevel.put(levelKeys.game(game.shop, game.objectId), {
await gamesSublevel.put(levelKeys.game(game.shop, game.objectId), {
...localGame,
remoteId: game.id,
lastTimePlayed: updatedLastTimePlayed,
Expand All @@ -39,7 +39,7 @@ export const mergeWithRemoteGames = async () => {
? steamUrlBuilder.icon(game.objectId, steamGame.clientIcon)
: null;

gamesSublevel.put(levelKeys.game(game.shop, game.objectId), {
await gamesSublevel.put(levelKeys.game(game.shop, game.objectId), {
objectId: game.objectId,
title: steamGame?.name,
remoteId: game.id,
Expand Down

0 comments on commit 2ed1899

Please sign in to comment.