diff --git a/src/frontend/index.tsx b/src/frontend/index.tsx index b830cdd..e8ea8cb 100644 --- a/src/frontend/index.tsx +++ b/src/frontend/index.tsx @@ -109,7 +109,13 @@ function TerminalStandalone({ hostId, params }: StandaloneViewProps) { } /** The desktop app's own shell, one tab per open. */ -function LocalTerminalTab({ tab, isVisible, isFocusedPane, label }: TabProps) { +function LocalTerminalTab({ + tab, + isVisible, + isFocusedPane, + label, + shell, +}: TabProps) { return ( shell.closeTab(tab.id)} /> ); diff --git a/src/frontend/local-terminal/LocalTerminal.tsx b/src/frontend/local-terminal/LocalTerminal.tsx index 61c9a8c..4d519a3 100644 --- a/src/frontend/local-terminal/LocalTerminal.tsx +++ b/src/frontend/local-terminal/LocalTerminal.tsx @@ -42,12 +42,14 @@ export function LocalTerminal({ sessionId = instanceId, isFocusedPane = false, label, + onClose, }: { instanceId: string; isVisible: boolean; sessionId?: string; isFocusedPane?: boolean; label?: string; + onClose?: () => void; }) { const { t } = useTranslation(); // Read via a ref inside the session-lifecycle effect below so a language @@ -55,6 +57,9 @@ export function LocalTerminal({ // the running local shell and spawn a new session. const tRef = useRef(t); tRef.current = t; + // Kept in a ref so a new callback identity doesn't restart the shell. + const onCloseRef = useRef(onClose); + onCloseRef.current = onClose; const { theme: appTheme } = useTheme(); const api = usePluginApi(); // The same look as SSH terminals get from the user's host defaults. @@ -288,6 +293,11 @@ export function LocalTerminal({ } else if (frame.type === "exit") { sessionReadyRef.current = false; emitSessionMessage({ type: "session_closed" }); + // Close the tab when the shell ends, like SSH sessions do. + if (onCloseRef.current) { + onCloseRef.current(); + return; + } terminal.write( `