diff --git a/src/main/events/notifications/update-achievement-notification-window.ts b/src/main/events/notifications/update-achievement-notification-window.ts index 48fba272..02dd45b1 100644 --- a/src/main/events/notifications/update-achievement-notification-window.ts +++ b/src/main/events/notifications/update-achievement-notification-window.ts @@ -16,7 +16,7 @@ const updateAchievementCustomNotificationWindow = async ( WindowManager.closeNotificationWindow(); if ( - userPreferences.achievementNotificationsEnabled && + userPreferences.achievementNotificationsEnabled !== false && userPreferences.achievementCustomNotificationsEnabled !== false ) { WindowManager.createNotificationWindow(); diff --git a/src/main/services/achievements/achievement-watcher-manager.ts b/src/main/services/achievements/achievement-watcher-manager.ts index c010f984..5cf09d4f 100644 --- a/src/main/services/achievements/achievement-watcher-manager.ts +++ b/src/main/services/achievements/achievement-watcher-manager.ts @@ -274,7 +274,7 @@ export class AchievementWatcherManager { } ); - if (userPreferences.achievementNotificationsEnabled) { + if (userPreferences.achievementNotificationsEnabled !== false) { if (userPreferences.achievementCustomNotificationsEnabled !== false) { WindowManager.notificationWindow?.webContents.send( "on-combined-achievements-unlocked", diff --git a/src/main/services/achievements/merge-achievements.ts b/src/main/services/achievements/merge-achievements.ts index 6b40ad72..2674e451 100644 --- a/src/main/services/achievements/merge-achievements.ts +++ b/src/main/services/achievements/merge-achievements.ts @@ -13,6 +13,7 @@ import { publishNewAchievementNotification } from "../notifications"; import { SubscriptionRequiredError } from "@shared"; import { achievementsLogger } from "../logger"; import { db, gameAchievementsSublevel, levelKeys } from "@main/level"; +import { getGameAchievementData } from "./get-game-achievement-data"; const isRareAchievement = (points: number) => { const rawPercentage = (50 - Math.sqrt(points)) * 2; @@ -55,12 +56,22 @@ export const mergeAchievements = async ( achievements: UnlockedAchievement[], publishNotification: boolean ) => { - const [localGameAchievement, userPreferences] = await Promise.all([ - gameAchievementsSublevel.get(levelKeys.game(game.shop, game.objectId)), - db.get(levelKeys.userPreferences, { + let localGameAchievement = await gameAchievementsSublevel.get( + levelKeys.game(game.shop, game.objectId) + ); + const userPreferences = await db.get( + levelKeys.userPreferences, + { valueEncoding: "json", - }), - ]); + } + ); + + if (!localGameAchievement) { + await getGameAchievementData(game.objectId, game.shop, true); + localGameAchievement = await gameAchievementsSublevel.get( + levelKeys.game(game.shop, game.objectId) + ); + } const achievementsData = localGameAchievement?.achievements ?? []; const unlockedAchievements = localGameAchievement?.unlockedAchievements ?? []; @@ -91,7 +102,7 @@ export const mergeAchievements = async ( if ( newAchievements.length && publishNotification && - userPreferences?.achievementNotificationsEnabled + userPreferences.achievementNotificationsEnabled !== false ) { const filteredAchievements = newAchievements .toSorted((a, b) => { @@ -125,7 +136,7 @@ export const mergeAchievements = async ( }; }); - if (userPreferences?.achievementCustomNotificationsEnabled !== false) { + if (userPreferences.achievementCustomNotificationsEnabled !== false) { WindowManager.notificationWindow?.webContents.send( "on-achievement-unlocked", userPreferences.achievementCustomNotificationPosition ?? "top-left", diff --git a/src/main/services/hydra-api.ts b/src/main/services/hydra-api.ts index 122960c7..0f5a4d21 100644 --- a/src/main/services/hydra-api.ts +++ b/src/main/services/hydra-api.ts @@ -42,7 +42,7 @@ export class HydraApi { subscription: null, }; - private static isLoggedIn() { + public static isLoggedIn() { return this.userAuth.authToken !== ""; } diff --git a/src/main/services/library-sync/upload-games-batch.ts b/src/main/services/library-sync/upload-games-batch.ts index 3593ac11..4294e389 100644 --- a/src/main/services/library-sync/upload-games-batch.ts +++ b/src/main/services/library-sync/upload-games-batch.ts @@ -33,7 +33,9 @@ export const uploadGamesBatch = async () => { await mergeWithRemoteGames(); - AchievementWatcherManager.preSearchAchievements(); + if (HydraApi.isLoggedIn()) { + AchievementWatcherManager.preSearchAchievements(); + } if (WindowManager.mainWindow) WindowManager.mainWindow.webContents.send("on-library-batch-complete"); diff --git a/src/main/services/window-manager.ts b/src/main/services/window-manager.ts index 0c58c867..7c789bf9 100644 --- a/src/main/services/window-manager.ts +++ b/src/main/services/window-manager.ts @@ -333,14 +333,22 @@ export class WindowManager { public static async createNotificationWindow() { if (this.notificationWindow) return; - const userPreferences = await db.get( + const userPreferences = await db.get( levelKeys.userPreferences, { valueEncoding: "json", } ); + + if ( + userPreferences?.achievementNotificationsEnabled === false || + userPreferences?.achievementCustomNotificationsEnabled === false + ) { + return; + } + const { x, y } = await this.getNotificationWindowPosition( - userPreferences.achievementCustomNotificationPosition + userPreferences?.achievementCustomNotificationPosition ); this.notificationWindow = new BrowserWindow({ diff --git a/src/renderer/src/pages/achievements/notification/achievement-notification.tsx b/src/renderer/src/pages/achievements/notification/achievement-notification.tsx index ffc223c4..0d99e37c 100644 --- a/src/renderer/src/pages/achievements/notification/achievement-notification.tsx +++ b/src/renderer/src/pages/achievements/notification/achievement-notification.tsx @@ -135,7 +135,6 @@ export function AchievementNotification() { useEffect(() => { const loadAndApplyTheme = async () => { const activeTheme = await window.electron.getActiveCustomTheme(); - console.log("activeTheme", activeTheme); if (activeTheme?.code) { injectCustomCss(activeTheme.code); } diff --git a/src/renderer/src/pages/settings/settings-general.tsx b/src/renderer/src/pages/settings/settings-general.tsx index aa46a519..ad4f1b82 100644 --- a/src/renderer/src/pages/settings/settings-general.tsx +++ b/src/renderer/src/pages/settings/settings-general.tsx @@ -38,7 +38,7 @@ export function SettingsGeneral() { downloadNotificationsEnabled: false, repackUpdatesNotificationsEnabled: false, friendRequestNotificationsEnabled: false, - achievementNotificationsEnabled: false, + achievementNotificationsEnabled: true, achievementCustomNotificationsEnabled: true, achievementCustomNotificationPosition: "top-left" as AchievementCustomNotificationPosition, @@ -104,7 +104,7 @@ export function SettingsGeneral() { repackUpdatesNotificationsEnabled: userPreferences.repackUpdatesNotificationsEnabled ?? false, achievementNotificationsEnabled: - userPreferences.achievementNotificationsEnabled ?? false, + userPreferences.achievementNotificationsEnabled ?? true, achievementCustomNotificationsEnabled: userPreferences.achievementCustomNotificationsEnabled ?? true, achievementCustomNotificationPosition: