dsh-mobile-plugin 0.5.82 → 0.5.83
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/README.md +4 -0
- package/dsh-mobile-credentials/lib/credentials.js +5 -0
- package/lib/client.js +171 -5
- package/lib/frpc/runner.cjs +45 -10
- package/lib/impl.js +25 -28
- package/lib/index.js +1 -1
- package/lib/mobile/approval-memory.js +2 -55
- package/lib/mobile/approvals.js +6 -82
- package/lib/mobile/host-bridge.js +12 -1
- package/lib/mobile/pairing.js +5 -5
- package/lib/mobile/relay-control.js +6 -5
- package/lib/panel/index.html +40 -22
- package/lib/relay/config-store.js +4 -6
- package/lib/relay/control.js +41 -10
- package/lib/relay/core.js +47 -5
- package/lib/relay/lan-discovery.cjs +22 -14
- package/lib/relay/lan-port-policy.cjs +8 -2
- package/lib/relay/lan-proxy.js +3 -5
- package/lib/relay/status.js +4 -7
- package/lib/routes/control-plane.js +16 -36
- package/lib/routes/mobile-api.js +0 -13
- package/lib/shell/updater.js +18 -6
- package/lib/sidecar-facade-worker.cjs +9 -6
- package/package.json +1 -1
- package/lib/mobile/auto-review.js +0 -178
package/README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
<!-- 移动端插件功能、连接设置与开发说明。 -->
|
|
1
2
|
<h3 align="center">AI-HUB 移动端插件</h3>
|
|
2
3
|
|
|
3
4
|

|
|
@@ -55,6 +56,9 @@
|
|
|
55
56
|
### 连接
|
|
56
57
|
|
|
57
58
|
- 两种连法:经 relay v2 隧道从公网连回来,或者同一个 Wi-Fi 下走局域网直连。
|
|
59
|
+
- 局域网默认端口是 **18787**,已有配置沿用保存的端口。占用时先重试原端口;只有所有已配对手机支持局域网发现、且没有固定入口依赖时,才会自动换到可用端口并保存。
|
|
60
|
+
- 使用外部穿透软件时,请在端口设置中开启「固定端口」。插件内的穿透配置和手填固定地址会自动保留端口;端口被占时提示释放占用。自带穿透会等待真实监听就绪,并跟随手动端口变更更新本地目标。
|
|
61
|
+
- 开启地址上报后,插件会把当前地址加密发给总控。APP 前台持续订阅,在地址变化后验证新入口并重新连接;回到前台、目录重连时补取最新快照。仅局域网等明确禁用总控的线路模式仍遵守原有范围。
|
|
58
62
|
- 配对码与配对策略可选,设备凭据能单独吊销,也能一次全撤。
|
|
59
63
|
- iOS 离线推送可选,不配也不影响其它功能。
|
|
60
64
|
|
|
@@ -97,6 +97,11 @@ function readFromDisk() {
|
|
|
97
97
|
} catch {
|
|
98
98
|
records = [];
|
|
99
99
|
}
|
|
100
|
+
// 权限档位已移除:所有设备一律全权。老记录若还带 `permissions` 子集,读到就抹掉
|
|
101
|
+
//(缺 `permissions` = 全权,与权限判定口径一致),下一次写盘即成全权。
|
|
102
|
+
for (const record of records) {
|
|
103
|
+
if (Object.prototype.hasOwnProperty.call(record, 'permissions')) delete record.permissions;
|
|
104
|
+
}
|
|
100
105
|
stamp = statOf();
|
|
101
106
|
rebuildIndex();
|
|
102
107
|
}
|
package/lib/client.js
CHANGED
|
@@ -55,6 +55,9 @@ window.__ModuleLoader__.load({
|
|
|
55
55
|
/* 中间那一档:确实有问题、但还没到「插件坏了」的程度(中转断着、旁挂进程没在跑、
|
|
56
56
|
配了手机却一直没连上)。琥珀色 + 同一颗点,图形与尺寸一样不动。 */
|
|
57
57
|
.dshm_footAction[data-dshm-warn],.dshm_footAction[data-dshm-warn]:hover{color:var(--dsw-alias-state-warning-primary)}
|
|
58
|
+
/* 需要重启 DSH 才能把这次更新的外壳部分用上:那颗入口临时变成「提醒」按钮,
|
|
59
|
+
旁边的电脑图标暂时藏起来,方框里只剩这颗,点它弹一扇说明窗。重启后自动变回来。 */
|
|
60
|
+
.dshm_footerGroup[data-dshm-restart] .dshm_footAction:not([data-dshm-restart-icon]){display:none}
|
|
58
61
|
.dshm_alertDot{display:none}
|
|
59
62
|
.dshm_footAction[data-dshm-alert] .dshm_alertDot,.dshm_footAction[data-dshm-warn] .dshm_alertDot{display:inline}
|
|
60
63
|
.dshm_overlay{position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;padding:clamp(8px,3vh,20px);background:rgba(0,0,0,.42)}
|
|
@@ -465,6 +468,11 @@ window.__ModuleLoader__.load({
|
|
|
465
468
|
iconHidden: '隐藏',
|
|
466
469
|
iconKeepOne: '至少要保留一颗图标',
|
|
467
470
|
iconSaveFailed: '保存图标设置失败',
|
|
471
|
+
restartNoticeButton: '有新版本,需要重启 DSH 生效',
|
|
472
|
+
restartNoticeTitle: '更新已就绪,需要重启一次 DSH',
|
|
473
|
+
restartNoticeBody: '这次更新的实现部分已经生效;其中外壳那部分要重启一次 DSH 才能用上。你正在进行的对话不会因此丢失,可以挑方便的时候再重启。',
|
|
474
|
+
restartNoticeHint: '重启方式:把 DSH 完整退出(不是只关窗口)再打开一次。',
|
|
475
|
+
restartNoticeClose: '知道了',
|
|
468
476
|
panelPending: '正在读取页面地址…',
|
|
469
477
|
panelMissing: '宿主还没给出页面地址,稍后再打开这一页试试。',
|
|
470
478
|
loadFailed: '读取宿主状态失败',
|
|
@@ -550,6 +558,11 @@ window.__ModuleLoader__.load({
|
|
|
550
558
|
iconHidden: 'Hidden',
|
|
551
559
|
iconKeepOne: 'Keep at least one icon',
|
|
552
560
|
iconSaveFailed: 'Could not save icon settings',
|
|
561
|
+
restartNoticeButton: 'Update installed — restart DSH to finish',
|
|
562
|
+
restartNoticeTitle: 'Update ready — restart DSH once',
|
|
563
|
+
restartNoticeBody: 'The implementation part of this update is already live; the shell part needs one DSH restart to take effect. Your running conversations are safe — restart whenever it suits you.',
|
|
564
|
+
restartNoticeHint: 'To restart: quit DSH completely (not just the window) and open it again.',
|
|
565
|
+
restartNoticeClose: 'Got it',
|
|
553
566
|
panelPending: 'Reading the page address…',
|
|
554
567
|
panelMissing: 'The host has not reported a page address yet — reopen this item in a moment.',
|
|
555
568
|
loadFailed: 'Failed to read host status',
|
|
@@ -974,6 +987,9 @@ window.__ModuleLoader__.load({
|
|
|
974
987
|
// 不多打一次接口 —— 那份读数本来就是「此刻这台宿主怎么样」。
|
|
975
988
|
devices: value.devices && typeof value.devices === 'object' ? value.devices : null,
|
|
976
989
|
fault: faultKeyOf(value),
|
|
990
|
+
// 盘上的外壳跟跑着的不一样:这次更新动了外壳,要重启一次 DSH 才生效(见 `/api/relay/status`)。
|
|
991
|
+
// 侧栏那颗入口据此临时换成「需要重启」的提醒。
|
|
992
|
+
shellChanged: value.shellChanged === true,
|
|
977
993
|
};
|
|
978
994
|
}
|
|
979
995
|
|
|
@@ -1204,6 +1220,19 @@ window.__ModuleLoader__.load({
|
|
|
1204
1220
|
/** 两颗图标那只方框的记号与类名:谁先落位谁造盒子,另一颗认记号挂进来。 */
|
|
1205
1221
|
const GROUP_MARK = 'data-dshm-footer-group';
|
|
1206
1222
|
const GROUP_CLASS = 'dshm_footerGroup';
|
|
1223
|
+
/** 需要重启时挂在方框上的记号(CSS 据此藏起旁边那颗电脑图标)与那颗「提醒」按钮自己的记号。 */
|
|
1224
|
+
const RESTART_GROUP_ATTR = 'data-dshm-restart';
|
|
1225
|
+
const RESTART_ICON_ATTR = 'data-dshm-restart-icon';
|
|
1226
|
+
/**
|
|
1227
|
+
* 「需要重启」那颗图标(循环箭头那一款):与手机/电脑同一套 24 画布描边。
|
|
1228
|
+
* 它不是入口,是一声提醒——点开弹一扇说明窗,告诉用户装好了但要重启一次 DSH。
|
|
1229
|
+
*/
|
|
1230
|
+
const RESTART_PATHS = [
|
|
1231
|
+
'M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8',
|
|
1232
|
+
'M21 3v5h-5',
|
|
1233
|
+
'M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16',
|
|
1234
|
+
'M8 16H3v5',
|
|
1235
|
+
];
|
|
1207
1236
|
|
|
1208
1237
|
/** 造一颗手机图标(含那颗常驻的告警红点,显不显示看 `data-dshm-alert`)。文档没有 SVG 能力时返回 null,按钮照样成立(只剩无障碍名字)。 */
|
|
1209
1238
|
function phoneIcon(doc, size) {
|
|
@@ -1255,6 +1284,35 @@ window.__ModuleLoader__.load({
|
|
|
1255
1284
|
return svg;
|
|
1256
1285
|
}
|
|
1257
1286
|
|
|
1287
|
+
/** 造「需要重启」那颗图标:循环箭头 + 右上角那颗告警红点(琥珀色由 `data-dshm-warn` 给)。 */
|
|
1288
|
+
function restartIcon(doc, size) {
|
|
1289
|
+
if (!doc || typeof doc.createElementNS !== 'function') return null;
|
|
1290
|
+
const svg = doc.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
1291
|
+
svg.setAttribute('viewBox', '0 0 24 24');
|
|
1292
|
+
svg.setAttribute('width', String(size));
|
|
1293
|
+
svg.setAttribute('height', String(size));
|
|
1294
|
+
svg.setAttribute('fill', 'none');
|
|
1295
|
+
svg.setAttribute('stroke', 'currentColor');
|
|
1296
|
+
svg.setAttribute('stroke-width', '1.7');
|
|
1297
|
+
svg.setAttribute('stroke-linecap', 'round');
|
|
1298
|
+
svg.setAttribute('stroke-linejoin', 'round');
|
|
1299
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
1300
|
+
svg.setAttribute('focusable', 'false');
|
|
1301
|
+
for (const d of RESTART_PATHS) {
|
|
1302
|
+
const path = doc.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
1303
|
+
path.setAttribute('d', d);
|
|
1304
|
+
svg.appendChild(path);
|
|
1305
|
+
}
|
|
1306
|
+
const dot = doc.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
1307
|
+
dot.setAttribute('class', 'dshm_alertDot');
|
|
1308
|
+
dot.setAttribute('cx', String(PHONE_ALERT_DOT.cx));
|
|
1309
|
+
dot.setAttribute('cy', String(PHONE_ALERT_DOT.cy));
|
|
1310
|
+
dot.setAttribute('r', String(PHONE_ALERT_DOT.r));
|
|
1311
|
+
dot.setAttribute('fill', 'currentColor');
|
|
1312
|
+
svg.appendChild(dot);
|
|
1313
|
+
return svg;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1258
1316
|
/** 造那一颗手机按钮:28 点,与同一行里那几颗图标按钮同尺寸。 */
|
|
1259
1317
|
function createFooterIcon(doc) {
|
|
1260
1318
|
const anchor = doc.createElement('a');
|
|
@@ -1306,6 +1364,27 @@ window.__ModuleLoader__.load({
|
|
|
1306
1364
|
node.onclick = onClick;
|
|
1307
1365
|
}
|
|
1308
1366
|
|
|
1367
|
+
/**
|
|
1368
|
+
* 按「要不要重启」把方框里那颗按钮的图形换掉:正常是手机图标,需要重启时换成循环箭头。
|
|
1369
|
+
* 只在状态真的变了时才重画图形(每次同步都重建会闪)。
|
|
1370
|
+
*/
|
|
1371
|
+
function applyFootGlyph(doc, node, pending) {
|
|
1372
|
+
if (!node || node.__dshmPending === pending) return;
|
|
1373
|
+
node.__dshmPending = pending;
|
|
1374
|
+
for (const child of Array.from(node.children || [])) {
|
|
1375
|
+
if (child && typeof child.remove === 'function') child.remove();
|
|
1376
|
+
}
|
|
1377
|
+
if (pending) {
|
|
1378
|
+
node.setAttribute(RESTART_ICON_ATTR, '');
|
|
1379
|
+
const icon = restartIcon(doc, PHONE_GLYPH_WIDE);
|
|
1380
|
+
if (icon) node.appendChild(icon);
|
|
1381
|
+
} else {
|
|
1382
|
+
node.removeAttribute(RESTART_ICON_ATTR);
|
|
1383
|
+
const icon = phoneIcon(doc, PHONE_GLYPH_WIDE);
|
|
1384
|
+
if (icon) node.appendChild(icon);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1309
1388
|
/**
|
|
1310
1389
|
* 在设置那一行找(或造)那只包住两颗图标的方框,紧跟头像出口。
|
|
1311
1390
|
*
|
|
@@ -1401,6 +1480,71 @@ window.__ModuleLoader__.load({
|
|
|
1401
1480
|
* **打不开的时候不许「点了没反应」**:一律弹诊断窗——宿主与外壳各说了什么、用户自己
|
|
1402
1481
|
* 能做的几步检查、能一键试的修复(重新装载 / 重读状态),以及一段可复制的读数。
|
|
1403
1482
|
*/
|
|
1483
|
+
/**
|
|
1484
|
+
* 「需要重启」的说明窗:一个常规应用内弹窗(复用与控制台同一套 `dshm_overlay`/`dshm_dialog`
|
|
1485
|
+
* 样式,不是另开网页),说清这次更新装好了、外壳那部分要重启一次 DSH 才生效、正在进行的
|
|
1486
|
+
* 对话不会丢,只放一颗「知道了」。**不做任何重启动作**——只是提醒,什么时候重启由用户定。
|
|
1487
|
+
*/
|
|
1488
|
+
function openRestartNotice(t) {
|
|
1489
|
+
if (typeof document === 'undefined' || !document.body) return;
|
|
1490
|
+
const doc = document;
|
|
1491
|
+
// 同一页面只留一份:反复点不叠窗。
|
|
1492
|
+
let existing = null;
|
|
1493
|
+
try {
|
|
1494
|
+
existing = typeof doc.querySelector === 'function' ? doc.querySelector('[data-dshm-restart-notice]') : null;
|
|
1495
|
+
} catch {
|
|
1496
|
+
existing = null;
|
|
1497
|
+
}
|
|
1498
|
+
if (existing) return;
|
|
1499
|
+
const overlay = doc.createElement('div');
|
|
1500
|
+
overlay.className = 'dshm_overlay';
|
|
1501
|
+
overlay.setAttribute('data-dshm-restart-notice', '');
|
|
1502
|
+
overlay.setAttribute('role', 'dialog');
|
|
1503
|
+
overlay.setAttribute('aria-modal', 'true');
|
|
1504
|
+
const card = doc.createElement('div');
|
|
1505
|
+
card.className = 'dshm_dialog';
|
|
1506
|
+
const title = doc.createElement('h3');
|
|
1507
|
+
title.className = 'dshm_dialogTitle';
|
|
1508
|
+
title.textContent = t('restartNoticeTitle');
|
|
1509
|
+
const lead = doc.createElement('p');
|
|
1510
|
+
lead.className = 'dshm_dialogLead';
|
|
1511
|
+
lead.textContent = t('restartNoticeBody');
|
|
1512
|
+
const hint = doc.createElement('p');
|
|
1513
|
+
hint.className = 'dshm_dialogNote';
|
|
1514
|
+
hint.textContent = t('restartNoticeHint');
|
|
1515
|
+
const actions = doc.createElement('div');
|
|
1516
|
+
actions.className = 'dshm_dialogActions';
|
|
1517
|
+
const ok = doc.createElement('button');
|
|
1518
|
+
ok.className = 'dshm_btn dshm_btnPrimary';
|
|
1519
|
+
ok.setAttribute('type', 'button');
|
|
1520
|
+
ok.textContent = t('restartNoticeClose');
|
|
1521
|
+
let escape = null;
|
|
1522
|
+
const close = () => {
|
|
1523
|
+
try { if (overlay.parentElement) overlay.remove(); } catch { /* ignore */ }
|
|
1524
|
+
if (escape && typeof doc.removeEventListener === 'function') doc.removeEventListener('keydown', escape);
|
|
1525
|
+
};
|
|
1526
|
+
ok.onclick = close;
|
|
1527
|
+
overlay.addEventListener('click', (event) => {
|
|
1528
|
+
if (event && event.target === overlay) close();
|
|
1529
|
+
});
|
|
1530
|
+
card.addEventListener('click', (event) => {
|
|
1531
|
+
if (event && typeof event.stopPropagation === 'function') event.stopPropagation();
|
|
1532
|
+
});
|
|
1533
|
+
if (typeof doc.addEventListener === 'function') {
|
|
1534
|
+
escape = (event) => {
|
|
1535
|
+
if (event && (event.key === 'Escape' || event.key === 'Esc')) close();
|
|
1536
|
+
};
|
|
1537
|
+
doc.addEventListener('keydown', escape);
|
|
1538
|
+
}
|
|
1539
|
+
actions.appendChild(ok);
|
|
1540
|
+
card.appendChild(title);
|
|
1541
|
+
card.appendChild(lead);
|
|
1542
|
+
card.appendChild(hint);
|
|
1543
|
+
card.appendChild(actions);
|
|
1544
|
+
overlay.appendChild(card);
|
|
1545
|
+
doc.body.appendChild(overlay);
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1404
1548
|
function MobileWebEntry({ wide, t }) {
|
|
1405
1549
|
/** null = 还没问到;'' = 问到了但宿主没给地址(老版本或还没起来)。 */
|
|
1406
1550
|
const [url, setUrl] = useState(null);
|
|
@@ -1413,6 +1557,8 @@ window.__ModuleLoader__.load({
|
|
|
1413
1557
|
const [fault, setFault] = useState('');
|
|
1414
1558
|
/** 标题上那句「现在什么情况」(几台设备、多久没连过);读不到现场时是空串。 */
|
|
1415
1559
|
const [hint, setHint] = useState('');
|
|
1560
|
+
/** 盘上外壳改过、要重启一次 DSH 才生效:这时这颗入口临时变成「需要重启」的提醒。 */
|
|
1561
|
+
const [restartPending, setRestartPending] = useState(false);
|
|
1416
1562
|
/** 展开态是否已经插进设置那一行。插不上就自己占一行。 */
|
|
1417
1563
|
const [anchored, setAnchored] = useState(true);
|
|
1418
1564
|
/** 用户在设置卡上有没有把这颗收起来;收起来时连插入的 DOM 一起撤掉。 */
|
|
@@ -1434,6 +1580,8 @@ window.__ModuleLoader__.load({
|
|
|
1434
1580
|
const pendingLabel = t('footerPending');
|
|
1435
1581
|
const loadMissingLabel = t('footerLoadMissing');
|
|
1436
1582
|
const publicConfirm = t('footerPublicConfirm');
|
|
1583
|
+
/** 「需要重启」那颗按钮的无障碍名字/悬停提示。 */
|
|
1584
|
+
const restartLabel = t('restartNoticeButton');
|
|
1437
1585
|
/**
|
|
1438
1586
|
* 宿主那一半没装载(`/status` 404):点了也打不开、重装前谁也修不好,所以这一种是
|
|
1439
1587
|
* **真故障**,那颗图标转红告警;标题也换成更具体的那一句。地址只是还没读到(后台
|
|
@@ -1467,6 +1615,7 @@ window.__ModuleLoader__.load({
|
|
|
1467
1615
|
setFault(summary.fault);
|
|
1468
1616
|
setHint(hintOf(summary));
|
|
1469
1617
|
setProblem(null);
|
|
1618
|
+
setRestartPending(summary.shellChanged === true);
|
|
1470
1619
|
return { ok: true, status: view };
|
|
1471
1620
|
} catch (error) {
|
|
1472
1621
|
const failed = {
|
|
@@ -1477,6 +1626,7 @@ window.__ModuleLoader__.load({
|
|
|
1477
1626
|
// 读不到现场就把那句话撤掉:留着上一轮那句「2 台设备 · 3 分钟前」会让人以为
|
|
1478
1627
|
// 现场还是那样,而其实这一刻我们什么都不知道。
|
|
1479
1628
|
setHint('');
|
|
1629
|
+
setRestartPending(false);
|
|
1480
1630
|
return { ok: false, problem: failed };
|
|
1481
1631
|
}
|
|
1482
1632
|
}
|
|
@@ -1509,6 +1659,7 @@ window.__ModuleLoader__.load({
|
|
|
1509
1659
|
* 那种情况每开一次页面都会出现,一有它就变脸等于天天报假警。
|
|
1510
1660
|
*/
|
|
1511
1661
|
function footerState() {
|
|
1662
|
+
if (restartPending) return { tone: 'warn', label: restartLabel };
|
|
1512
1663
|
if (hostMissing) return { tone: 'error', label: loadMissingLabel };
|
|
1513
1664
|
if (fault) return { tone: 'warn', label: hint ? `${t(fault)} · ${openLabel}` : openLabel };
|
|
1514
1665
|
if (!url) return { tone: '', label: pendingLabel };
|
|
@@ -1901,7 +2052,20 @@ window.__ModuleLoader__.load({
|
|
|
1901
2052
|
// 其余 = 还没就绪),有地址时说现场(几台设备、多久没连过、链路有没有报错)。
|
|
1902
2053
|
const sync = () => {
|
|
1903
2054
|
const state = footerState();
|
|
1904
|
-
|
|
2055
|
+
// 需要重启时这颗不做入口,改成「提醒」:点开弹说明窗,别让人以为还能当链接点走。
|
|
2056
|
+
const onClick = restartPending ? () => openRestartNotice(t) : openPanel;
|
|
2057
|
+
syncFooterIcon(node, { href: restartPending ? '' : url, label: state.label, onClick, tone: state.tone });
|
|
2058
|
+
applyFootGlyph(doc, node, restartPending);
|
|
2059
|
+
// 方框上的记号改由这颗同步:置上它,旁边的电脑图标由 CSS 暂时藏起,方框里只剩提醒。
|
|
2060
|
+
const group = node.parentElement;
|
|
2061
|
+
try {
|
|
2062
|
+
if (group && typeof group.getAttribute === 'function' && group.getAttribute(GROUP_MARK) !== null) {
|
|
2063
|
+
if (restartPending) group.setAttribute(RESTART_GROUP_ATTR, '');
|
|
2064
|
+
else group.removeAttribute(RESTART_GROUP_ATTR);
|
|
2065
|
+
}
|
|
2066
|
+
} catch {
|
|
2067
|
+
// 认不出方框就还原成两颗各占位,不因为这一条把图标弄丢。
|
|
2068
|
+
}
|
|
1905
2069
|
};
|
|
1906
2070
|
let attached = false;
|
|
1907
2071
|
try {
|
|
@@ -1940,16 +2104,17 @@ window.__ModuleLoader__.load({
|
|
|
1940
2104
|
if (frame !== 0 && typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame);
|
|
1941
2105
|
if (typeof node.remove === 'function' && node.parentElement) node.remove();
|
|
1942
2106
|
};
|
|
1943
|
-
}, [wide, visible, url, openLabel, loadMissingLabel, pendingLabel, problem, panelScope, webAccess, hint, fault]);
|
|
2107
|
+
}, [wide, visible, url, openLabel, loadMissingLabel, pendingLabel, problem, panelScope, webAccess, hint, fault, restartPending, restartLabel]);
|
|
1944
2108
|
|
|
1945
2109
|
// 窄条,或者这一版外壳里认不出那一行:自己占一行,入口不能因为认不出位置就消失。
|
|
1946
2110
|
// 收起来的那一颗例外:它这一页里根本不该再有入口。
|
|
1947
2111
|
if (!visible) return null;
|
|
1948
2112
|
if (!wide || !anchored) {
|
|
1949
2113
|
const state = footerState();
|
|
2114
|
+
const glyphPaths = restartPending ? RESTART_PATHS : PHONE_PATHS;
|
|
1950
2115
|
return h('a', {
|
|
1951
2116
|
className: 'dshm_footAction dshm_footActionRail',
|
|
1952
|
-
href: url || undefined,
|
|
2117
|
+
href: restartPending ? undefined : (url || undefined),
|
|
1953
2118
|
target: '_blank',
|
|
1954
2119
|
rel: 'noreferrer',
|
|
1955
2120
|
'aria-label': state.label,
|
|
@@ -1957,7 +2122,8 @@ window.__ModuleLoader__.load({
|
|
|
1957
2122
|
'aria-disabled': 'false',
|
|
1958
2123
|
[FOOTER_ALERT]: state.tone === 'error' ? '' : undefined,
|
|
1959
2124
|
[FOOTER_WARN]: state.tone === 'warn' ? '' : undefined,
|
|
1960
|
-
|
|
2125
|
+
[RESTART_ICON_ATTR]: restartPending ? '' : undefined,
|
|
2126
|
+
onClick: restartPending ? () => openRestartNotice(t) : openPanel,
|
|
1961
2127
|
}, h('svg', {
|
|
1962
2128
|
viewBox: '0 0 24 24',
|
|
1963
2129
|
width: PHONE_GLYPH_RAIL,
|
|
@@ -1969,7 +2135,7 @@ window.__ModuleLoader__.load({
|
|
|
1969
2135
|
'aria-hidden': 'true',
|
|
1970
2136
|
focusable: 'false',
|
|
1971
2137
|
}, [
|
|
1972
|
-
...
|
|
2138
|
+
...glyphPaths.map((d) => h('path', { key: d, d })),
|
|
1973
2139
|
h('circle', {
|
|
1974
2140
|
key: 'alert',
|
|
1975
2141
|
className: 'dshm_alertDot',
|
package/lib/frpc/runner.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// FRP
|
|
1
|
+
// FRP 等待真实监听端口并跟随运行中变更,异常退出有限重试,主动停止取消待启动工作。
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
/** 本机 frpc 的配置准备、进程起停和服务端分配地址读取。 */
|
|
@@ -100,24 +100,31 @@ function createFrpcRunner(options = {}) {
|
|
|
100
100
|
let retryTimer = null;
|
|
101
101
|
let retries = 0;
|
|
102
102
|
let activeAdminPort = adminPort;
|
|
103
|
+
let requestedLocalPort = 0;
|
|
104
|
+
let runningLocalPort = 0;
|
|
105
|
+
let waitingForPort = false;
|
|
103
106
|
let discovery = null;
|
|
104
107
|
let addressListener = typeof options.onRemoteAddress === 'function' ? options.onRemoteAddress : null;
|
|
105
108
|
const exists = (p) => { try { return fsImpl.existsSync(p); } catch { return false; } };
|
|
106
109
|
const configPath = () => exists(paths.jsonConfig) ? paths.jsonConfig : paths.config;
|
|
107
110
|
const readConfig = () => { try { return fsImpl.readFileSync(configPath(), 'utf8'); } catch { return null; } };
|
|
111
|
+
const localPort = () => {
|
|
112
|
+
const port = Number(portOf());
|
|
113
|
+
return Number.isInteger(port) && port >= 1024 && port <= 65535 ? port : 0;
|
|
114
|
+
};
|
|
108
115
|
|
|
109
116
|
function status() {
|
|
110
117
|
return {
|
|
111
118
|
available: Boolean(binary), running: Boolean(child), pid: child && child.pid ? child.pid : null,
|
|
112
119
|
error, startedAt, configPresent: exists(paths.config) || exists(paths.jsonConfig),
|
|
113
120
|
enabled: exists(paths.enabled), starting: Boolean(starting && !child), retrying: retryTimer !== null,
|
|
114
|
-
remoteAddress: child ? remoteAddress : '',
|
|
121
|
+
waitingForPort, localPort: child ? runningLocalPort : 0, remoteAddress: child ? remoteAddress : '',
|
|
115
122
|
};
|
|
116
123
|
}
|
|
117
124
|
|
|
118
|
-
function writeRunConfig(text) {
|
|
125
|
+
function writeRunConfig(text, port = localPort()) {
|
|
119
126
|
if (isIniConfig(text)) throw new Error('旧 INI 格式不能运行,请让服务商提供 TOML 或 JSON 配置');
|
|
120
|
-
const prepared = withAdminPort(alignLocalPort(text,
|
|
127
|
+
const prepared = withAdminPort(alignLocalPort(text, port), adminPort);
|
|
121
128
|
const json = prepared.trimStart().startsWith('{');
|
|
122
129
|
const target = json ? paths.jsonConfig : paths.config;
|
|
123
130
|
fsImpl.mkdirSync(paths.dir, { recursive: true });
|
|
@@ -196,9 +203,9 @@ function createFrpcRunner(options = {}) {
|
|
|
196
203
|
const run = (async () => {
|
|
197
204
|
const raw = readConfig();
|
|
198
205
|
if (!raw) { error = '还没有导入 frpc 配置'; return; }
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
206
|
+
requestedLocalPort = localPort();
|
|
207
|
+
waitingForPort = requestedLocalPort === 0;
|
|
208
|
+
if (waitingForPort) { error = ''; return; }
|
|
202
209
|
let got;
|
|
203
210
|
try { got = await ensure({}); }
|
|
204
211
|
catch (err) { got = { ok: false, message: err && err.message ? err.message : String(err) }; }
|
|
@@ -208,6 +215,14 @@ function createFrpcRunner(options = {}) {
|
|
|
208
215
|
scheduleRestart();
|
|
209
216
|
return;
|
|
210
217
|
}
|
|
218
|
+
// 获取二进制期间监听可能尚未就绪或已经换号,启动前只取这一刻的实绑端口。
|
|
219
|
+
const port = localPort();
|
|
220
|
+
requestedLocalPort = port;
|
|
221
|
+
waitingForPort = port === 0;
|
|
222
|
+
if (waitingForPort) { error = ''; return; }
|
|
223
|
+
let target;
|
|
224
|
+
try { target = writeRunConfig(raw, port); }
|
|
225
|
+
catch (err) { error = `写 frpc 配置失败:${err && err.message ? err.message : err}`; return; }
|
|
211
226
|
binary = got.path;
|
|
212
227
|
let proc;
|
|
213
228
|
try {
|
|
@@ -218,6 +233,7 @@ function createFrpcRunner(options = {}) {
|
|
|
218
233
|
return;
|
|
219
234
|
}
|
|
220
235
|
child = proc;
|
|
236
|
+
runningLocalPort = port;
|
|
221
237
|
activeAdminPort = adminPortOf(readConfig(), adminPort);
|
|
222
238
|
error = '';
|
|
223
239
|
remoteAddress = '';
|
|
@@ -234,6 +250,7 @@ function createFrpcRunner(options = {}) {
|
|
|
234
250
|
proc.on('close', (code, signal) => {
|
|
235
251
|
if (child !== proc) return;
|
|
236
252
|
child = null;
|
|
253
|
+
runningLocalPort = 0;
|
|
237
254
|
remoteAddress = '';
|
|
238
255
|
const lastLine = tail.trim() ? tail.trim().split('\n').pop() : '';
|
|
239
256
|
error = `frpc 已退出(code=${code}${signal ? `, ${signal}` : ''})${lastLine ? `:${lastLine}` : ''}`;
|
|
@@ -255,22 +272,40 @@ function createFrpcRunner(options = {}) {
|
|
|
255
272
|
return launch();
|
|
256
273
|
}
|
|
257
274
|
|
|
258
|
-
|
|
259
|
-
desired = false;
|
|
275
|
+
function stopProcess() {
|
|
260
276
|
generation += 1;
|
|
261
277
|
if (retryTimer !== null) clearTimer(retryTimer);
|
|
262
278
|
retryTimer = null;
|
|
263
279
|
starting = null;
|
|
264
280
|
const proc = child;
|
|
265
281
|
child = null;
|
|
282
|
+
runningLocalPort = 0;
|
|
266
283
|
remoteAddress = '';
|
|
267
284
|
error = '';
|
|
268
285
|
if (proc) { try { proc.kill('SIGTERM'); } catch { /* 已退出。 */ } }
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** 监听状态变化时同步;不会越过主动停止,也不为同一个端口重启。 */
|
|
289
|
+
async function syncLocalPort() {
|
|
290
|
+
if (!desired) return status();
|
|
291
|
+
const port = localPort();
|
|
292
|
+
if (!port) { waitingForPort = !child; return status(); }
|
|
293
|
+
if (port === requestedLocalPort && !waitingForPort) return status();
|
|
294
|
+
stopProcess();
|
|
295
|
+
retries = 0;
|
|
296
|
+
return launch();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async function stop() {
|
|
300
|
+
desired = false;
|
|
301
|
+
stopProcess();
|
|
302
|
+
requestedLocalPort = 0;
|
|
303
|
+
waitingForPort = false;
|
|
269
304
|
return status();
|
|
270
305
|
}
|
|
271
306
|
|
|
272
307
|
return {
|
|
273
|
-
status, start, stop, saveConfig, discoverRemoteAddress,
|
|
308
|
+
status, start, stop, syncLocalPort, saveConfig, discoverRemoteAddress,
|
|
274
309
|
get runId() { return generation; },
|
|
275
310
|
setAddressListener(listener) {
|
|
276
311
|
addressListener = typeof listener === 'function' ? listener : null;
|
package/lib/impl.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// 每代兼容桥使用独立服务作用域,热重载时新旧两代可同时提供宿主调用。
|
|
2
|
+
// 真实监听状态同步总控和穿透,固定入口约束自动换号。
|
|
1
3
|
// 配置 schema 与投影拆到 lib/relay/config-store.js,装配层只留装配与状态仓外壳(行数兜底)。
|
|
2
4
|
// 装配移动 API、设备吊销与独立直连生命周期,并向本机面板提供真实上报目的地。
|
|
3
5
|
/**
|
|
@@ -39,7 +41,7 @@ const { pairingPayload, pairingText } = require('./relay/pairing-payload.cjs')
|
|
|
39
41
|
// 总控上报客户端:把本机全部连接地址报给总控、拿回设备令牌(见 lib/relay/control.js)。
|
|
40
42
|
const { createControlClient } = require('./relay/control.js')
|
|
41
43
|
const { createIdentityRotator } = require('./relay/identity-rotate.cjs')
|
|
42
|
-
const { createLanPortPolicy } = require('./relay/lan-port-policy.cjs')
|
|
44
|
+
const { createLanPortPolicy, lanPortLockReason } = require('./relay/lan-port-policy.cjs')
|
|
43
45
|
const { mountTailcat } = require('./tailcat/wiring.cjs') // 直连隧道:入口 + 落点代理 + 助手会话 + 启停
|
|
44
46
|
const { mountP2P } = require('./p2p/wiring.cjs') // 点对点隧道:助手会话 + 落点代理(连接从隧道里进来,不必开回环门)
|
|
45
47
|
// FRP 直连:用面板导入的配置拉起本地 frpc(见 lib/frpc/runner.cjs)。
|
|
@@ -53,8 +55,8 @@ const hostWeb = require('./mobile/host-web.js')
|
|
|
53
55
|
// 否则「撤销全部授权」只清了中转侧,同网设备仍能用旧凭据直连宿主。
|
|
54
56
|
// 入口按两条盘上布局分别找(嵌在插件包内 / 与插件包同级),见 shared/credentials-entry.js。
|
|
55
57
|
const credentials = require('./shared/credentials-entry.js').credentialsEntry()
|
|
56
|
-
const { createApiProxy } = require('./mobile/host-bridge.js')
|
|
57
|
-
const { installApprovalBridge, setPushNotifier: setApprovalPushNotifier
|
|
58
|
+
const { createApiProxy, runtimeProvidesApiProxy } = require('./mobile/host-bridge.js')
|
|
59
|
+
const { installApprovalBridge, setPushNotifier: setApprovalPushNotifier } = require('./mobile/approvals.js')
|
|
58
60
|
const { installQuestionBridge, setPushNotifier: setQuestionPushNotifier } = require('./mobile/questions.js')
|
|
59
61
|
const { createPushNotifier } = require('./mobile/push-notify.js')
|
|
60
62
|
const { installNarration } = require('./mobile/narration.js') // 过程播报:默认关,开关真值每步现读
|
|
@@ -181,26 +183,9 @@ function createConfigStore(state) {
|
|
|
181
183
|
// 的 `advertisedCandidates`:那是地址策略,不是装配。这里只把它转交给三处消费点。
|
|
182
184
|
// 「手机上最近来过没有」同理,住在 `./mobile/activity.cjs`(守卫记、控制面状态读)。
|
|
183
185
|
|
|
184
|
-
/**
|
|
185
|
-
* 运行时是否自带 `@deepseek-ai/dsh-host-apiproxy`(`api-gateway` 那个入口)。
|
|
186
|
-
*
|
|
187
|
-
* 从本模块所在位置解析,而不是读 DSH 版本号:桌面端插件装在 profile 的 node_modules 里,
|
|
188
|
-
* 往上碰不到 DSH 的依赖树(在 app.asar 里),解析不到就用兼容桥;无头宿主跑在插件包里,
|
|
189
|
-
* 包内就有整套 `@deepseek-ai/*`,解析得到就用宿主自己那份。解析失败只是「没有」。
|
|
190
|
-
*
|
|
191
|
-
* 模块顶层就被 `export const inject` 用了一次,所以必须是函数声明(提升),不能写成 `const`
|
|
192
|
-
* 箭头函数 —— 那会撞上 TDZ。
|
|
193
|
-
*/
|
|
194
|
-
function runtimeProvidesApiProxy() {
|
|
195
|
-
try {
|
|
196
|
-
require.resolve('@deepseek-ai/dsh-host-apiproxy/package.json')
|
|
197
|
-
return true
|
|
198
|
-
} catch {
|
|
199
|
-
return false
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
186
|
function apply(ctx) {
|
|
187
|
+
const hostContext = ctx
|
|
188
|
+
ctx = ctx.isolate('apiProxy')
|
|
204
189
|
// 0.2.0 删掉了 `apiProxy` 服务(宿主 RPC 全走 ctx.get('typertGateway')),但插件里
|
|
205
190
|
// 17 个移动端模块历史上都是 `ctx.apiProxy.<ns>.<method>({rpcId,method,payload}, signal)`
|
|
206
191
|
// + `{result:{ok,value}|{ok:false,error}}` 这一套。这里在自己的 fiber 上把同形状的
|
|
@@ -246,7 +231,7 @@ function apply(ctx) {
|
|
|
246
231
|
*
|
|
247
232
|
* 三者都只在「宿主这一代没有真 apiProxy」时才装:旧宿主自带真服务,多 provide 一次会让
|
|
248
233
|
* 整棵树加载失败(`service "apiProxy" has been registered at <dsh-mobile-plugin>`)。
|
|
249
|
-
*
|
|
234
|
+
* 兼容服务只在本代作用域可见;蓝绿换代时旧代仍在服务,新代也能独立完成装配。
|
|
250
235
|
*/
|
|
251
236
|
const installCompatBridges = () => {
|
|
252
237
|
mount('apiProxy 兼容桥', () => ctx.reflect.provide('apiProxy', createApiProxy(ctx)))
|
|
@@ -260,7 +245,11 @@ function apply(ctx) {
|
|
|
260
245
|
// 前后就会挂上),到点还没有就当作新版宿主,自己把兼容桥与两条帧桥装上 —— 否则
|
|
261
246
|
// 十几个移动端模块读到的是一个永远不来的服务,手机侧全程静默失败。
|
|
262
247
|
const timer = setTimeout(() => {
|
|
263
|
-
|
|
248
|
+
const hostProxy = hostContext.get('apiProxy')
|
|
249
|
+
if (hostProxy) {
|
|
250
|
+
ctx.reflect.provide('apiProxy', hostProxy)
|
|
251
|
+
return
|
|
252
|
+
}
|
|
264
253
|
warn('等不到宿主的 apiProxy,按新版宿主装配兼容桥')
|
|
265
254
|
installCompatBridges()
|
|
266
255
|
}, API_PROXY_GRACE_MS)
|
|
@@ -290,7 +279,7 @@ function apply(ctx) {
|
|
|
290
279
|
// relay.json 是这个命名空间的种子。现在由 createConfigStore 直接以 relay.json
|
|
291
280
|
// 为准(见那里的说明与代价)。
|
|
292
281
|
const settings = createConfigStore(state)
|
|
293
|
-
Object.assign(state, settings.get())
|
|
282
|
+
Object.assign(state, settings.get())
|
|
294
283
|
// 实例历史密钥(HK)的取值器:缺失时惰性生成并落盘(relay.json 单一真源)。配对响应、
|
|
295
284
|
// `/api/mobile/v1/history-key` 与镜像推送三条路共用这一个入口。
|
|
296
285
|
const getHistoryKey = () => core.ensureHistoryKey(state)
|
|
@@ -299,6 +288,10 @@ function apply(ctx) {
|
|
|
299
288
|
const lanPorts = createLanPortPolicy({ state, saveState: core.saveState })
|
|
300
289
|
const lanPortInUse = lanPorts.port
|
|
301
290
|
const resolveLanPort = lanPorts.resolve
|
|
291
|
+
let syncNetwork = () => {}
|
|
292
|
+
let forwardingConfigured = () => false
|
|
293
|
+
const portLock = () => lanPortLockReason(state, forwardingConfigured())
|
|
294
|
+
const onLanState = lan => { lanPorts.apply(lan); syncNetwork() }
|
|
302
295
|
const advertisedLanPort = () => sidecarLifecycle.getAdvertisedLanPort()
|
|
303
296
|
// 总控上报客户端:把本机全部地址报给总控,拿回设备令牌交给 APP(见 relay/control.js)。
|
|
304
297
|
// 生命周期挂在下面的 effect 上;配置变更由 applyServices → control.sync() 驱动。
|
|
@@ -328,14 +321,14 @@ function apply(ctx) {
|
|
|
328
321
|
// in inactive context",导致重启与配置下发全失败(隧道、frpc、P2P 都起不来)。
|
|
329
322
|
const webPortForSidecar = ctx.webServer.port
|
|
330
323
|
const webHostForSidecar = ctx.webServer.host
|
|
331
|
-
const buildSidecarConfig = (lanPort) => ({ enabled: state.enabled, relayUrl: state.relayUrl, relayUrls: core.relayAddressesOf(state).relayUrls, instanceId: state.instanceId, previousInstanceId: state.previousInstanceId || '', pairingCode: state.pairingCode, pairingTicket: state.pairingTicket || '', pairingTier: permissions.isKnownTier(state.pairingTier) ? state.pairingTier : permissions.DEFAULT_TIER, name: state.name, upstreamPort: webPortForSidecar, upstreamHost: webHostForSidecar, lanPort, lanEnabled: effectiveLanEnabled(), lanSecret: state.lanSecret, registerSecret: state.registerSecret })
|
|
324
|
+
const buildSidecarConfig = (lanPort) => ({ enabled: state.enabled, relayUrl: state.relayUrl, relayUrls: core.relayAddressesOf(state).relayUrls, instanceId: state.instanceId, previousInstanceId: state.previousInstanceId || '', pairingCode: state.pairingCode, pairingTicket: state.pairingTicket || '', pairingTier: permissions.isKnownTier(state.pairingTier) ? state.pairingTier : permissions.DEFAULT_TIER, name: state.name, upstreamPort: webPortForSidecar, upstreamHost: webHostForSidecar, lanPort, lanPortLockReason: portLock(), lanEnabled: effectiveLanEnabled(), lanSecret: state.lanSecret, registerSecret: state.registerSecret })
|
|
332
325
|
let hostedSidecar = null
|
|
333
326
|
try { hostedSidecar = typeof ctx.get === 'function' ? ctx.get('dshMobileSidecarHost') || null : null } catch { hostedSidecar = null }
|
|
334
327
|
const sidecarLifecycle = hostedSidecar || createSidecarLifecycle({
|
|
335
328
|
ctx,
|
|
336
329
|
lanPortInUse,
|
|
337
330
|
resolveLanPort,
|
|
338
|
-
onLanState
|
|
331
|
+
onLanState,
|
|
339
332
|
// 本代实现所在的 lib/。默认值能推对,但代际目录里那份推出来的是它自己,
|
|
340
333
|
// 显式传入能让「re-fork 前清的是不是正在跑的那份缓存」不依赖巧合。
|
|
341
334
|
pluginLibDir: path.dirname(fileURLToPath(import.meta.url)),
|
|
@@ -354,7 +347,7 @@ function apply(ctx) {
|
|
|
354
347
|
buildConfig: buildSidecarConfig,
|
|
355
348
|
lanPortInUse,
|
|
356
349
|
resolveLanPort,
|
|
357
|
-
onLanState
|
|
350
|
+
onLanState,
|
|
358
351
|
pluginLibDir: path.dirname(fileURLToPath(import.meta.url)),
|
|
359
352
|
})
|
|
360
353
|
}
|
|
@@ -480,6 +473,7 @@ function apply(ctx) {
|
|
|
480
473
|
getP2P: () => (p2p ? p2p.status() : null),
|
|
481
474
|
// 总控上报当前状态(地址、令牌、连没连上):手机据此知道该不该、能不能去总控查。
|
|
482
475
|
getControl: () => control.snapshot(),
|
|
476
|
+
getLanPortLock: portLock,
|
|
483
477
|
})
|
|
484
478
|
function applyServices() {
|
|
485
479
|
control.sync()
|
|
@@ -508,6 +502,9 @@ function apply(ctx) {
|
|
|
508
502
|
let frpHost = null
|
|
509
503
|
try { frpHost = typeof ctx.get === 'function' ? ctx.get('dshMobileTransportFrp') || null : null } catch { frpHost = null }
|
|
510
504
|
const frpRunner = frpHost && frpHost.runner ? frpHost.runner : createFrpcRunner({ portOf: advertisedLanPort })
|
|
505
|
+
forwardingConfigured = () => frpRunner.shouldAutoStart()
|
|
506
|
+
syncNetwork = () => { control.sync(); void frpRunner.syncLocalPort?.().catch(warn) }
|
|
507
|
+
syncNetwork()
|
|
511
508
|
if (frpHost && typeof frpHost.setPortProvider === 'function') frpHost.setPortProvider(advertisedLanPort)
|
|
512
509
|
mount('frpc 公网地址', () => ctx.effect(() => {
|
|
513
510
|
if (typeof frpRunner.setAddressListener !== 'function') return () => {}
|
package/lib/index.js
CHANGED
|
@@ -136,7 +136,7 @@ export function apply(ctx) {
|
|
|
136
136
|
async function applyUpdate(options = {}) {
|
|
137
137
|
const { force = false, auto = false } = options
|
|
138
138
|
try {
|
|
139
|
-
const result = await updater.performUpdate({ runtime, base, hostService, updateState, force, auto, log, beforeInstall: snapshotRunning })
|
|
139
|
+
const result = await updater.performUpdate({ runtime, base, hostService, updateState, force, auto, log, beforeInstall: snapshotRunning, runningShellHash })
|
|
140
140
|
// 换过去了:新代自己挂了隧道,别再起一个助手占端口。没换过去:这里把旧的拉回来。
|
|
141
141
|
if (result?.swapped) tailcatPaused = false
|
|
142
142
|
else await resumeTailcat()
|