The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useAtomValue } from "@effect/atom-react"; |
| 2 | import { Atom } from "effect/reactivity"; |
| 3 | |
| 4 | import { environmentShell, environmentShellSummaryAtom } from "./shell"; |
| 5 | import { isEnvironmentShellPending, projectWorkspaceState } from "./workspaceModel"; |
| 6 | import { environmentCatalog } from "../connection/catalog"; |
| 7 | import { environmentPresentations } from "./presentation"; |
| 8 | import { createWorkspaceConnectionAtoms } from "./workspace-connection-atoms"; |
| 9 | |
| 10 | export const workspaceConnections = createWorkspaceConnectionAtoms({ |
| 11 | catalogValueAtom: environmentCatalog.catalogValueAtom, |
| 12 | networkStatusValueAtom: environmentCatalog.networkStatusValueAtom, |
| 13 | presentationAtom: environmentPresentations.presentationAtom, |
| 14 | }); |
| 15 | |
| 16 | // A disconnected environment's retries also leave its shell synchronizing. |
| 17 | const hasSyncingConnectedEnvironmentAtom = Atom.make((get) => |
| 18 | get(workspaceConnections.environmentsAtom).some( |
| 19 | (environment) => |
| 20 | environment.isEnabled && |
| 21 | environment.connectionState === "connected" && |
| 22 | isEnvironmentShellPending(get(environmentShell.stateValueAtom(environment.environmentId))), |
| 23 | ), |
| 24 | ).pipe(Atom.withLabel("mobile:has-syncing-connected-environment")); |
| 25 | |
| 26 | export function useWorkspaceEnvironments() { |
| 27 | return useAtomValue(workspaceConnections.environmentsAtom); |
| 28 | } |
| 29 | |
| 30 | export function useWorkspaceConnectionState() { |
| 31 | return useAtomValue(workspaceConnections.stateAtom); |
| 32 | } |
| 33 | |
| 34 | export function useConnectionsReady() { |
| 35 | return useAtomValue(workspaceConnections.isReadyAtom); |
| 36 | } |
| 37 | |
| 38 | export const workspaceStateAtom = Atom.make((get) => |
| 39 | projectWorkspaceState({ |
| 40 | isReady: get(workspaceConnections.isReadyAtom), |
| 41 | networkStatus: get(environmentCatalog.networkStatusValueAtom), |
| 42 | environments: get(workspaceConnections.environmentsAtom), |
| 43 | shellSummary: get(environmentShellSummaryAtom), |
| 44 | hasSyncingConnectedEnvironment: get(hasSyncingConnectedEnvironmentAtom), |
| 45 | }), |
| 46 | ).pipe(Atom.withLabel("mobile:workspace-state")); |
| 47 | |
| 48 | export function useWorkspaceState() { |
| 49 | return { |
| 50 | environments: useWorkspaceEnvironments(), |
| 51 | state: useAtomValue(workspaceStateAtom), |
| 52 | }; |
| 53 | } |