The best way to control Claude Code, Codex and more from any computer or phone

main
ts 67 lines 2.44 KB
Raw
1 import { msg } from "gt-react-native";
2
3 import { m, type MessageResolver } from "../../i18n/messages";
4 import { runtimeConnectionErrorText } from "../connection/environmentStatusText";
5 import type { WorkspaceState } from "../../state/workspaceModel";
6
7 export interface WorkspaceConnectionStatusPresentation {
8 readonly label: string;
9 readonly showsProgress: boolean;
10 }
11
12 function shouldShowWorkspaceConnectionStatus(state: WorkspaceState): boolean {
13 if (state.networkStatus === "offline") return true;
14 if (state.hasReadyEnvironment) return state.hasSyncingConnectedEnvironment;
15 return (
16 state.connectionError !== null ||
17 state.hasConnectingEnvironment ||
18 state.hasPendingShellSnapshot ||
19 (state.hasLoadedShellSnapshot && !state.hasReadyEnvironment)
20 );
21 }
22
23 function workspaceConnectionStatusLabel(state: WorkspaceState, resolve: MessageResolver): string {
24 if (state.networkStatus === "offline") return resolve(msg("You are offline"));
25 if (state.hasReadyEnvironment && state.hasSyncingConnectedEnvironment) {
26 return state.hasLoadedShellSnapshot
27 ? resolve(msg("Syncing threads..."))
28 : resolve(msg("Loading threads..."));
29 }
30 if (state.connectingEnvironments.length === 1) {
31 return resolve(
32 msg("Reconnecting to {environment}", {
33 environment: state.connectingEnvironments[0]!.environmentLabel,
34 }),
35 );
36 }
37 if (state.connectingEnvironments.length > 1) {
38 return resolve(
39 msg(
40 "{count, plural, one {Reconnecting {count} environment} other {Reconnecting {count} environments}}",
41 { count: state.connectingEnvironments.length },
42 ),
43 );
44 }
45 const connectionError = runtimeConnectionErrorText(state, resolve);
46 if (connectionError !== null) return connectionError;
47 if (state.hasPendingShellSnapshot) {
48 return state.hasLoadedShellSnapshot
49 ? resolve(msg("Syncing threads..."))
50 : resolve(msg("Loading threads..."));
51 }
52 return resolve(msg("Not connected"));
53 }
54
55 export function workspaceConnectionStatusPresentation(
56 state: WorkspaceState,
57 resolve: MessageResolver = m,
58 ): WorkspaceConnectionStatusPresentation | null {
59 if (!shouldShowWorkspaceConnectionStatus(state)) return null;
60 return {
61 label: workspaceConnectionStatusLabel(state, resolve),
62 showsProgress:
63 state.networkStatus !== "offline" &&
64 (state.hasReadyEnvironment || state.connectionError === null) &&
65 (state.connectingEnvironments.length > 0 || state.hasPendingShellSnapshot),
66 };
67 }