Uses the existing check_claude_cli Tauri command to detect the claude binary at app startup and shows a status badge — green/neutral when found, orange warning when missing with a click-to-install link. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
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<T>(command: string): Promise<T> {
|
|
return isTauri() ? invoke<T>(command) : mockInvoke<T>(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<ClaudeCodeStatus>('checking')
|
|
const [version, setVersion] = useState<string | null>(null)
|
|
|
|
useEffect(() => {
|
|
let cancelled = false
|
|
|
|
tauriCall<ClaudeCliResult>('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 }
|
|
}
|