diff --git a/src/renderer/context/App.tsx b/src/renderer/context/App.tsx index ff7b80816..9632cbed8 100644 --- a/src/renderer/context/App.tsx +++ b/src/renderer/context/App.tsx @@ -182,9 +182,34 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { settings.filterReasons, ]); - useInterval(() => { - fetchNotifications({ auth, settings }); - }, Constants.FETCH_NOTIFICATIONS_INTERVAL); + useEffect(() => { + let timeout: NodeJS.Timeout; + + const resetTimeout = () => { + if (timeout) { + clearTimeout(timeout); + } + timeout = setTimeout(() => { + fetchNotifications({ auth, settings }); + }, Constants.FETCH_NOTIFICATIONS_INTERVAL); + }; + + const handleActivity = () => { + console.log('Activity detected'); + resetTimeout(); + }; + + window.addEventListener('mousedown', handleActivity); + window.addEventListener('keydown', handleActivity); + + resetTimeout(); + + return () => { + clearTimeout(timeout); + window.removeEventListener('mousedown', handleActivity); + window.removeEventListener('keydown', handleActivity); + }; + }, [auth, settings, fetchNotifications]); useInterval(() => { for (const account of auth.accounts) {