Files
Netcatty/application/state/useTerminalPopupWindow.ts
T
陈大猫 f99efa8ac1 fix(ui): open AI silent sessions in an attach terminal popup (#2380)
* fix(ui): open AI silent sessions in an attach terminal popup

Tray jumps for hidden MCP sessions attach the existing terminal popup
to the live PTY instead of activating a tab-less main-window surface.
Output is rebound to the popup and restored when the popup closes.

* fix(terminal): register rebindOutput handlers under worker mode

Worker-enabled builds returned early from terminalBridge.registerHandlers
without registering rebind/restore IPC, so the first AI silent-session
attach popup always failed with "No handler registered". Register those
handlers in both paths and rebind display routing via terminalWorkerManager.

* fix(terminal): harden AI attach popup for worker mode lifecycle

Address codex review P1s: resume flow control before restoring output,
route exit/events to the rebound renderer, and replay home scrollback
via a snapshot request before rebinding display output.

* fix(terminal): restore attach routing on popup close and dual-notify exit

Hardening for AI observe popups: restore output from BrowserWindow closed
lifecycle (not only React cleanup), keep attach home for exit events so
main/tray lifecycle updates, and resume paused backend flow on attach.

* fix(terminal): resume flow on attach restore and close snapshot gaps

Resume backend output when attach popups are force-closed, fan out
lifecycle exit events to home+display in non-worker mode, and pause
during snapshot→rebind so live bytes are not dropped from the popup.

* fix(terminal): harden attach restore and worker lifecycle edges

Prefer live display for ZMODEM dialogs after rebind, dual-notify worker
crash exits to attach-home, and avoid clearing attach-home when restore
targets a dead renderer.

* fix(terminal): sync observe-popup state home and fan out SSH exits

Push popup serializations home before restore, fall back to hibernate
snapshots, settle briefly after pause for worker handoff, and dual-notify
SSH exits to attach-home owners in non-worker mode.

* fix(terminal): fan out exits for mosh/telnet/et attach owners

Use shared fanout for in-process protocol exits so attach-home and
display renderers both receive netcatty:exit under non-worker mode.

* fix(terminal): restore attach only onto main app windows

Avoid routing silent-session output to settings/prewarm windows when the
original home renderer is gone; fall back only to registered main windows.

* fix(terminal): harden silent session popup handoff

* fix(terminal): close observed popup with session

* fix(terminal): keep observe popup from reconnecting

* fix(terminal): preserve cleared observe snapshots

* fix(terminal): route transfer prompts to observer

* fix(terminal): keep context after observe restore
2026-07-22 08:58:58 +08:00

30 lines
1.2 KiB
TypeScript

import { useCallback } from 'react';
import { netcattyBridge } from '../../infrastructure/services/netcattyBridge';
import type { TerminalPopupPayload } from '../../domain/systemManager/types';
export function useTerminalPopupWindow() {
const close = useCallback(async () => {
await netcattyBridge.get()?.windowClose?.();
}, []);
const setWindowTitle = useCallback(async (title: string) => {
await netcattyBridge.get()?.setWindowTitle?.(title);
}, []);
const onPopupConfig = useCallback((cb: (payload: TerminalPopupPayload) => void) => {
const bridge = netcattyBridge.get();
if (!bridge?.onTerminalPopupConfig) return () => {};
return bridge.onTerminalPopupConfig(cb);
}, []);
const markAttachClosePrepared = useCallback(async (sessionId: string, authorization: string) => {
return netcattyBridge.get()?.markAttachPopupClosePrepared?.(sessionId, authorization);
}, []);
const onPrepareClose = useCallback((cb: (payload: { sessionId: string; authorization: string }) => void) => {
return netcattyBridge.get()?.onTerminalPopupPrepareClose?.(cb) ?? (() => {});
}, []);
return { close, setWindowTitle, onPopupConfig, markAttachClosePrepared, onPrepareClose };
}