1- import { createContext , type ReactNode , useEffect , useMemo } from 'react' ;
1+ import {
2+ createContext ,
3+ type ReactNode ,
4+ useEffect ,
5+ useMemo ,
6+ useState ,
7+ } from 'react' ;
8+
9+ import { onlineManager } from '@tanstack/react-query' ;
210
311import { useAccounts } from '../hooks/useAccounts' ;
412import { useKeyboardNavigation } from '../hooks/useKeyboardNavigation' ;
@@ -35,6 +43,8 @@ export interface AppContextState {
3543 ) => Promise < void > ;
3644
3745 focusedNotificationId : string | null ;
46+
47+ isOnline : boolean ;
3848}
3949
4050export const AppContext = createContext < Partial < AppContextState > | undefined > (
@@ -56,6 +66,8 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
5666 const useUnreadActiveIcon = useSettingsStore ( ( s ) => s . useUnreadActiveIcon ) ;
5767 const useAlternateIdleIcon = useSettingsStore ( ( s ) => s . useAlternateIdleIcon ) ;
5868
69+ const [ isOnline , setIsOnline ] = useState ( false ) ;
70+
5971 const {
6072 status,
6173 globalError,
@@ -82,14 +94,15 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
8294 // biome-ignore lint/correctness/useExhaustiveDependencies: We want to update the tray on setting or notification changes
8395 useEffect ( ( ) => {
8496 const trayCount = status === 'error' ? - 1 : notificationCount ;
85- setTrayIconColorAndTitle ( trayCount , hasMoreAccountNotifications ) ;
97+ setTrayIconColorAndTitle ( trayCount , hasMoreAccountNotifications , isOnline ) ;
8698 } , [
8799 showNotificationsCountInTray ,
88100 useUnreadActiveIcon ,
89101 useAlternateIdleIcon ,
90102 status ,
91103 notificationCount ,
92104 hasMoreAccountNotifications ,
105+ isOnline ,
93106 ] ) ;
94107
95108 useEffect ( ( ) => {
@@ -100,6 +113,25 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
100113 } ) ;
101114 } , [ resetAccounts , resetFilters ] ) ;
102115
116+ // Online / Offline status monitoring via TanStack Query onlineManager
117+ useEffect ( ( ) => {
118+ const handle = ( ) => {
119+ try {
120+ const online = onlineManager . isOnline ( ) ;
121+
122+ setIsOnline ( online ) ;
123+ } catch ( _err ) {
124+ // ignore
125+ }
126+ } ;
127+
128+ // Subscribe and call immediately to set initial status
129+ const unsubscribe = onlineManager . subscribe ( handle ) ;
130+ handle ( ) ;
131+
132+ return ( ) => unsubscribe ( ) ;
133+ } , [ ] ) ;
134+
103135 const contextValues : AppContextState = useMemo (
104136 ( ) => ( {
105137 status,
@@ -116,6 +148,8 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
116148 markNotificationsUnread,
117149
118150 focusedNotificationId,
151+
152+ isOnline,
119153 } ) ,
120154 [
121155 status ,
@@ -132,6 +166,8 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
132166 markNotificationsUnread ,
133167
134168 focusedNotificationId ,
169+
170+ isOnline ,
135171 ] ,
136172 ) ;
137173
0 commit comments