Skip to content
Merged
9 changes: 8 additions & 1 deletion src/frontend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Suspense fallback={null}>
<LocalTerminal
Expand All @@ -118,6 +124,7 @@ function LocalTerminalTab({ tab, isVisible, isFocusedPane, label }: TabProps) {
sessionId={tab.id}
isFocusedPane={isFocusedPane}
label={label}
onClose={() => shell.closeTab(tab.id)}
/>
</Suspense>
);
Expand Down
10 changes: 10 additions & 0 deletions src/frontend/local-terminal/LocalTerminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,24 @@ 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
// change (which gives react-i18next a new `t` identity) doesn't tear down
// 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.
Expand Down Expand Up @@ -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(
`

Expand Down