dsh-mobile-plugin 0.5.73 → 0.5.75

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.
@@ -1,34 +1,36 @@
1
1
  'use strict';
2
2
  // 远程电脑管理仅接受本机可信界面;电脑配对和加密升级由各自协议独立认证。
3
3
  // 桌面壳入口带专属标记,本机代理据此只给壳会话启用桌面端排版。
4
+ // 2026-11-19:spawn 的异步失败(没有 pid 或收到 error)和 900ms 内闪退同等处理,回 shellOpened:false;
5
+ // 错误文案改读 controller 里那一份唯一定义,并给 bad-invite / bad-id / bad-mode 带上错误码。
6
+ // 2026-11-19:/mode 删掉静态档位白名单,存在性只由 controller.setMode → router.setMode 校验
7
+ // (静态那份冗余且先过期,会把新通道挡在门外)。
4
8
  const { sendJson, readJsonBody } = require('../shared/http-util.js');
5
9
  const { trustedLocalUi, crossSiteRequest } = require('../http/routing.js');
6
- const { launchShell } = require('./shell.cjs');
10
+ const { launchShell, spawnFailed } = require('./shell.cjs');
11
+ const { REMOTE_ERROR_TEXT, REMOTE_ERROR_FALLBACK } = require('./controller.cjs');
7
12
  const PREFIX = '/api/relay/remote-computers';
8
13
  // 壳拉起后先观察一小会儿:刚起来就退(缺运行库 / 无图形会话 / 闪退)就当没打开,让前端退回浏览器。
9
14
  const SHELL_GRACE_MS = 900;
10
15
  function shellSurvived(child, waitMs = SHELL_GRACE_MS) {
16
+ // 测试里 launch 可能只给个占位值(不响应事件):没法判死活,按起来处理,保持原契约。
11
17
  if (!child || typeof child.once !== 'function') return Promise.resolve(true);
18
+ // 进程没拿到 pid 或已收到 error:可执行文件根本没跑起来,和闪退一样当没打开。
12
19
  if (child.exitCode !== null && child.exitCode !== undefined) return Promise.resolve(false);
20
+ if (spawnFailed(child)) return Promise.resolve(false);
13
21
  return new Promise((resolve) => {
14
22
  let settled = false;
15
- const finish = (alive) => { if (settled) return; settled = true; clearTimeout(timer); child.removeListener?.('exit', onExit); resolve(alive); };
23
+ const finish = (alive) => { if (settled) return; settled = true; clearTimeout(timer); child.removeListener?.('exit', onExit); child.removeListener?.('error', onError); resolve(alive); };
16
24
  const onExit = () => finish(false);
25
+ const onError = () => finish(false);
17
26
  const timer = setTimeout(() => finish(true), waitMs);
18
27
  timer.unref?.();
19
28
  child.once('exit', onExit);
29
+ child.once('error', onError);
20
30
  });
21
31
  }
22
32
  const METHODS = { '': 'GET', '/invite': 'POST', '/add': 'POST', '/open': 'POST', '/open-shell': 'POST',
23
33
  '/renew': 'POST', '/stop': 'POST', '/remove': 'POST', '/mode': 'POST', '/probe': 'POST', '/diagnose': 'POST', '/revoke': 'POST' };
24
- const PUBLIC_ERRORS = {
25
- 'credentials-unavailable': '宿主凭据存储暂不可用,请稍后重试',
26
- REMOTE_AUTH: '远程电脑认证失败,请重新绑定', REMOTE_REVOKED: '这台电脑的授权已被撤销,请重新绑定',
27
- REMOTE_VERSION: '对方插件版本不兼容,请升级到支持远程电脑的版本',
28
- REMOTE_EXPIRED: '授权已到期,请重新打开', REMOTE_TIMEOUT: '连接远程电脑超时,请重试或检测线路',
29
- REMOTE_CONNECT: '暂时无法连接远程电脑,请检查网络和对方是否在线',
30
- SHELL_UNAVAILABLE: '本机未安装远程电脑桌面端,请改用默认方式打开',
31
- };
32
34
  function createRemoteRoutes({ controller, host, credentials, instanceId, now = Date.now, launch = launchShell }) {
33
35
  function authorizedComputers() {
34
36
  return credentials.listRemoteComputers(instanceId);
@@ -54,7 +56,7 @@ function createRemoteRoutes({ controller, host, credentials, instanceId, now = D
54
56
  });
55
57
  if (suffix === '/invite') return sendJson(res, 200, { ok: true, ...await host.mintInvite() });
56
58
  if (suffix === '/add') {
57
- if (typeof body.invite !== 'string' || body.invite.length > 24 * 1024) throw new Error('bad-invite');
59
+ if (typeof body.invite !== 'string' || body.invite.length > 24 * 1024) throw Object.assign(new Error('bad-invite'), { code: 'bad-invite' });
58
60
  return sendJson(res, 200, { ok: true, device: await controller.add(body.invite) });
59
61
  }
60
62
  if (suffix === '/revoke') {
@@ -65,7 +67,7 @@ function createRemoteRoutes({ controller, host, credentials, instanceId, now = D
65
67
  host.revoke(body.deviceId);
66
68
  return sendJson(res, 200, { ok: true, revoked });
67
69
  }
68
- if (typeof body.id !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(body.id)) throw new Error('bad-id');
70
+ if (typeof body.id !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(body.id)) throw Object.assign(new Error('bad-id'), { code: 'bad-id' });
69
71
  if (suffix === '/open') return sendJson(res, 200, { ok: true, ...await controller.open(body.id) });
70
72
  if (suffix === '/open-shell') {
71
73
  const result = await controller.open(body.id);
@@ -88,7 +90,7 @@ function createRemoteRoutes({ controller, host, credentials, instanceId, now = D
88
90
  if (suffix === '/stop') await controller.stop(body.id);
89
91
  if (suffix === '/remove') await controller.remove(body.id);
90
92
  if (suffix === '/mode') {
91
- if (typeof body.mode !== 'string' || !['auto', 'lan', 'ipv6', 'relay', 'tunnel', 'p2p'].includes(body.mode)) throw new Error('bad-mode');
93
+ if (typeof body.mode !== 'string') throw Object.assign(new Error('bad-mode'), { code: 'bad-mode' });
92
94
  await controller.setMode(body.id, body.mode);
93
95
  }
94
96
  if (suffix === '/probe') await controller.probe(body.id);
@@ -98,7 +100,7 @@ function createRemoteRoutes({ controller, host, credentials, instanceId, now = D
98
100
  const code = typeof error?.code === 'string' ? error.code : 'remote-operation-failed';
99
101
  const status = /REVOKED|AUTH/.test(code) ? 401 : /EXPIRED|expired/i.test(code) ? 410 : 400;
100
102
  return sendJson(res, status, { ok: false, error: { code,
101
- message: PUBLIC_ERRORS[code] || '远程电脑操作未完成,请确认绑定信息、网络和访问期限后重试' } });
103
+ message: REMOTE_ERROR_TEXT[code] || REMOTE_ERROR_FALLBACK } });
102
104
  }
103
105
  };
104
106
  }
@@ -1,5 +1,7 @@
1
- 'use strict';
2
1
  // 远程电脑桌面端显示壳:按平台包找到随插件分发的可执行文件,用一次性入口拉起独立窗口。
2
+ // 2026-11-19:spawn 的失败是异步通知(ENOENT/EACCES 不会同步抛),记下 error、暴露「壳根本没起来」
3
+ // 的判据,让路由按 shellOpened:false 退回浏览器,和 900ms 内闪退同等处理。
4
+ 'use strict';
3
5
  const { spawn } = require('node:child_process');
4
6
  const fs = require('node:fs');
5
7
  const path = require('node:path');
@@ -93,9 +95,16 @@ function launchShell({ url, deviceName } = {}, options = {}) {
93
95
  } catch {
94
96
  throw failure(SHELL_UNAVAILABLE);
95
97
  }
96
- child?.on?.('error', () => {});
98
+ // spawn 的失败要等下一拍才以 error 事件送到:这里记下来,判存活时按「根本没起来」处理;
99
+ // 同时必须挂监听,否则未处理的 error 事件会让宿主崩掉。
100
+ child?.on?.('error', (error) => { child.shellSpawnError = error; });
97
101
  child?.unref?.();
98
102
  return child;
99
103
  }
100
104
 
101
- module.exports = { PLATFORM_IDS, SHELL_UNAVAILABLE, platformId, binaryPath, resolveShell, buildArgs, launchShell };
105
+ /** 壳进程到底起没起来:没有 pid 或已收到 error,都说明可执行文件没能跑起来。 */
106
+ function spawnFailed(child) {
107
+ return !child || child.pid === undefined || child.pid === null || Boolean(child.shellSpawnError);
108
+ }
109
+
110
+ module.exports = { PLATFORM_IDS, SHELL_UNAVAILABLE, platformId, binaryPath, resolveShell, buildArgs, launchShell, spawnFailed };
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+ // 由 App 通道表同步;运行 scripts/sync-route-policy.mjs 更新。
3
+ function createRouteChannels() {
4
+ const exports = {};
5
+ "use strict";
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ROUTE_CHANNELS = void 0;
8
+ exports.ROUTE_CHANNELS = [
9
+ { channel: 'lan', backoffThreshold: 2, budget: 'lan' },
10
+ { channel: 'ipv6', backoffThreshold: 2, budget: 'lan' },
11
+ { channel: 'relay', backoffThreshold: 2, budget: 'lan' },
12
+ { channel: 'tunnel', backoffThreshold: 1, budget: 'tunnel' },
13
+ { channel: 'p2p', backoffThreshold: 1, budget: 'tunnel' },
14
+ { channel: 'tcp', backoffThreshold: 2, budget: 'tunnel' },
15
+ ];
16
+
17
+ return exports;
18
+ }
19
+ module.exports = { createRouteChannels, ...createRouteChannels() };
@@ -10,6 +10,8 @@
10
10
  *
11
11
  * 任何一步起不来都只意味着「这台机器没有这条通道」:`mount` 兜住异常并留一行日志,中转与
12
12
  * 局域网一行不受影响。
13
+ *
14
+ * 门面也交给外壳一份:自更新装包前要让助手先松开平台包目录,装完再拉起来。
13
15
  */
14
16
 
15
17
  const { createLoopbackIngress } = require('./ingress.cjs');
@@ -122,6 +124,9 @@ function mountTailcat(options) {
122
124
  };
123
125
  }, `${name}: tailcat`),
124
126
  );
127
+ // 更新要替换平台包目录(Windows 上助手进程占着 exe 时 pnpm 会 EPERM)。把停/起口交给外壳,
128
+ // 装包前停、装完拉起;只给门面,不把助手会话本身交出去。
129
+ mount('隧道更新暂停口', () => ctx.reflect.provide('dshMobileTailcatCtl', door));
125
130
  return door;
126
131
  }
127
132
 
@@ -1,4 +1,7 @@
1
1
  /** 更新后核对插件依赖,失败时通过原包管理器恢复上一版完整安装。 */
2
+ /**
3
+ * 失败结论里给「文件被占用」附一句能照着做的提示:手机与面板只显示这一句话。
4
+ */
2
5
  'use strict';
3
6
 
4
7
  /**
@@ -519,7 +522,12 @@ function withReason(message, output) {
519
522
  if (lines.length === 0) return message;
520
523
  const marked = lines.filter(line => /ERR_PNPM|ERROR/.test(line));
521
524
  const reason = (marked.length > 0 ? marked : lines.slice(-1)).slice(0, 3).join('\n').slice(0, 600);
522
- return reason === '' ? message : `${message}\n${reason}`;
525
+ if (reason === '') return message;
526
+ // 文件被占用是最常见的「装不上、连恢复旧版也一起失败」:给一句能照着做的,别只丢一段日志。
527
+ const hint = /EPERM|EBUSY|operation not permitted/i.test(String(output || ''))
528
+ ? '文件被占用(隧道助手或杀毒软件占着),退出 DSH 再更新一次。\n'
529
+ : '';
530
+ return `${message}\n${hint}${reason}`;
523
531
  }
524
532
 
525
533
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mobile-plugin",
3
- "version": "0.5.73",
3
+ "version": "0.5.75",
4
4
  "description": "Mobile API (/api/mobile/v1) and relay client for the DSH mobile app — desktop profile build (dsh 0.2.x, peers resolved by the host)",
5
5
  "license": "MIT",
6
6
  "icon": "./icon.png",