cicy-desktop 2.1.203 → 2.1.204

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cicy-desktop",
3
- "version": "2.1.203",
3
+ "version": "2.1.204",
4
4
  "description": "CiCy - AI-powered operating system browser",
5
5
  "main": "src/main.js",
6
6
  "bin": {
@@ -104,11 +104,24 @@ function download(url, dest, onProgress, redirects = 0) {
104
104
  }
105
105
  if (res.statusCode !== 200) { f.close(); try { fs.unlinkSync(dest); } catch {} return reject(new Error(`HTTP ${res.statusCode}`)); }
106
106
  const total = parseInt(res.headers["content-length"] || "0", 10) || 0;
107
- let transferred = 0, lastPct = -1;
107
+ let transferred = 0, lastEmit = 0;
108
+ const startT = Date.now();
109
+ let winT = startT, winBytes = 0, bytesPerSec = 0;
108
110
  res.on("data", (chunk) => {
109
111
  transferred += chunk.length;
110
- const percent = total ? Math.floor((transferred / total) * 100) : 0;
111
- if (percent !== lastPct) { lastPct = percent; try { onProgress && onProgress({ percent, transferred, total }); } catch {} }
112
+ const now = Date.now();
113
+ // 速度按 ~500ms 滑窗算,平滑不抖。
114
+ if (now - winT >= 500) {
115
+ bytesPerSec = (transferred - winBytes) / ((now - winT) / 1000);
116
+ winT = now; winBytes = transferred;
117
+ }
118
+ // 节流:每 ~120ms 或下载完才推一次(够顺滑又不刷爆 IPC)。
119
+ if (now - lastEmit >= 120 || transferred === total) {
120
+ lastEmit = now;
121
+ const percent = total ? Math.min(100, Math.floor((transferred / total) * 100)) : 0;
122
+ const etaSec = bytesPerSec > 0 && total ? Math.max(0, Math.round((total - transferred) / bytesPerSec)) : 0;
123
+ try { onProgress && onProgress({ percent, transferred, total, bytesPerSec, etaSec }); } catch {}
124
+ }
112
125
  });
113
126
  res.pipe(f);
114
127
  f.on("finish", () => f.close(() => resolve()));