From 4a41d0133f95b75f314d0b21fd7faa0c74bd8fc3 Mon Sep 17 00:00:00 2001 From: denis0001-dev Date: Sun, 21 Sep 2025 16:00:29 +0300 Subject: [PATCH] Initialize the notification system on credential restoration --- frontend/src/ui/state.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/frontend/src/ui/state.ts b/frontend/src/ui/state.ts index 70166e2..21e6594 100644 --- a/frontend/src/ui/state.ts +++ b/frontend/src/ui/state.ts @@ -7,6 +7,8 @@ import { DMPanel, type DMPanelData } from "./panels/DMPanel"; import { getAuthHeaders } from "../auth/api"; import { restoreKeys } from "../auth/crypto"; import { API_BASE_URL } from "../core/config"; +import { initialize, subscribe, startElectronReceiver, isSupported } from "../utils/notifications"; +import { isElectron } from "../electron/electron"; type Page = "login" | "register" | "chat" export type ChatTabs = "chats" | "channels" | "contacts" | "dms" @@ -215,6 +217,23 @@ export const useAppState = create((set, get) => ({ }, currentPage: "chat" })); + + // Initialize notifications after successful credential restoration + try { + if (isSupported()) { + const initialized = await initialize(); + if (initialized) { + await subscribe(token); + + // For Electron, start the notification receiver + if (isElectron) { + await startElectronReceiver(); + } + } + } + } catch (e) { + console.error("Notification setup failed (restored):", e); + } } else { throw new Error("Unable to authenticate"); }