Files
Netcatty/application/state/resolveTerminalSessionExitIntent.ts
T
陈大猫 34c4efb225 feat(terminal): add exit auto-close setting (#2394)
* feat: add terminal exit auto-close setting

* fix: sync terminal auto-close preference

* fix: reveal kept popup after clean exit

* fix: use latest terminal exit handler

* test: include terminal behavior coverage

* fix: reveal all kept command popups
2026-07-22 16:14:30 +08:00

49 lines
1.4 KiB
TypeScript

export type TerminalSessionExitEvent = {
exitCode?: number;
signal?: number;
error?: string;
reason?: "exited" | "error" | "timeout" | "closed";
};
export type TerminalSessionExitIntent =
| { kind: "closeSession" }
| { kind: "markDisconnected" };
type TerminalPopupExitOptions = {
autoCloseOnExit?: boolean;
isAttachMode?: boolean;
};
function isConfirmedCleanExit(evt: TerminalSessionExitEvent): boolean {
return evt.reason === "exited" && evt.exitCode === 0;
}
export function resolveTerminalSessionExitIntent(
evt: TerminalSessionExitEvent,
autoCloseOnExit = true,
): TerminalSessionExitIntent {
if (autoCloseOnExit && isConfirmedCleanExit(evt)) {
return { kind: "closeSession" };
}
// Non-zero or unknown exits, timeouts, transport errors, and channel closes
// should keep the tab visible so the user can inspect output and reconnect.
return { kind: "markDisconnected" };
}
export function shouldCloseTerminalPopupOnExit(
evt: TerminalSessionExitEvent,
options: TerminalPopupExitOptions = {},
): boolean {
if (options.autoCloseOnExit === false) return false;
return options.isAttachMode === true || isConfirmedCleanExit(evt);
}
export function shouldRevealTerminalPopupOnExit(
_evt: TerminalSessionExitEvent,
options: TerminalPopupExitOptions = {},
): boolean {
return options.autoCloseOnExit === false &&
options.isAttachMode !== true;
}