import { useEffect, useState } from 'react' import { invoke } from '@tauri-apps/api/core' import { isTauri, mockInvoke } from '../mock-tauri' export type ClaudeCodeStatus = 'checking' | 'installed' | 'missing' interface ClaudeCliResult { installed: boolean version: string | null } function tauriCall(command: string): Promise { return isTauri() ? invoke(command) : mockInvoke(command) } /** * Checks once on mount whether the `claude` CLI binary is available. * Returns a status suitable for the status bar badge. */ export function useClaudeCodeStatus(): { status: ClaudeCodeStatus; version: string | null } { const [status, setStatus] = useState('checking') const [version, setVersion] = useState(null) useEffect(() => { let cancelled = false tauriCall('check_claude_cli') .then((result) => { if (cancelled) return setStatus(result.installed ? 'installed' : 'missing') setVersion(result.version ?? null) }) .catch(() => { if (!cancelled) setStatus('missing') }) return () => { cancelled = true } }, []) return { status, version } }