Skip to content

Commit d231a7f

Browse files
committed
feat: refresh on inactivity
Signed-off-by: Adam Setch <[email protected]>
1 parent 43e7faf commit d231a7f

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/renderer/context/App.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,34 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
166166
fetchNotifications({ auth, settings });
167167
}, [auth.accounts, settings.filterReasons, settings.hideBots]);
168168

169-
useInterval(() => {
170-
fetchNotifications({ auth, settings });
171-
}, Constants.FETCH_NOTIFICATIONS_INTERVAL);
169+
useEffect(() => {
170+
let timeout: NodeJS.Timeout;
171+
172+
const resetTimeout = () => {
173+
if (timeout) {
174+
clearTimeout(timeout);
175+
}
176+
timeout = setTimeout(() => {
177+
fetchNotifications({ auth, settings });
178+
}, Constants.FETCH_NOTIFICATIONS_INTERVAL);
179+
};
180+
181+
const handleActivity = () => {
182+
console.log('Activity detected');
183+
resetTimeout();
184+
};
185+
186+
window.addEventListener('mousedown', handleActivity);
187+
window.addEventListener('keydown', handleActivity);
188+
189+
resetTimeout();
190+
191+
return () => {
192+
clearTimeout(timeout);
193+
window.removeEventListener('mousedown', handleActivity);
194+
window.removeEventListener('keydown', handleActivity);
195+
};
196+
}, [auth, settings, fetchNotifications]);
172197

173198
useInterval(() => {
174199
for (const account of auth.accounts) {

0 commit comments

Comments
 (0)