Skip to content

Commit d90be80

Browse files
committed
feat: initialize codex client and manage loading state in App component
This commit enhances the App component by introducing a codex client initialization process using an asynchronous function. It manages the loading state with a new `initialized` state variable, displaying a loading message while the client initializes. The store subscriptions are now set up only after successful initialization, improving the application's startup sequence and user experience.
1 parent a0fc916 commit d90be80

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/App.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
1-
import { useEffect } from "react";
1+
import { useEffect, useState } from "react";
22
import { Layout } from "@/components/layout";
33
import { useDeepLink } from "./hooks/useDeepLink";
44
import { initializeActiveConversationSubscription } from "@/stores/codex/useActiveConversationStore";
5+
import { invoke } from "@/lib/tauri-proxy";
6+
import { InitializeResponse } from "@/bindings/InitializeResponse";
57
import "./App.css";
68

79
export default function App() {
810
// Initialize deep linking - must be called at top level, not conditionally
911
useDeepLink();
12+
const [initialized, setInitialized] = useState(false);
1013

1114
useEffect(() => {
12-
// Initialize store subscriptions
13-
initializeActiveConversationSubscription();
15+
// Initialize codex client before any other operations
16+
const initializeCodex = async () => {
17+
try {
18+
await invoke<InitializeResponse>("initialize_client");
19+
console.log("Codex client initialized successfully");
20+
setInitialized(true);
21+
} catch (error) {
22+
console.error("Failed to initialize codex client", error);
23+
// Still mark as initialized to allow UI to load, but log the error
24+
setInitialized(true);
25+
}
26+
27+
// Initialize store subscriptions after codex client is initialized
28+
initializeActiveConversationSubscription();
29+
};
30+
31+
// Wait for initialization
32+
initializeCodex();
1433
}, []);
1534

35+
if (!initialized) {
36+
return <div className="flex items-center justify-center h-screen">Initializing...</div>;
37+
}
38+
1639
return <Layout />;
1740
}

0 commit comments

Comments
 (0)