Files
Netcatty/components/terminal/connectionProgress.ts
T
bincxz c0d6646f73 fix(terminal): keep connection progress from rewinding
The connecting dialog bar stretched, shrank, then stretched again
because the initial value was 15, the timeout effect snapped back to 5
whenever hop or phase changed, and hop updates could overwrite a higher
value. Seed once when status becomes connecting and only move forward.
2026-08-14 20:02:46 +08:00

19 lines
748 B
TypeScript

export const CONNECTION_PROGRESS_START = 5;
export const CONNECTION_PROGRESS_CAP = 95;
export const advanceIndeterminateConnectionProgress = (prev: number): number => {
if (prev >= CONNECTION_PROGRESS_CAP) return prev;
const remaining = CONNECTION_PROGRESS_CAP - prev;
const increment = Math.max(1, remaining * 0.15);
return Math.min(CONNECTION_PROGRESS_CAP, prev + increment);
};
export const resolveHopConnectionProgress = (hop: number, total: number): number => {
const safeTotal = Math.max(1, total);
const safeHop = Math.max(0, hop);
return Math.min(CONNECTION_PROGRESS_CAP, (safeHop / safeTotal) * 80 + 10);
};
export const advanceMonotonicConnectionProgress = (prev: number, next: number): number =>
Math.max(prev, next);