mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-11 05:46:17 +00:00
fix: notifications not working on first run
This commit is contained in:
@@ -16,7 +16,7 @@ const updateAchievementCustomNotificationWindow = async (
|
||||
WindowManager.closeNotificationWindow();
|
||||
|
||||
if (
|
||||
userPreferences.achievementNotificationsEnabled &&
|
||||
userPreferences.achievementNotificationsEnabled !== false &&
|
||||
userPreferences.achievementCustomNotificationsEnabled !== false
|
||||
) {
|
||||
WindowManager.createNotificationWindow();
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -42,7 +42,7 @@ export class HydraApi {
|
||||
subscription: null,
|
||||
};
|
||||
|
||||
private static isLoggedIn() {
|
||||
public static isLoggedIn() {
|
||||
return this.userAuth.authToken !== "";
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user