|
| 1 | +import { useEffect, useState } from 'react' |
| 2 | +import { AlertTriangle } from 'lucide-react' |
| 3 | +import { Alert, AlertDescription } from './ui/alert' |
| 4 | +import log from 'electron-log/renderer' |
| 5 | + |
| 6 | +/** |
| 7 | + * Banner that displays a warning when using a custom ToolHive port in development mode. |
| 8 | + * Only visible when THV_PORT environment variable is set. |
| 9 | + */ |
| 10 | +export function CustomPortBanner() { |
| 11 | + const [isCustomPort, setIsCustomPort] = useState(false) |
| 12 | + const [port, setPort] = useState<number | undefined>(undefined) |
| 13 | + |
| 14 | + useEffect(() => { |
| 15 | + Promise.all([ |
| 16 | + window.electronAPI.isUsingCustomPort(), |
| 17 | + window.electronAPI.getToolhivePort(), |
| 18 | + ]) |
| 19 | + .then(([usingCustom, toolhivePort]) => { |
| 20 | + setIsCustomPort(usingCustom) |
| 21 | + setPort(toolhivePort) |
| 22 | + }) |
| 23 | + .catch((error: unknown) => { |
| 24 | + log.error('Failed to get custom port info:', error) |
| 25 | + }) |
| 26 | + }, []) |
| 27 | + |
| 28 | + // Don't render if not using custom port or port is not available |
| 29 | + if (!isCustomPort || !port) { |
| 30 | + return null |
| 31 | + } |
| 32 | + |
| 33 | + const httpAddress = `http://127.0.0.1:${port}` |
| 34 | + |
| 35 | + return ( |
| 36 | + <Alert |
| 37 | + className="fixed bottom-4 left-1/2 z-50 w-auto max-w-[95vw] |
| 38 | + -translate-x-1/2 border-yellow-200 bg-yellow-50 text-yellow-900 |
| 39 | + dark:border-yellow-800 dark:bg-yellow-950 dark:text-yellow-100" |
| 40 | + > |
| 41 | + <AlertTriangle /> |
| 42 | + <AlertDescription className="flex items-start gap-2"> |
| 43 | + <div className="whitespace-nowrap"> |
| 44 | + <span>Using external ToolHive at </span> |
| 45 | + <span |
| 46 | + className="rounded bg-yellow-100 px-1 py-0.5 font-mono text-xs |
| 47 | + dark:bg-yellow-900" |
| 48 | + title={httpAddress} |
| 49 | + > |
| 50 | + {httpAddress} |
| 51 | + </span> |
| 52 | + </div> |
| 53 | + </AlertDescription> |
| 54 | + </Alert> |
| 55 | + ) |
| 56 | +} |
0 commit comments