Skip to content

Commit a5aabe0

Browse files
committed
fix: notifications not working on first run
1 parent 276c098 commit a5aabe0

File tree

8 files changed

+36
-16
lines changed

8 files changed

+36
-16
lines changed

src/main/events/notifications/update-achievement-notification-window.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const updateAchievementCustomNotificationWindow = async (
1616
WindowManager.closeNotificationWindow();
1717

1818
if (
19-
userPreferences.achievementNotificationsEnabled &&
19+
userPreferences.achievementNotificationsEnabled !== false &&
2020
userPreferences.achievementCustomNotificationsEnabled !== false
2121
) {
2222
WindowManager.createNotificationWindow();

src/main/services/achievements/achievement-watcher-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class AchievementWatcherManager {
274274
}
275275
);
276276

277-
if (userPreferences.achievementNotificationsEnabled) {
277+
if (userPreferences.achievementNotificationsEnabled !== false) {
278278
if (userPreferences.achievementCustomNotificationsEnabled !== false) {
279279
WindowManager.notificationWindow?.webContents.send(
280280
"on-combined-achievements-unlocked",

src/main/services/achievements/merge-achievements.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { publishNewAchievementNotification } from "../notifications";
1313
import { SubscriptionRequiredError } from "@shared";
1414
import { achievementsLogger } from "../logger";
1515
import { db, gameAchievementsSublevel, levelKeys } from "@main/level";
16+
import { getGameAchievementData } from "./get-game-achievement-data";
1617

1718
const isRareAchievement = (points: number) => {
1819
const rawPercentage = (50 - Math.sqrt(points)) * 2;
@@ -55,12 +56,22 @@ export const mergeAchievements = async (
5556
achievements: UnlockedAchievement[],
5657
publishNotification: boolean
5758
) => {
58-
const [localGameAchievement, userPreferences] = await Promise.all([
59-
gameAchievementsSublevel.get(levelKeys.game(game.shop, game.objectId)),
60-
db.get<string, UserPreferences>(levelKeys.userPreferences, {
59+
let localGameAchievement = await gameAchievementsSublevel.get(
60+
levelKeys.game(game.shop, game.objectId)
61+
);
62+
const userPreferences = await db.get<string, UserPreferences>(
63+
levelKeys.userPreferences,
64+
{
6165
valueEncoding: "json",
62-
}),
63-
]);
66+
}
67+
);
68+
69+
if (!localGameAchievement) {
70+
await getGameAchievementData(game.objectId, game.shop, true);
71+
localGameAchievement = await gameAchievementsSublevel.get(
72+
levelKeys.game(game.shop, game.objectId)
73+
);
74+
}
6475

6576
const achievementsData = localGameAchievement?.achievements ?? [];
6677
const unlockedAchievements = localGameAchievement?.unlockedAchievements ?? [];
@@ -91,7 +102,7 @@ export const mergeAchievements = async (
91102
if (
92103
newAchievements.length &&
93104
publishNotification &&
94-
userPreferences?.achievementNotificationsEnabled
105+
userPreferences.achievementNotificationsEnabled !== false
95106
) {
96107
const filteredAchievements = newAchievements
97108
.toSorted((a, b) => {
@@ -125,7 +136,7 @@ export const mergeAchievements = async (
125136
};
126137
});
127138

128-
if (userPreferences?.achievementCustomNotificationsEnabled !== false) {
139+
if (userPreferences.achievementCustomNotificationsEnabled !== false) {
129140
WindowManager.notificationWindow?.webContents.send(
130141
"on-achievement-unlocked",
131142
userPreferences.achievementCustomNotificationPosition ?? "top-left",

src/main/services/hydra-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class HydraApi {
4242
subscription: null,
4343
};
4444

45-
private static isLoggedIn() {
45+
public static isLoggedIn() {
4646
return this.userAuth.authToken !== "";
4747
}
4848

src/main/services/library-sync/upload-games-batch.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ export const uploadGamesBatch = async () => {
3333

3434
await mergeWithRemoteGames();
3535

36-
AchievementWatcherManager.preSearchAchievements();
36+
if (HydraApi.isLoggedIn()) {
37+
AchievementWatcherManager.preSearchAchievements();
38+
}
3739

3840
if (WindowManager.mainWindow)
3941
WindowManager.mainWindow.webContents.send("on-library-batch-complete");

src/main/services/window-manager.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,22 @@ export class WindowManager {
333333
public static async createNotificationWindow() {
334334
if (this.notificationWindow) return;
335335

336-
const userPreferences = await db.get<string, UserPreferences>(
336+
const userPreferences = await db.get<string, UserPreferences | undefined>(
337337
levelKeys.userPreferences,
338338
{
339339
valueEncoding: "json",
340340
}
341341
);
342+
343+
if (
344+
userPreferences?.achievementNotificationsEnabled === false ||
345+
userPreferences?.achievementCustomNotificationsEnabled === false
346+
) {
347+
return;
348+
}
349+
342350
const { x, y } = await this.getNotificationWindowPosition(
343-
userPreferences.achievementCustomNotificationPosition
351+
userPreferences?.achievementCustomNotificationPosition
344352
);
345353

346354
this.notificationWindow = new BrowserWindow({

src/renderer/src/pages/achievements/notification/achievement-notification.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ export function AchievementNotification() {
135135
useEffect(() => {
136136
const loadAndApplyTheme = async () => {
137137
const activeTheme = await window.electron.getActiveCustomTheme();
138-
console.log("activeTheme", activeTheme);
139138
if (activeTheme?.code) {
140139
injectCustomCss(activeTheme.code);
141140
}

src/renderer/src/pages/settings/settings-general.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function SettingsGeneral() {
3838
downloadNotificationsEnabled: false,
3939
repackUpdatesNotificationsEnabled: false,
4040
friendRequestNotificationsEnabled: false,
41-
achievementNotificationsEnabled: false,
41+
achievementNotificationsEnabled: true,
4242
achievementCustomNotificationsEnabled: true,
4343
achievementCustomNotificationPosition:
4444
"top-left" as AchievementCustomNotificationPosition,
@@ -104,7 +104,7 @@ export function SettingsGeneral() {
104104
repackUpdatesNotificationsEnabled:
105105
userPreferences.repackUpdatesNotificationsEnabled ?? false,
106106
achievementNotificationsEnabled:
107-
userPreferences.achievementNotificationsEnabled ?? false,
107+
userPreferences.achievementNotificationsEnabled ?? true,
108108
achievementCustomNotificationsEnabled:
109109
userPreferences.achievementCustomNotificationsEnabled ?? true,
110110
achievementCustomNotificationPosition:

0 commit comments

Comments
 (0)