diff options
| author | haoyuren <13851610112@163.com> | 2026-03-13 17:28:27 -0500 |
|---|---|---|
| committer | haoyuren <13851610112@163.com> | 2026-03-13 17:28:27 -0500 |
| commit | e377dabf99595a6783fd962a8765d2214a635ac2 (patch) | |
| tree | b6f8654e13579552f31326d7f2780005b13cfa7e /src/preload | |
| parent | c069e833b98253f31ef153317a6212cefde07c9a (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'src/preload')
| -rw-r--r-- | src/preload/index.ts | 22 |
1 files changed, 11 insertions, 11 deletions
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 |
