fix: notifications not working on first run

This commit is contained in:
Zamitto
2025-05-17 20:32:24 -03:00
parent 276c098fbc
commit a5aabe0ad7
8 changed files with 36 additions and 16 deletions

View File

@@ -16,7 +16,7 @@ const updateAchievementCustomNotificationWindow = async (
WindowManager.closeNotificationWindow(); WindowManager.closeNotificationWindow();
if ( if (
userPreferences.achievementNotificationsEnabled && userPreferences.achievementNotificationsEnabled !== false &&
userPreferences.achievementCustomNotificationsEnabled !== false userPreferences.achievementCustomNotificationsEnabled !== false
) { ) {
WindowManager.createNotificationWindow(); WindowManager.createNotificationWindow();

View File

@@ -274,7 +274,7 @@ export class AchievementWatcherManager {
} }
); );
if (userPreferences.achievementNotificationsEnabled) { if (userPreferences.achievementNotificationsEnabled !== false) {
if (userPreferences.achievementCustomNotificationsEnabled !== false) { if (userPreferences.achievementCustomNotificationsEnabled !== false) {
WindowManager.notificationWindow?.webContents.send( WindowManager.notificationWindow?.webContents.send(
"on-combined-achievements-unlocked", "on-combined-achievements-unlocked",

View File

@@ -13,6 +13,7 @@ import { publishNewAchievementNotification } from "../notifications";
import { SubscriptionRequiredError } from "@shared"; import { SubscriptionRequiredError } from "@shared";
import { achievementsLogger } from "../logger"; import { achievementsLogger } from "../logger";
import { db, gameAchievementsSublevel, levelKeys } from "@main/level"; import { db, gameAchievementsSublevel, levelKeys } from "@main/level";
import { getGameAchievementData } from "./get-game-achievement-data";
const isRareAchievement = (points: number) => { const isRareAchievement = (points: number) => {
const rawPercentage = (50 - Math.sqrt(points)) * 2; const rawPercentage = (50 - Math.sqrt(points)) * 2;
@@ -55,12 +56,22 @@ export const mergeAchievements = async (
achievements: UnlockedAchievement[], achievements: UnlockedAchievement[],
publishNotification: boolean publishNotification: boolean
) => { ) => {
const [localGameAchievement, userPreferences] = await Promise.all([ let localGameAchievement = await gameAchievementsSublevel.get(
gameAchievementsSublevel.get(levelKeys.game(game.shop, game.objectId)), levelKeys.game(game.shop, game.objectId)
db.get<string, UserPreferences>(levelKeys.userPreferences, { );
const userPreferences = await db.get<string, UserPreferences>(
levelKeys.userPreferences,
{
valueEncoding: "json", 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 achievementsData = localGameAchievement?.achievements ?? [];
const unlockedAchievements = localGameAchievement?.unlockedAchievements ?? []; const unlockedAchievements = localGameAchievement?.unlockedAchievements ?? [];
@@ -91,7 +102,7 @@ export const mergeAchievements = async (
if ( if (
newAchievements.length && newAchievements.length &&
publishNotification && publishNotification &&
userPreferences?.achievementNotificationsEnabled userPreferences.achievementNotificationsEnabled !== false
) { ) {
const filteredAchievements = newAchievements const filteredAchievements = newAchievements
.toSorted((a, b) => { .toSorted((a, b) => {
@@ -125,7 +136,7 @@ export const mergeAchievements = async (
}; };
}); });
if (userPreferences?.achievementCustomNotificationsEnabled !== false) { if (userPreferences.achievementCustomNotificationsEnabled !== false) {
WindowManager.notificationWindow?.webContents.send( WindowManager.notificationWindow?.webContents.send(
"on-achievement-unlocked", "on-achievement-unlocked",
userPreferences.achievementCustomNotificationPosition ?? "top-left", userPreferences.achievementCustomNotificationPosition ?? "top-left",

View File

@@ -42,7 +42,7 @@ export class HydraApi {
subscription: null, subscription: null,
}; };
private static isLoggedIn() { public static isLoggedIn() {
return this.userAuth.authToken !== ""; return this.userAuth.authToken !== "";
} }

View File

@@ -33,7 +33,9 @@ export const uploadGamesBatch = async () => {
await mergeWithRemoteGames(); await mergeWithRemoteGames();
AchievementWatcherManager.preSearchAchievements(); if (HydraApi.isLoggedIn()) {
AchievementWatcherManager.preSearchAchievements();
}
if (WindowManager.mainWindow) if (WindowManager.mainWindow)
WindowManager.mainWindow.webContents.send("on-library-batch-complete"); WindowManager.mainWindow.webContents.send("on-library-batch-complete");

View File

@@ -333,14 +333,22 @@ export class WindowManager {
public static async createNotificationWindow() { public static async createNotificationWindow() {
if (this.notificationWindow) return; if (this.notificationWindow) return;
const userPreferences = await db.get<string, UserPreferences>( const userPreferences = await db.get<string, UserPreferences | undefined>(
levelKeys.userPreferences, levelKeys.userPreferences,
{ {
valueEncoding: "json", valueEncoding: "json",
} }
); );
if (
userPreferences?.achievementNotificationsEnabled === false ||
userPreferences?.achievementCustomNotificationsEnabled === false
) {
return;
}
const { x, y } = await this.getNotificationWindowPosition( const { x, y } = await this.getNotificationWindowPosition(
userPreferences.achievementCustomNotificationPosition userPreferences?.achievementCustomNotificationPosition
); );
this.notificationWindow = new BrowserWindow({ this.notificationWindow = new BrowserWindow({

View File

@@ -135,7 +135,6 @@ export function AchievementNotification() {
useEffect(() => { useEffect(() => {
const loadAndApplyTheme = async () => { const loadAndApplyTheme = async () => {
const activeTheme = await window.electron.getActiveCustomTheme(); const activeTheme = await window.electron.getActiveCustomTheme();
console.log("activeTheme", activeTheme);
if (activeTheme?.code) { if (activeTheme?.code) {
injectCustomCss(activeTheme.code); injectCustomCss(activeTheme.code);
} }

View File

@@ -38,7 +38,7 @@ export function SettingsGeneral() {
downloadNotificationsEnabled: false, downloadNotificationsEnabled: false,
repackUpdatesNotificationsEnabled: false, repackUpdatesNotificationsEnabled: false,
friendRequestNotificationsEnabled: false, friendRequestNotificationsEnabled: false,
achievementNotificationsEnabled: false, achievementNotificationsEnabled: true,
achievementCustomNotificationsEnabled: true, achievementCustomNotificationsEnabled: true,
achievementCustomNotificationPosition: achievementCustomNotificationPosition:
"top-left" as AchievementCustomNotificationPosition, "top-left" as AchievementCustomNotificationPosition,
@@ -104,7 +104,7 @@ export function SettingsGeneral() {
repackUpdatesNotificationsEnabled: repackUpdatesNotificationsEnabled:
userPreferences.repackUpdatesNotificationsEnabled ?? false, userPreferences.repackUpdatesNotificationsEnabled ?? false,
achievementNotificationsEnabled: achievementNotificationsEnabled:
userPreferences.achievementNotificationsEnabled ?? false, userPreferences.achievementNotificationsEnabled ?? true,
achievementCustomNotificationsEnabled: achievementCustomNotificationsEnabled:
userPreferences.achievementCustomNotificationsEnabled ?? true, userPreferences.achievementCustomNotificationsEnabled ?? true,
achievementCustomNotificationPosition: achievementCustomNotificationPosition: