dsh-mobile-plugin 0.5.72 → 0.5.74
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/docs/extension-authoring.md +55 -16
- package/lib/impl.js +4 -0
- package/lib/index.js +46 -4
- package/lib/mobile/drive-roots.js +45 -14
- package/lib/mobile/workspaces.js +4 -3
- package/lib/panel/index.html +3 -3
- package/lib/relay/control.js +39 -12
- package/lib/relay/core.js +1 -1
- package/lib/remote/controller.cjs +72 -28
- package/lib/remote/local.cjs +7 -2
- package/lib/remote/network.cjs +46 -5
- package/lib/remote/router.cjs +106 -15
- package/lib/remote/routes.cjs +16 -14
- package/lib/remote/shell.cjs +12 -3
- package/lib/shared/route-channels.cjs +19 -0
- package/lib/tailcat/wiring.cjs +5 -0
- package/lib/update-install.cjs +30 -10
- package/package.json +1 -1
package/lib/remote/routes.cjs
CHANGED
|
@@ -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'
|
|
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:
|
|
103
|
+
message: REMOTE_ERROR_TEXT[code] || REMOTE_ERROR_FALLBACK } });
|
|
102
104
|
}
|
|
103
105
|
};
|
|
104
106
|
}
|
package/lib/remote/shell.cjs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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() };
|
package/lib/tailcat/wiring.cjs
CHANGED
|
@@ -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
|
|
package/lib/update-install.cjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
/** 更新后核对插件依赖,失败时通过原包管理器恢复上一版完整安装。 */
|
|
2
|
+
/**
|
|
3
|
+
* 失败结论里给「文件被占用」附一句能照着做的提示:手机与面板只显示这一句话。
|
|
4
|
+
*/
|
|
2
5
|
'use strict';
|
|
3
6
|
|
|
4
7
|
/**
|
|
@@ -222,16 +225,26 @@ function installationProblem(profileNodeModules, name, version) {
|
|
|
222
225
|
}
|
|
223
226
|
}
|
|
224
227
|
|
|
228
|
+
/** 声明里写的是不是精确版本(`1.1.4` / `1.1.4-rc.1`),不是范围、标签或 git/url。 */
|
|
229
|
+
function exactDeclaredVersion(spec) {
|
|
230
|
+
if (typeof spec !== 'string') return null;
|
|
231
|
+
const trimmed = spec.trim();
|
|
232
|
+
return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(trimmed) ? trimmed : null;
|
|
233
|
+
}
|
|
234
|
+
|
|
225
235
|
/**
|
|
226
|
-
*
|
|
236
|
+
* 这次装完后,插件声明的可选依赖(例如 tailcat 平台包)各自要登记进排除清单的版本。
|
|
227
237
|
*
|
|
228
238
|
* 它们和插件本体一样可能刚发布就被装进来,登记排除清单时要一并写 —— 否则这些包自己的
|
|
229
|
-
* 锁条目会把后续的安装挡在 24
|
|
230
|
-
*
|
|
239
|
+
* 锁条目会把后续的安装挡在 24 小时冷却窗口里。**必须按声明补齐所有平台**:pnpm 11 在任何
|
|
240
|
+
* add / remove 之前校验的是**整份 lockfile**,lockfile 锁了全部 os / cpu 变体,所以
|
|
241
|
+
* 「os / cpu 不匹配、没落到盘上」的平台包,其锁条目照样参与校验 —— 跳过安装不等于跳过校验。
|
|
231
242
|
*
|
|
232
|
-
*
|
|
243
|
+
* 版本取值:声明里是精确版本就直接用(本项目这些平台包就钉死版本);写的是范围之类解析不出的,
|
|
244
|
+
* 退回读实际装上的那份;两样都拿不到就跳过这条,不猜。读不到插件清单也只跳过、不抛 ——
|
|
245
|
+
* 登记是善后,不该把装好的版本说成没装上。
|
|
233
246
|
*/
|
|
234
|
-
function
|
|
247
|
+
function optionalDepsToExclude(profileNodeModules, name = DEFAULT_NAME) {
|
|
235
248
|
const readVersion = (dir) => {
|
|
236
249
|
try {
|
|
237
250
|
const raw = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
|
|
@@ -249,8 +262,10 @@ function installedOptionalDeps(profileNodeModules, name = DEFAULT_NAME) {
|
|
|
249
262
|
}
|
|
250
263
|
if (!optional || typeof optional !== 'object') return out;
|
|
251
264
|
for (const depName of Object.keys(optional)) {
|
|
252
|
-
//
|
|
253
|
-
const version =
|
|
265
|
+
// 精确版本覆盖所有平台(有些平台没装上也照样要登记);范围类才回落到盘上装的那份。
|
|
266
|
+
const version = exactDeclaredVersion(optional[depName])
|
|
267
|
+
// hoisted 布局在 profile/node_modules 顶层;严格布局下在插件自己的 node_modules 里。
|
|
268
|
+
|| readVersion(path.join(profileNodeModules, depName))
|
|
254
269
|
|| readVersion(path.join(profileNodeModules, name, 'node_modules', depName));
|
|
255
270
|
if (version) out.push({ name: depName, version });
|
|
256
271
|
}
|
|
@@ -507,7 +522,12 @@ function withReason(message, output) {
|
|
|
507
522
|
if (lines.length === 0) return message;
|
|
508
523
|
const marked = lines.filter(line => /ERR_PNPM|ERROR/.test(line));
|
|
509
524
|
const reason = (marked.length > 0 ? marked : lines.slice(-1)).slice(0, 3).join('\n').slice(0, 600);
|
|
510
|
-
|
|
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}`;
|
|
511
531
|
}
|
|
512
532
|
|
|
513
533
|
/**
|
|
@@ -785,7 +805,7 @@ async function installLatest({
|
|
|
785
805
|
// 插件按平台带出来的可选依赖(如 tailcat 平台包)也是刚发就可能刚装上的,同批登记,
|
|
786
806
|
// 否则这些包自己的锁条目会把后续安装挡在冷却窗口里。逐条尽力写,失败不影响主结果。
|
|
787
807
|
if (changed) {
|
|
788
|
-
for (const dep of
|
|
808
|
+
for (const dep of optionalDepsToExclude(profileNodeModules, name)) {
|
|
789
809
|
recordReleaseAgeExclusion(profileDir, dep.name, dep.version);
|
|
790
810
|
}
|
|
791
811
|
}
|
|
@@ -931,7 +951,7 @@ module.exports = {
|
|
|
931
951
|
installLatest,
|
|
932
952
|
installLatestIfNeeded,
|
|
933
953
|
installedVersion,
|
|
934
|
-
|
|
954
|
+
optionalDepsToExclude,
|
|
935
955
|
declaredSource,
|
|
936
956
|
// 「Windows 上怎么起包管理器」在本机跑不起来,守卫只能验拼好的那一行,所以这两样露出来。
|
|
937
957
|
cmdInvocation,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mobile-plugin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.74",
|
|
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",
|