| 1 | import { useSyncExternalStore } from "react"; |
| 2 | |
| 3 | const visible = () => |
| 4 | document.visibilityState !== "hidden" && window.cageWindowVisible !== false; |
| 5 | |
| 6 | function subscribe(notify) { |
| 7 | document.addEventListener("visibilitychange", notify); |
| 8 | window.addEventListener("cage-window-visibility", notify); |
| 9 | return () => { |
| 10 | document.removeEventListener("visibilitychange", notify); |
| 11 | window.removeEventListener("cage-window-visibility", notify); |
| 12 | }; |
| 13 | } |
| 14 | |
| 15 | export function useWindowVisibility() { |
| 16 | return useSyncExternalStore(subscribe, visible); |
| 17 | } |