* Main content router - decides which page to show based on onboarding state
()
| 45 | * Main content router - decides which page to show based on onboarding state |
| 46 | */ |
| 47 | function AppContent() { |
| 48 | const billingMethod = useAtomValue(billingMethodAtom) |
| 49 | const setBillingMethod = useSetAtom(billingMethodAtom) |
| 50 | const anthropicOnboardingCompleted = useAtomValue( |
| 51 | anthropicOnboardingCompletedAtom |
| 52 | ) |
| 53 | const setAnthropicOnboardingCompleted = useSetAtom(anthropicOnboardingCompletedAtom) |
| 54 | const apiKeyOnboardingCompleted = useAtomValue(apiKeyOnboardingCompletedAtom) |
| 55 | const setApiKeyOnboardingCompleted = useSetAtom(apiKeyOnboardingCompletedAtom) |
| 56 | const codexOnboardingCompleted = useAtomValue(codexOnboardingCompletedAtom) |
| 57 | const selectedProject = useAtomValue(selectedProjectAtom) |
| 58 | const setSelectedChatId = useSetAtom(selectedAgentChatIdAtom) |
| 59 | const { setActiveSubChat, addToOpenSubChats, setChatId } = useAgentSubChatStore() |
| 60 | |
| 61 | // Apply initial window params (chatId/subChatId) when opening via "Open in new window" |
| 62 | useEffect(() => { |
| 63 | const params = getInitialWindowParams() |
| 64 | if (params.chatId) { |
| 65 | console.log("[App] Opening chat from window params:", params.chatId, params.subChatId) |
| 66 | setSelectedChatId(params.chatId) |
| 67 | setChatId(params.chatId) |
| 68 | if (params.subChatId) { |
| 69 | addToOpenSubChats(params.subChatId) |
| 70 | setActiveSubChat(params.subChatId) |
| 71 | } |
| 72 | } |
| 73 | }, [setSelectedChatId, setChatId, addToOpenSubChats, setActiveSubChat]) |
| 74 | |
| 75 | // Claim the initially selected chat to prevent duplicate windows. |
| 76 | // For new windows opened via "Open in new window", the chat is pre-claimed by main process. |
| 77 | // For restored windows (persisted localStorage), we need to claim here. |
| 78 | // Read atom directly from store to avoid stale closure with empty deps. |
| 79 | useEffect(() => { |
| 80 | if (!window.desktopApi?.claimChat) return |
| 81 | const currentChatId = appStore.get(selectedAgentChatIdAtom) |
| 82 | if (!currentChatId) return |
| 83 | window.desktopApi.claimChat(currentChatId).then((result) => { |
| 84 | if (!result.ok) { |
| 85 | // Another window already has this chat — clear our selection |
| 86 | setSelectedChatId(null) |
| 87 | } |
| 88 | }) |
| 89 | // Only run on mount |
| 90 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 91 | }, []) |
| 92 | |
| 93 | // Check if user has existing CLI config (API key or proxy) |
| 94 | // Based on PR #29 by @sa4hnd |
| 95 | const { data: cliConfig, isLoading: isLoadingCliConfig } = |
| 96 | trpc.claudeCode.hasExistingCliConfig.useQuery() |
| 97 | |
| 98 | // Migration: If user already completed Anthropic onboarding but has no billing method set, |
| 99 | // automatically set it to "claude-subscription" (legacy users before billing method was added) |
| 100 | useEffect(() => { |
| 101 | if (!billingMethod && anthropicOnboardingCompleted) { |
| 102 | setBillingMethod("claude-subscription") |
| 103 | } |
| 104 | }, [billingMethod, anthropicOnboardingCompleted, setBillingMethod]) |
nothing calls this directly
no test coverage detected