dsh-oc-desktop 0.3.9 → 0.3.11

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.
@@ -37,6 +37,10 @@ function main() {
37
37
  console.error('dsh-oc-desktop: launcher/main.js missing, reinstall the package.');
38
38
  process.exit(1);
39
39
  }
40
+ // electron.exe binary may be missing when npm global install hit its package cache
41
+ // and skipped electron's postinstall (no dist/). Re-run install.js before booting —
42
+ // it pulls from the local electron cache or the network.
43
+ ensureElectron(electron);
40
44
  // electron.exe brand icon may be lost after `npm install` (electron re-downloads its
41
45
  // exe). Re-inject before the shell starts — electron is not running yet, so the exe
42
46
  // is writable. Taskbar/TaskManager icons come from the exe, so this keeps them right.
@@ -55,6 +59,35 @@ function main() {
55
59
  // Re-inject the brand icon (and DSH Desktop version info) into electron.exe if it was
56
60
  // re-downloaded. Probe ProductName first (fast); inject when it is not 'DSH Desktop'.
57
61
  const injectScript = path.join(__dirname, '..', 'scripts', 'set-exe-icon.ps1');
62
+
63
+ // Ensure the electron binary exists before booting. `npm install -g` can skip
64
+ // electron's postinstall when the npm package cache is warm, leaving dist/ empty;
65
+ // re-running install.js fetches the binary from the local electron cache or network.
66
+ function ensureElectron(electron) {
67
+ if (fs.existsSync(electron)) return; // binary already present
68
+ console.log('dsh-oc-desktop: electron binary missing, running electron/install.js ...');
69
+ const pkgDir = path.resolve(path.dirname(electron), '..');
70
+ const installJs = path.join(pkgDir, 'install.js');
71
+ if (!fs.existsSync(installJs)) {
72
+ console.error(`dsh-oc-desktop: ${installJs} missing, reinstall the package.`);
73
+ process.exit(1);
74
+ }
75
+ try {
76
+ // Default to the npmmirror mirror unless the user set ELECTRON_MIRROR already.
77
+ const env = Object.assign({}, process.env);
78
+ if (!env.ELECTRON_MIRROR) env.ELECTRON_MIRROR = 'https://npmmirror.com/mirrors/electron/';
79
+ execFileSync(process.execPath, [installJs], { stdio: 'inherit', windowsHide: true, env });
80
+ } catch (e) {
81
+ console.error(`dsh-oc-desktop: failed to fetch electron binary: ${e && e.message ? e.message : e}`);
82
+ console.error('If this is a network issue, set ELECTRON_MIRROR to a mirror and retry.');
83
+ process.exit(1);
84
+ }
85
+ if (!fs.existsSync(electron)) {
86
+ console.error('dsh-oc-desktop: electron binary still missing after install.js; reinstall the package.');
87
+ process.exit(1);
88
+ }
89
+ }
90
+
58
91
  function ensureInjected(electron) {
59
92
  if (!fs.existsSync(injectScript)) return; // package missing the script — skip silently
60
93
  try {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-oc-desktop",
3
3
  "productName": "DeepSeek Harness Desktop",
4
- "version": "0.3.9",
4
+ "version": "0.3.11",
5
5
  "description": "DeepSeek Harness 桌面端插件(Electron 启动器):自绘标题栏/托盘/通知/快捷键/崩溃自愈",
6
6
  "main": "launcher/main.js",
7
7
  "bin": {
@@ -9,7 +9,8 @@
9
9
  },
10
10
  "scripts": {
11
11
  "start": "electron .",
12
- "test": "node --check launcher/main.js && node --check launcher/preload.js && node --check launcher/dialog-preload.js && node --check launcher/events.js && node --check launcher/session-window.js && node --check launcher/updater.js && node --check launcher/apply-update.js && node --check bin/dsh-desktop.cjs && node scripts/test.mjs && node scripts/test-updater.mjs"
12
+ "postinstall": "node scripts/postinstall.js",
13
+ "test": "node --check launcher/main.js && node --check launcher/preload.js && node --check launcher/dialog-preload.js && node --check launcher/events.js && node --check launcher/session-window.js && node --check launcher/updater.js && node --check launcher/apply-update.js && node --check bin/dsh-desktop.cjs && node --check scripts/postinstall.js && node scripts/test.mjs && node scripts/test-updater.mjs"
13
14
  },
14
15
  "dependencies": {
15
16
  "electron": "^43.4.0"
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ // dsh-oc-desktop postinstall: make sure the electron binary exists after install.
4
+ // npm package-cache hits can skip electron's postinstall (dist/ left empty), which
5
+ // makes the desktop shell unbootable. Download it now via the npmmirror mirror so
6
+ // the install is complete; never fail the install — the bin self-heals on first
7
+ // launch as a last resort.
8
+ const fs = require('node:fs');
9
+ const path = require('node:path');
10
+ const { spawnSync } = require('node:child_process');
11
+
12
+ const ELECTRON_MIRROR_DEFAULT = 'https://npmmirror.com/mirrors/electron/';
13
+
14
+ const electronDir = path.join(__dirname, '..', 'node_modules', 'electron');
15
+ if (!fs.existsSync(path.join(electronDir, 'install.js'))) process.exit(0);
16
+ const exe = path.join(electronDir, 'dist', process.platform === 'win32' ? 'electron.exe' : 'electron');
17
+ if (fs.existsSync(exe)) process.exit(0);
18
+
19
+ console.log('dsh-oc-desktop: electron binary missing, downloading (mirror) ...');
20
+ const env = Object.assign({}, process.env);
21
+ if (!env.ELECTRON_MIRROR) env.ELECTRON_MIRROR = ELECTRON_MIRROR_DEFAULT;
22
+ const r = spawnSync(process.execPath, [path.join(electronDir, 'install.js')], { stdio: 'inherit', env, windowsHide: true });
23
+ if (r.status !== 0 || !fs.existsSync(exe)) {
24
+ console.warn('dsh-oc-desktop: electron binary fetch failed; it will self-heal on first launch.');
25
+ }
26
+ process.exit(0);