fix: 修复 Ghostty 实例重复加载问题并优化终端输入逻辑
This commit is contained in:
10
src/App.tsx
10
src/App.tsx
@@ -194,11 +194,13 @@ function TerminalPanel({ initialCwd, connectDelay = 0, autoFocus = false }: { in
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="grid grid-cols-2 grid-rows-2 gap-1 h-screen w-screen bg-[#1e1e1e]">
|
||||
<div className="grid grid-cols-2 grid-rows-3 gap-1 h-screen w-screen bg-[#1e1e1e]">
|
||||
<TerminalPanel initialCwd={DEFAULT_CWD} connectDelay={0} autoFocus={true} />
|
||||
<TerminalPanel initialCwd={DEFAULT_CWD} connectDelay={100} />
|
||||
<TerminalPanel initialCwd={DEFAULT_CWD} connectDelay={200} />
|
||||
<TerminalPanel initialCwd={DEFAULT_CWD} connectDelay={300} />
|
||||
<TerminalPanel initialCwd={DEFAULT_CWD} connectDelay={500} />
|
||||
<TerminalPanel initialCwd={DEFAULT_CWD} connectDelay={1000} />
|
||||
<TerminalPanel initialCwd={DEFAULT_CWD} connectDelay={1500} />
|
||||
<TerminalPanel initialCwd={DEFAULT_CWD} connectDelay={2000} />
|
||||
<TerminalPanel initialCwd={DEFAULT_CWD} connectDelay={2500} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,12 +11,16 @@ import { cn } from '../lib/utils';
|
||||
|
||||
// 使用 Map 按 sessionKey 隔离 Ghostty 实例,避免多面板状态冲突
|
||||
const ghosttyInstances = new Map<string, Promise<Ghostty>>();
|
||||
let globalGhosttyLoadPromise: Promise<Ghostty> | null = null;
|
||||
|
||||
function getGhostty(sessionKey: string): Promise<Ghostty> {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -654,7 +654,16 @@ export async function sendTerminalInput(
|
||||
sessionId: string,
|
||||
data: string
|
||||
): Promise<void> {
|
||||
// 直接使用 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user