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();
if (
userPreferences.achievementNotificationsEnabled &&
userPreferences.achievementNotificationsEnabled !== false &&
userPreferences.achievementCustomNotificationsEnabled !== false
) {
WindowManager.createNotificationWindow();

View File

@@ -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",

View File

@@ -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<string, UserPreferences>(levelKeys.userPreferences, {
let localGameAchievement = await gameAchievementsSublevel.get(
levelKeys.game(game.shop, game.objectId)
);
const userPreferences = await db.get<string, UserPreferences>(
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",

View File

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

View File

@@ -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");

View File

@@ -333,14 +333,22 @@ export class WindowManager {
public static async createNotificationWindow() {
if (this.notificationWindow) return;
const userPreferences = await db.get<string, UserPreferences>(
const userPreferences = await db.get<string, UserPreferences | undefined>(
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({

View File

@@ -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);
}

View File

@@ -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: