mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 20:11:08 +00:00
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.
19 lines
748 B
TypeScript
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);
|