(totalBytes, doneBytes, elapsedMs)
| 3022 | } |
| 3023 | |
| 3024 | function estimateCryptoProgress(totalBytes, doneBytes, elapsedMs) { |
| 3025 | if (!Number.isFinite(totalBytes) || totalBytes <= 0) return null; |
| 3026 | |
| 3027 | let bps = readCryptoEstimateSpeed(); |
| 3028 | if (Number.isFinite(doneBytes) && doneBytes > 0 && elapsedMs > 1000) { |
| 3029 | const observed = (doneBytes * 1000) / Math.max(1, elapsedMs); |
| 3030 | if (Number.isFinite(observed) && observed > 0) { |
| 3031 | bps = clampNum((bps * 0.45) + (observed * 0.55), CRYPTO_MIN_SPEED_BPS, CRYPTO_MAX_SPEED_BPS); |
| 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | const estDone = clampNum( |
| 3036 | Math.max(Number.isFinite(doneBytes) ? doneBytes : 0, Math.round((elapsedMs / 1000) * bps)), |
| 3037 | 0, |
| 3038 | totalBytes |
| 3039 | ); |
| 3040 | const pct = clampNum(Math.round((estDone / Math.max(1, totalBytes)) * 100), 0, 97); |
| 3041 | const etaMs = Math.max(0, Math.round(((totalBytes - estDone) / Math.max(1, bps)) * 1000)); |
| 3042 | return { pct, estDone, etaMs, bps }; |
| 3043 | } |
| 3044 | |
| 3045 | function setEncryptedClassForRenderedSubtree(folder, encrypted) { |
| 3046 | try { |
no test coverage detected