mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
feat(desktop): show download progress and diagnostics on splash (#3273)
This commit is contained in:
1 parent
795e190bda
commit
0ef1cd14c3
12 files changed
+667
-18
No files matched your search
@@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
const RATE_SMOOTHING_WINDOW_MS = 3000;
|
||||
const RATE_MIN_SAMPLE_MS = 200;
|
||||
|
||||
export class ModuleDownloadRate {
|
||||
private lastBytes: number | null = null;
|
||||
private lastAt = 0;
|
||||
private rate: number | null = null;
|
||||
|
||||
public reset(): void {
|
||||
this.lastBytes = null;
|
||||
this.lastAt = 0;
|
||||
this.rate = null;
|
||||
}
|
||||
|
||||
public sample(bytes: number, at: number): number | null {
|
||||
if (this.lastBytes == null || bytes < this.lastBytes) {
|
||||
this.lastBytes = bytes;
|
||||
this.lastAt = at;
|
||||
this.rate = null;
|
||||
return null;
|
||||
}
|
||||
const elapsed = at - this.lastAt;
|
||||
if (elapsed < RATE_MIN_SAMPLE_MS) {
|
||||
return this.rate;
|
||||
}
|
||||
const instant = ((bytes - this.lastBytes) * 1000) / elapsed;
|
||||
const weight = 1 - Math.exp(-elapsed / RATE_SMOOTHING_WINDOW_MS);
|
||||
this.rate = this.rate == null ? instant : this.rate + (instant - this.rate) * weight;
|
||||
this.lastBytes = bytes;
|
||||
this.lastAt = at;
|
||||
return this.rate;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user