mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-23 16:42:19 +00:00
A keep-count change during victim drain was still applied from the count captured when the leave started, so a zero setting could soft-hide the leaving tab with no later timer to correct it. Retention now uses the live count, and an already soft-hidden tab re-enters hibernate when the limit hits zero. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import { terminalHiddenRendererStore } from "./terminalHiddenRendererStore.ts";
|
|
|
|
/**
|
|
* Walk keep-count victims until one hibernate completes, then retain the
|
|
* leaving tab only if its reserved slot still fits.
|
|
*
|
|
* The reservation is taken before the first await. Clearing a victim marker
|
|
* during wake would otherwise look like spare capacity to a second hidden-tab
|
|
* timer, and both tabs would soft-hide once the same eviction resolved.
|
|
*/
|
|
export async function retainLeavingTabAfterEviction(input: {
|
|
sessionId: string;
|
|
candidates: readonly string[];
|
|
/** Count captured when this leave started. Used only if resolveKeepCount is absent. */
|
|
keepCount: number;
|
|
/**
|
|
* Live keep-count read after eviction settles. Settings can change while the
|
|
* victim drains or serializes; retaining against the captured count would
|
|
* soft-hide a tab the user no longer wants kept.
|
|
*/
|
|
resolveKeepCount?: () => number;
|
|
stillWantsRetention: () => boolean;
|
|
softHide: () => void;
|
|
fullHibernate: () => void;
|
|
evict?: (sessionId: string) => Promise<boolean> | boolean;
|
|
}): Promise<void> {
|
|
const token = terminalHiddenRendererStore.reserveLeavingSlot(input.sessionId);
|
|
try {
|
|
const evict = input.evict ?? ((sessionId: string) => (
|
|
terminalHiddenRendererStore.evictSoftHidden(sessionId)
|
|
));
|
|
let completed = false;
|
|
for (const candidate of input.candidates) {
|
|
if (!candidate || candidate === input.sessionId) continue;
|
|
if (await evict(candidate)) {
|
|
completed = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!input.stillWantsRetention()) return;
|
|
const keepCount = input.resolveKeepCount?.() ?? input.keepCount;
|
|
if (
|
|
completed
|
|
&& terminalHiddenRendererStore.leavingSlotStillFits(input.sessionId, keepCount)
|
|
) {
|
|
input.softHide();
|
|
return;
|
|
}
|
|
input.fullHibernate();
|
|
} finally {
|
|
terminalHiddenRendererStore.releaseLeavingSlot(input.sessionId, token);
|
|
}
|
|
}
|