MCPcopy Create free account
hub / github.com/GooseMod/OpenAsar / UIProgress

Class UIProgress

src/splash/index.js:79–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77
78let toSend = 0; // Progress state to send for ModuleUpdater (0 = downloading, 1 = installing)
79class UIProgress { // Generic class to track updating and sent states to splash
80 constructor(st) {
81 this.st = st;
82
83 this.reset();
84 }
85
86 reset() {
87 Object.assign(this, {
88 progress: new Map(),
89 done: new Set(),
90 total: new Set()
91 });
92 }
93
94 record(id, state, current, outOf) {
95 this.total.add(id);
96
97 if (current) this.progress.set(id, [ current, outOf ?? 100 ]);
98 if (state === 'Complete') this.done.add(id);
99
100 this.send();
101 }
102
103 send() {
104 if ((toSend === -1 && this.progress.size > 0 && this.progress.size > this.done.size) || toSend === this.st) {
105 const progress = Math.min(100, [...this.progress.values()].reduce((a, x) => a + x[0], 0) / [...this.progress.values()].reduce((a, x) => a + x[1], 0) * 100); // Clamp progress to 0-100
106
107 sendState(this.st ? 'installing' : 'downloading', {
108 current: this.done.size + 1,
109 total: this.total.size,
110 progress
111 });
112
113 return true;
114 }
115 }
116}
117
118const initNew = async (inst) => {
119 toSend = -1;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected