The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useSyncExternalStore } from "react"; |
| 2 | |
| 3 | export type HistoryDirection = "back" | "forward"; |
| 4 | |
| 5 | function subscribeToNavigationHistory(onChange: () => void): () => void { |
| 6 | window.navigation.addEventListener("currententrychange", onChange); |
| 7 | return () => window.navigation.removeEventListener("currententrychange", onChange); |
| 8 | } |
| 9 | |
| 10 | export function canNavigateHistory(direction: HistoryDirection): boolean { |
| 11 | return direction === "back" ? window.navigation.canGoBack : window.navigation.canGoForward; |
| 12 | } |
| 13 | |
| 14 | export function navigateHistory(direction: HistoryDirection) { |
| 15 | if (direction === "back") window.history.back(); |
| 16 | else window.history.forward(); |
| 17 | } |
| 18 | |
| 19 | /** Only for Electron: the Navigation API is Chromium-only. */ |
| 20 | export function useCanNavigateHistory(direction: HistoryDirection): boolean { |
| 21 | return useSyncExternalStore(subscribeToNavigationHistory, () => canNavigateHistory(direction)); |
| 22 | } |