From d231a7fd6dc8239b520d186b8faebb51bc42bf81 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sat, 8 Feb 2025 09:33:28 -0500 Subject: [PATCH] feat: refresh on inactivity Signed-off-by: Adam Setch --- src/renderer/context/App.tsx | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/renderer/context/App.tsx b/src/renderer/context/App.tsx index 68973bcd5..112924390 100644 --- a/src/renderer/context/App.tsx +++ b/src/renderer/context/App.tsx @@ -166,9 +166,34 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { fetchNotifications({ auth, settings }); }, [auth.accounts, settings.filterReasons, settings.hideBots]); - 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) {