cicy-desktop 2.1.86 → 2.1.88

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/bin/cicy-desktop CHANGED
@@ -40,41 +40,65 @@ function globalElectronBin() {
40
40
  return _globalElectronBin;
41
41
  }
42
42
 
43
- // Self-heal electron's downloaded binary so a FRESH `npx cicy-desktop` starts
44
- // first-try. cicy-desktop pins electron 41.0.3 as a dependency; its postinstall
45
- // downloads the platform binary. If that never ran (--ignore-scripts), failed
46
- // (GitHub blocked in CN with no mirror) or got wiped (AV touched node_modules),
47
- // `npx electron` throws "Electron failed to install correctly" and the worker
48
- // crash-loops. Detect a missing binary and re-run electron's OWN install.js with
49
- // the npmmirror ELECTRON_MIRROR. Uses the pinned 41.0.3 already on disk — never
50
- // pulls latest (latest's native extract-zip is unpublished for win32-x64 →
51
- // "Cannot find native binding"). Runs once per process.
43
+ // Pinned electron version = the one cicy-desktop is built against (package.json
44
+ // dependency). NEVER install "latest": its native extract-zip prebuild is
45
+ // unpublished for win32-x64 `npm i -g electron` dies with "Cannot find native
46
+ // binding". 41.x downloads fine.
47
+ const ELECTRON_VERSION = (() => {
48
+ try {
49
+ const pj = require("../package.json");
50
+ const v = (pj.dependencies && pj.dependencies.electron) ||
51
+ (pj.devDependencies && pj.devDependencies.electron) || "";
52
+ return String(v).replace(/^[\^~>=\s]*/, "").trim() || "41.0.3";
53
+ } catch { return "41.0.3"; }
54
+ })();
55
+
56
+ // True iff <electronDir> has a downloaded, runnable binary (path.txt → dist/exe).
57
+ function electronBinaryHealthy(electronDir) {
58
+ if (!electronDir) return false;
59
+ try {
60
+ const exe = fs.readFileSync(path.join(electronDir, "path.txt"), "utf8").trim();
61
+ return !!exe && fs.existsSync(path.join(electronDir, "dist", exe));
62
+ } catch { return false; }
63
+ }
64
+
65
+ // The GLOBAL electron's package dir for the current npm prefix (null if none).
66
+ function globalElectronDir() {
67
+ try {
68
+ const prefix = execSync("npm prefix -g", { stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
69
+ if (!prefix) return null;
70
+ return isWindows
71
+ ? path.join(prefix, "node_modules", "electron") // win: <prefix>\node_modules\electron
72
+ : path.join(prefix, "lib", "node_modules", "electron"); // unix: <prefix>/lib/node_modules/electron
73
+ } catch { return null; }
74
+ }
75
+
76
+ // Make sure a USABLE electron exists before spawning the worker. Prefer a shared
77
+ // GLOBAL electron (downloaded once, survives npx-cache eviction, and
78
+ // resolveElectronSpawn() picks it first). If nothing healthy is found anywhere,
79
+ // auto-install the PINNED version GLOBALLY with the npmmirror mirror — i.e. do the
80
+ // `npm i -g electron@<pin>` step for the user, so a fresh `npx cicy-desktop`
81
+ // self-provisions electron and starts first-try. Runs once per process.
52
82
  let _electronEnsured = false;
53
83
  function ensureElectron() {
54
84
  if (_electronEnsured) return;
55
85
  _electronEnsured = true;
56
- let electronDir;
57
- try { electronDir = path.dirname(require.resolve("electron/package.json", { paths: [PACKAGE_ROOT] })); }
58
- catch { return; } // not resolvable from here → leave it to npx
59
- try {
60
- const pathTxt = path.join(electronDir, "path.txt");
61
- if (fs.existsSync(pathTxt)) {
62
- const exe = fs.readFileSync(pathTxt, "utf8").trim();
63
- if (exe && fs.existsSync(path.join(electronDir, "dist", exe))) return; // healthy
64
- }
65
- } catch {}
66
- const installJs = path.join(electronDir, "install.js");
67
- if (!fs.existsSync(installJs)) return;
68
- console.log("⚙️ Electron binary missing — repairing via electron/install.js (mirror)…");
86
+ // Already usable (global, or the resolvable bundled/npx copy)? nothing to do.
87
+ if (electronBinaryHealthy(globalElectronDir())) return;
88
+ let bundledDir = null;
89
+ try { bundledDir = path.dirname(require.resolve("electron/package.json", { paths: [PACKAGE_ROOT] })); } catch {}
90
+ if (electronBinaryHealthy(bundledDir)) return;
91
+ // None usable → install the pinned electron globally (with the mirror).
92
+ console.log(`⚙️ No usable Electron — installing electron@${ELECTRON_VERSION} -g (mirror), one-time…`);
69
93
  try {
70
- execSync(`"${process.execPath}" "${installJs}"`, {
71
- cwd: electronDir,
94
+ execSync(`npm i -g electron@${ELECTRON_VERSION} --registry=${NPM_REGISTRY}`, {
72
95
  stdio: "inherit",
73
96
  env: { ...process.env, ELECTRON_MIRROR, npm_config_registry: NPM_REGISTRY },
74
97
  });
98
+ _globalElectronBin = undefined; // bust the memo so resolveElectronSpawn re-finds the new global bin
75
99
  } catch (e) {
76
- console.warn(`⚠️ Electron repair failed: ${e.message}`);
77
- console.warn(` Fix manually: set ELECTRON_MIRROR=${ELECTRON_MIRROR} && npm i -g electron@41.0.3`);
100
+ console.warn(`⚠️ Global electron install failed: ${e.message}`);
101
+ console.warn(` Fix manually: set ELECTRON_MIRROR=${ELECTRON_MIRROR} && npm i -g electron@${ELECTRON_VERSION}`);
78
102
  }
79
103
  }
80
104
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cicy-desktop",
3
- "version": "2.1.86",
3
+ "version": "2.1.88",
4
4
  "description": "CiCy - AI-powered operating system browser",
5
5
  "main": "src/main.js",
6
6
  "bin": {
@@ -133,11 +133,11 @@
133
133
  },
134
134
  "//optionalDependencies": "Runtime Bundle v1 (主人指令): platform binaries delivered by `npm i -g cicy-desktop` itself — npm installs only the current-platform subpackage (os/cpu pinned in each), so first start seeds the runtime store with ZERO network, ZERO npx. Windows packages are named *-windows-* (npm spam filter 403s new names containing win32). cicy-msys2 added once published.",
135
135
  "optionalDependencies": {
136
- "cicy-code-darwin-x64": "2.3.7",
137
- "cicy-code-darwin-arm64": "2.3.7",
138
- "cicy-code-linux-x64": "2.3.7",
139
- "cicy-code-linux-arm64": "2.3.7",
140
- "cicy-code-windows-x64": "2.3.7",
136
+ "cicy-code-darwin-x64": "2.3.9",
137
+ "cicy-code-darwin-arm64": "2.3.9",
138
+ "cicy-code-linux-x64": "2.3.9",
139
+ "cicy-code-linux-arm64": "2.3.9",
140
+ "cicy-code-windows-x64": "2.3.9",
141
141
  "cicy-mihomo-darwin-x64": "1.10.4",
142
142
  "cicy-mihomo-darwin-arm64": "1.10.4",
143
143
  "cicy-mihomo-linux-x64": "1.10.4",