| 1 | import { useSyncExternalStore } from "react"; |
| 2 | |
| 3 | import { isTerminalFocused } from "../lib/terminalFocus"; |
| 4 | |
| 5 | export function subscribeToTerminalFocusChanges(listener: () => void): () => void { |
| 6 | window.addEventListener("focusin", listener, true); |
| 7 | window.addEventListener("focusout", listener, true); |
| 8 | return () => { |
| 9 | window.removeEventListener("focusin", listener, true); |
| 10 | window.removeEventListener("focusout", listener, true); |
| 11 | }; |
| 12 | } |
| 13 | |
| 14 | export function useTerminalFocus(): boolean { |
| 15 | return useSyncExternalStore(subscribeToTerminalFocusChanges, isTerminalFocused, () => false); |
| 16 | } |