refactor: streamline keep-alive timer management in useKeyboard hook

This commit is contained in:
Adam Shiervani 2025-09-18 11:13:03 +02:00 committed by Siyuan Miao
parent 820e462dda
commit a2b060b42e
1 changed files with 3 additions and 5 deletions

View File

@ -272,15 +272,13 @@ export default function useKeyboard() {
}, []);
const scheduleKeepAlive = useCallback(() => {
// Clear existing timer if it exists
if (keepAliveTimerRef.current) {
clearInterval(keepAliveTimerRef.current);
}
// Clears existing keepalive timer
cancelKeepAlive();
keepAliveTimerRef.current = setInterval(() => {
sendKeypressKeepAliveHidRpc();
}, KEEPALIVE_INTERVAL);
}, [sendKeypressKeepAliveHidRpc]);
}, [cancelKeepAlive, sendKeypressKeepAliveHidRpc]);
// resetKeyboardState is used to reset the keyboard state to no keys pressed and no modifiers.
// This is useful for macros and when the browser loses focus to ensure that the keyboard state