mirror of https://github.com/jetkvm/kvm.git
refactor: streamline keep-alive timer management in useKeyboard hook
This commit is contained in:
parent
820e462dda
commit
a2b060b42e
|
@ -272,15 +272,13 @@ export default function useKeyboard() {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const scheduleKeepAlive = useCallback(() => {
|
const scheduleKeepAlive = useCallback(() => {
|
||||||
// Clear existing timer if it exists
|
// Clears existing keepalive timer
|
||||||
if (keepAliveTimerRef.current) {
|
cancelKeepAlive();
|
||||||
clearInterval(keepAliveTimerRef.current);
|
|
||||||
}
|
|
||||||
|
|
||||||
keepAliveTimerRef.current = setInterval(() => {
|
keepAliveTimerRef.current = setInterval(() => {
|
||||||
sendKeypressKeepAliveHidRpc();
|
sendKeypressKeepAliveHidRpc();
|
||||||
}, KEEPALIVE_INTERVAL);
|
}, KEEPALIVE_INTERVAL);
|
||||||
}, [sendKeypressKeepAliveHidRpc]);
|
}, [cancelKeepAlive, sendKeypressKeepAliveHidRpc]);
|
||||||
|
|
||||||
// resetKeyboardState is used to reset the keyboard state to no keys pressed and no modifiers.
|
// 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
|
// This is useful for macros and when the browser loses focus to ensure that the keyboard state
|
||||||
|
|
Loading…
Reference in New Issue