import { useEffect } from 'react'; import { useAppStore } from '../store/useAppStore'; import { useLMStudio } from './useLMStudio'; /** * Checks the server once when the app opens, after the saved settings have been * restored, so the connection badge and model list are not stale until the user * visits Settings. */ export function useAutoConnect() { const { fetchModels } = useLMStudio(); useEffect(() => { const { persist } = useAppStore; if (persist.hasHydrated()) { void fetchModels(); return; } return persist.onFinishHydration(() => void fetchModels()); // Mount only: later checks are triggered by the user (model selector, Settings). // eslint-disable-next-line react-hooks/exhaustive-deps }, []); }