cicy-desktop 2.1.137 → 2.1.139

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.137",
3
+ "version": "2.1.139",
4
4
  "description": "CiCy - AI-powered operating system browser",
5
5
  "main": "src/main.js",
6
6
  "bin": {
@@ -119,12 +119,26 @@ async function distroInstalled(distro = DISTRO) {
119
119
  // Raw `wsl --import` of the rootfs as an ISOLATED v2 distro.
120
120
  function importTarball(dest, installDir) {
121
121
  return new Promise((resolve, reject) => {
122
+ // 240s, NOT 600s: a 444MB import finishes in well under 4min on a healthy WSL.
123
+ // If it runs longer it has WEDGED (the whole WSL subsystem hangs — every later
124
+ // `wsl` call then blocks and the app goes 未响应). Bound it short so we FAIL FAST
125
+ // and the caller can `wsl --shutdown` + retry instead of hanging 10 minutes.
122
126
  execFile("wsl", ["--import", DISTRO, installDir, dest, "--version", "2"],
123
- { timeout: 600000, windowsHide: true },
127
+ { timeout: 240000, windowsHide: true },
124
128
  (err, _so, se) => { if (err) { err.stderr = String(se || ""); return reject(err); } resolve(); });
125
129
  });
126
130
  }
127
131
 
132
+ // `wsl --shutdown`: hard-reset the ENTIRE WSL VM. This is the only reliable cure
133
+ // when WSL wedges (a hung `wsl --import` leaves every subsequent `wsl` call
134
+ // blocking → the app freezes). Unlike `wsl --list/-d` it doesn't query the wedged
135
+ // VM, so it returns even when WSL is stuck. Use it as recovery between retries.
136
+ function wslShutdown() {
137
+ return new Promise((resolve) => {
138
+ execFile("wsl", ["--shutdown"], { timeout: 30000, windowsHide: true }, () => resolve());
139
+ });
140
+ }
141
+
128
142
  // `wsl --terminate <distro>`: stop the distro so the NEXT `wsl -d` cold-boots it
129
143
  // clean. This is the fix for the「引擎没起来」-on-fresh-install failure: a distro
130
144
  // straight out of `wsl --import` is frequently half-initialized / unresponsive,
@@ -157,10 +171,17 @@ async function installDistro({ emit } = {}) {
157
171
  try {
158
172
  await importTarball(dest, installDir);
159
173
  } catch (e) {
160
- // Most likely the shared WSL2 kernel component is missing install it
161
- // (idempotent) and retry once.
162
- emit && emit({ phase: "container", status: "running", message: "需要 WSL2 内核,正在安装后重试…" });
163
- await ensureWslKernel({ emit });
174
+ // Import failed or WEDGED (our 4-min timeout fired). Recover hard, then retry once:
175
+ // 1) `wsl --shutdown` — clears a wedged WSL VM (the real cause of the 8-min hang
176
+ // + app freeze). Without this the retry hits the same stuck VM and hangs again.
177
+ // 2) ensure the WSL2 kernel (import also fails when it's missing).
178
+ // 3) unregister any half-registered distro a wedged import left behind, so the
179
+ // retry imports clean.
180
+ log.warn(`[installDistro] import failed/wedged (${e.message}) → wsl --shutdown + retry`);
181
+ emit && emit({ phase: "container", status: "running", message: "导入卡住,重置 WSL(--shutdown)后重试…" });
182
+ try { await wslShutdown(); } catch {}
183
+ try { await ensureWslKernel({ emit }); } catch {}
184
+ try { await new Promise((r) => execFile("wsl", ["--unregister", DISTRO], { timeout: 30000, windowsHide: true }, () => r())); } catch {}
164
185
  await importTarball(dest, installDir);
165
186
  }
166
187
  // 3) Force a clean cold boot. A freshly-imported distro is often wedged, so the
@@ -349,7 +370,12 @@ async function runContainer({ port = 8009, container = "cicy-code-docker", volum
349
370
  .filter(([, v]) => v != null && v !== "")
350
371
  .map(([k, v]) => `-e ${k}='${String(v).replace(/'/g, "'\\''")}'`)
351
372
  .join(" ");
352
- const cmd = `docker run -d --name ${container} --restart unless-stopped -p 127.0.0.1:${port}:8008 -e CICY_PUBLIC=1 -v ${volume}:/home/cicy ${shareMountArg()} ${envArgs} ${IMAGE}`;
373
+ // --dns: WSL2's auto resolv.conf points the distro at the host NAT gateway
374
+ // (172.x.x.1), which docker's default DNS forwarding does NOT reach from inside a
375
+ // bridge container → every lookup is EAI_AGAIN and cicy-code's startup `npm i`
376
+ // crash-loops the container (:8009 never comes up). Pin public resolvers: Aliyun
377
+ // 223.5.5.5 (CN-fast) first, Google 8.8.8.8 as the overseas fallback.
378
+ const cmd = `docker run -d --name ${container} --restart unless-stopped --dns 223.5.5.5 --dns 8.8.8.8 -p 127.0.0.1:${port}:8008 -e CICY_PUBLIC=1 -v ${volume}:/home/cicy ${shareMountArg()} ${envArgs} ${IMAGE}`;
353
379
  await wslRun(cmd, { timeout: 60000 });
354
380
  ensureDesktopShortcut(volume, port).catch(() => {});
355
381
  return { started: true };