From 3e8e71bd79437784e4fb84712511fe7db025dd6e Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Fri, 20 Mar 2026 12:34:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Ghostty=20=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E9=87=8D=E5=A4=8D=E5=8A=A0=E8=BD=BD=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E7=BB=88=E7=AB=AF=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 10 ++++++---- src/components/TerminalViewport.tsx | 8 ++++++-- src/lib/terminalApi.ts | 11 ++++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) 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); }