From e377dabf99595a6783fd962a8765d2214a635ac2 Mon Sep 17 00:00:00 2001 From: haoyuren <13851610112@163.com> Date: Fri, 13 Mar 2026 17:28:27 -0500 Subject: Separate Terminal and Claude into independent pty instances - Support multiple named pty instances via ID-based IPC channels - Terminal tab spawns a shell, Claude tab spawns `claude` CLI separately - Fix pty race condition: old instance's onExit callback could delete the replacement instance from the Map during React StrictMode re-mount - Guard against StrictMode double-initialization in TerminalInstance Co-Authored-By: Claude Opus 4.6 --- src/preload/index.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/preload/index.ts') diff --git a/src/preload/index.ts b/src/preload/index.ts index 1bf97b3..aa16872 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -16,20 +16,20 @@ const api = { return () => ipcRenderer.removeListener('latex:log', handler) }, - // Terminal - ptySpawn: (cwd: string) => ipcRenderer.invoke('pty:spawn', cwd), - ptyWrite: (data: string) => ipcRenderer.invoke('pty:write', data), - ptyResize: (cols: number, rows: number) => ipcRenderer.invoke('pty:resize', cols, rows), - ptyKill: () => ipcRenderer.invoke('pty:kill'), - onPtyData: (cb: (data: string) => void) => { + // Terminal (supports multiple named instances) + ptySpawn: (id: string, cwd: string, cmd?: string, args?: string[]) => ipcRenderer.invoke('pty:spawn', id, cwd, cmd, args), + ptyWrite: (id: string, data: string) => ipcRenderer.invoke('pty:write', id, data), + ptyResize: (id: string, cols: number, rows: number) => ipcRenderer.invoke('pty:resize', id, cols, rows), + ptyKill: (id: string) => ipcRenderer.invoke('pty:kill', id), + onPtyData: (id: string, cb: (data: string) => void) => { const handler = (_e: Electron.IpcRendererEvent, data: string) => cb(data) - ipcRenderer.on('pty:data', handler) - return () => ipcRenderer.removeListener('pty:data', handler) + ipcRenderer.on(`pty:data:${id}`, handler) + return () => ipcRenderer.removeListener(`pty:data:${id}`, handler) }, - onPtyExit: (cb: () => void) => { + onPtyExit: (id: string, cb: () => void) => { const handler = () => cb() - ipcRenderer.on('pty:exit', handler) - return () => ipcRenderer.removeListener('pty:exit', handler) + ipcRenderer.on(`pty:exit:${id}`, handler) + return () => ipcRenderer.removeListener(`pty:exit:${id}`, handler) }, // SyncTeX -- cgit v1.2.3