diff --git a/src/App.tsx b/src/App.tsx index 7ec9ef6..df1dc07 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -194,11 +194,13 @@ function TerminalPanel({ initialCwd, connectDelay = 0, autoFocus = false }: { in function App() { return ( -
+
- - - + + + + +
); } diff --git a/src/components/TerminalViewport.tsx b/src/components/TerminalViewport.tsx index af36be5..aef7e4a 100644 --- a/src/components/TerminalViewport.tsx +++ b/src/components/TerminalViewport.tsx @@ -11,12 +11,16 @@ import { cn } from '../lib/utils'; // 使用 Map 按 sessionKey 隔离 Ghostty 实例,避免多面板状态冲突 const ghosttyInstances = new Map>(); +let globalGhosttyLoadPromise: Promise | null = null; function getGhostty(sessionKey: string): Promise { let promise = ghosttyInstances.get(sessionKey); if (!promise) { - promise = Ghostty.load(); - ghosttyInstances.set(sessionKey, promise); + if (!globalGhosttyLoadPromise) { + globalGhosttyLoadPromise = Ghostty.load(); + } + ghosttyInstances.set(sessionKey, globalGhosttyLoadPromise); + promise = globalGhosttyLoadPromise; } return promise; } diff --git a/src/lib/terminalApi.ts b/src/lib/terminalApi.ts index ca139b2..fc0321c 100644 --- a/src/lib/terminalApi.ts +++ b/src/lib/terminalApi.ts @@ -654,7 +654,16 @@ export async function sendTerminalInput( sessionId: string, data: string ): Promise { - // 直接使用 HTTP,避免 WebSocket 连接等待延迟 + const globalState = getTerminalInputWsGlobalState(); + const manager = globalState.manager; + + if (manager && manager.isConnectedOrConnecting()) { + const sent = await manager.sendInput(sessionId, data); + if (sent) { + return; + } + } + await sendTerminalInputHttp(sessionId, data); }