| 1 | import { useEffect } from "react"; |
| 2 | import { app } from "../lib/bridge"; |
| 3 | import { dismissOnboarding, shouldOpenOnboarding } from "../lib/onboarding"; |
| 4 | import { useOverlayStore } from "../store/overlays"; |
| 5 | import { useAppNavigationStore } from "../store/appNavigation"; |
| 6 | |
| 7 | export async function probeProviderSetupState(): Promise<boolean> { |
| 8 | const needs = await app.NeedsOnboarding(); |
| 9 | useOverlayStore.getState().setProviderSetupNeeded(needs); |
| 10 | return needs; |
| 11 | } |
| 12 | |
| 13 | /** Probes setup once; a later navigation intent owns the current page. */ |
| 14 | export function StartupGateLifecycle() { |
| 15 | useEffect(() => { |
| 16 | let cancelled = false; |
| 17 | const navigationGeneration = useAppNavigationStore.getState().generation; |
| 18 | (async () => { |
| 19 | try { |
| 20 | const needs = await app.NeedsOnboarding(); |
| 21 | if (cancelled) return; |
| 22 | useOverlayStore.getState().setProviderSetupNeeded(needs); |
| 23 | const navigation = useAppNavigationStore.getState(); |
| 24 | if (shouldOpenOnboarding(needs) && navigation.generation === navigationGeneration) { |
| 25 | dismissOnboarding(); |
| 26 | navigation.setSettingsFocus({ target: "model-access", onboarding: true }); |
| 27 | navigation.setSettingsTarget("providers"); |
| 28 | } |
| 29 | } catch { |
| 30 | // Setup status is advisory; bridge failures must not block startup. |
| 31 | } |
| 32 | })(); |
| 33 | return () => { cancelled = true; }; |
| 34 | }, []); |
| 35 | return null; |
| 36 | } |
| 37 |