dsh-mobile-plugin 0.5.81 → 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.
Files changed (67) hide show
  1. package/README.md +4 -0
  2. package/dsh-mobile-credentials/lib/credentials.js +5 -0
  3. package/lib/client.js +171 -5
  4. package/lib/frpc/provision.cjs +21 -17
  5. package/lib/frpc/runner.cjs +231 -168
  6. package/lib/impl.js +77 -107
  7. package/lib/index.js +1 -1
  8. package/lib/mirror/pusher.cjs +60 -10
  9. package/lib/mobile/approval-memory.js +2 -55
  10. package/lib/mobile/approvals.js +6 -82
  11. package/lib/mobile/events.js +2 -1
  12. package/lib/mobile/feedback.js +6 -5
  13. package/lib/mobile/file-read.js +4 -2
  14. package/lib/mobile/host-bridge.js +12 -1
  15. package/lib/mobile/mux.js +148 -21
  16. package/lib/mobile/paired-devices.js +2 -1
  17. package/lib/mobile/pairing.js +8 -7
  18. package/lib/mobile/relay-control.js +33 -38
  19. package/lib/mobile/session-changes.js +8 -2
  20. package/lib/mobile/session-delivery.js +5 -1
  21. package/lib/mobile/session-file.js +46 -25
  22. package/lib/mobile/session-head.js +7 -3
  23. package/lib/mobile/session-snapshot.js +5 -1
  24. package/lib/mobile/session-step.js +13 -7
  25. package/lib/mobile/session-stop-summary.js +6 -1
  26. package/lib/mobile/stream-registry.js +48 -53
  27. package/lib/mobile/stream.js +17 -2
  28. package/lib/mobile/uploads.js +190 -163
  29. package/lib/p2p/session.cjs +169 -70
  30. package/lib/p2p/wiring.cjs +4 -2
  31. package/lib/panel/index.html +44 -24
  32. package/lib/relay/blob-upload.cjs +103 -0
  33. package/lib/relay/config-store.js +79 -0
  34. package/lib/relay/control.js +131 -52
  35. package/lib/relay/core.js +55 -17
  36. package/lib/relay/lan-discovery.cjs +22 -14
  37. package/lib/relay/lan-port-policy.cjs +8 -2
  38. package/lib/relay/lan-proxy.js +47 -12
  39. package/lib/relay/pairing-payload.cjs +14 -5
  40. package/lib/relay/preview-webapp.cjs +150 -0
  41. package/lib/relay/preview.js +35 -8
  42. package/lib/relay/protocol.js +6 -4
  43. package/lib/relay/relay-probe.js +112 -21
  44. package/lib/relay/status.js +4 -7
  45. package/lib/relay/tunnel-forwarder.cjs +4 -2
  46. package/lib/relay/tunnel.js +39 -8
  47. package/lib/remote/controller.cjs +33 -3
  48. package/lib/remote/host-control.cjs +11 -2
  49. package/lib/remote/router.cjs +83 -33
  50. package/lib/remote/transport.cjs +32 -5
  51. package/lib/remote/tunnel-helper.cjs +51 -25
  52. package/lib/remote/tunnels.cjs +27 -3
  53. package/lib/routes/control-plane.js +41 -53
  54. package/lib/routes/mobile-api.js +21 -31
  55. package/lib/shared/fresh-request.js +32 -1
  56. package/lib/shared/route-order.cjs +118 -132
  57. package/lib/shared/sse-write.js +29 -10
  58. package/lib/shared/via-header.js +5 -12
  59. package/lib/shell/transport-host.js +9 -1
  60. package/lib/shell/updater.js +18 -6
  61. package/lib/sidecar-facade-worker.cjs +165 -118
  62. package/lib/sidecar-facade.cjs +6 -1
  63. package/lib/sidecar-lifecycle.cjs +6 -2
  64. package/lib/tailcat/host-process.cjs +32 -8
  65. package/lib/tailcat/session.cjs +27 -10
  66. package/package.json +6 -6
  67. 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
  ![AI-HUB:手机和平板上的 DeepSeek Harness 会话界面](https://raw.githubusercontent.com/WNLUO/dsh-mobile-plugin/main/assets/banner.jpg)
@@ -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
- syncFooterIcon(node, { href: url, label: state.label, onClick: openPanel, tone: state.tone });
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
- onClick: openPanel,
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
- ...PHONE_PATHS.map((d) => h('path', { key: d, d })),
2138
+ ...glyphPaths.map((d) => h('path', { key: d, d })),
1973
2139
  h('circle', {
1974
2140
  key: 'alert',
1975
2141
  className: 'dshm_alertDot',
@@ -1,3 +1,4 @@
1
+ // FRP 下载逐源分配预算,响应体同样受时限约束,坏校验不阻断后续镜像。
1
2
  'use strict';
2
3
 
3
4
  // 2026-11-18:下载加国内镜像回退(官方不通自动换源,仍按同一份 sha256 校验),失败文案挖出 cause 真话。
@@ -260,18 +261,18 @@ async function downloadTo({ url, asset, dir, fetchImpl, timeoutMs = DOWNLOAD_TIM
260
261
  if (typeof doFetch !== 'function') throw codedError('no-fetch', '当前环境没有可用的 fetch');
261
262
  const controller = typeof AbortController === 'function' ? new AbortController() : null;
262
263
  const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;
263
- let response;
264
+ let buffer;
264
265
  try {
265
- response = await doFetch(url, controller ? { signal: controller.signal } : {});
266
+ const response = await doFetch(url, controller ? { signal: controller.signal } : {});
267
+ if (!response || response.ok !== true) {
268
+ throw new Error(`HTTP ${response ? response.status : '无响应'}`);
269
+ }
270
+ buffer = Buffer.from(await response.arrayBuffer());
266
271
  } catch (error) {
267
272
  throw codedError('download-failed', `下载 frpc 失败:${fetchErrorMessage(error)}`);
268
273
  } finally {
269
274
  if (timer) clearTimeout(timer);
270
275
  }
271
- if (!response || response.ok !== true) {
272
- throw codedError('download-failed', `下载 frpc 失败:HTTP ${response ? response.status : '无响应'}`);
273
- }
274
- const buffer = Buffer.from(await response.arrayBuffer());
275
276
  const got = sha256Hex(buffer);
276
277
  if (asset.sha256 && got !== asset.sha256) {
277
278
  throw codedError('checksum', `frpc 校验失败:下载内容的 sha256 与预期不一致(预期 ${asset.sha256},实际 ${got})`);
@@ -379,17 +380,18 @@ async function ensureFrpc(options = {}) {
379
380
  const staging = path.join(root, `.staging-${process.pid}-${crypto.randomBytes(6).toString('hex')}`);
380
381
  const bases = baseUrlsOf(options);
381
382
  const attempts = [];
382
- // 整轮回退共用一份时间预算(与过去单源超时相同):否则 GitHub 卡住不吃不吐时,
383
- // 逐源各等满 120 秒会把面板晾八分钟。排在后面的镜像只拿得到「剩下的时间」。
383
+ // 在总预算内给每个剩余源留一份,首源挂起也不能独占整轮。
384
384
  const budgetMs = Number(options.timeoutMs) > 0 ? Number(options.timeoutMs) : DOWNLOAD_TIMEOUT_MS;
385
- const deadline = Date.now() + budgetMs;
385
+ const deadline = performance.now() + budgetMs;
386
+ let lastError = null;
386
387
  try {
387
- for (const base of bases) {
388
- const remaining = deadline - Date.now();
388
+ for (const [index, base] of bases.entries()) {
389
+ const remaining = deadline - performance.now();
389
390
  if (remaining <= 0) break;
391
+ const timeoutMs = Math.max(1, remaining / (bases.length - index));
390
392
  const url = `${String(base).replace(/\/+$/, '')}/${asset.file}`;
391
393
  try {
392
- await downloadTo({ url, asset, dir: staging, fetchImpl: options.fetchImpl, timeoutMs: remaining });
394
+ await downloadTo({ url, asset, dir: staging, fetchImpl: options.fetchImpl, timeoutMs });
393
395
  // 先剔掉可能残留的旧目录,再把暂存目录原子换上。
394
396
  fs.rmSync(dir, { recursive: true, force: true });
395
397
  fs.mkdirSync(path.dirname(dir), { recursive: true });
@@ -397,17 +399,19 @@ async function ensureFrpc(options = {}) {
397
399
  pruneOldVersions(root, version);
398
400
  return { ok: true, path: binaryPath, source: 'downloaded', version, platform };
399
401
  } catch (error) {
402
+ lastError = error;
400
403
  const reason = error && error.message ? error.message : String(error);
401
404
  attempts.push(reason.replace(/^下载 frpc 失败:/, ''));
402
- // 校验不符不是「网络不通」:字节到了却对不上钉死的 sha256,换镜像也是同一份坏包,
403
- // 继续试只会让人以为在尽力。当场拒掉,和过去单源的行为一致。
404
- if (error && error.code === 'checksum') throw error;
405
+ // 本源响应可能是门户页或镜像错误页;后源仍必须通过同一份钉死校验。
406
+ fs.rmSync(staging, { recursive: true, force: true });
405
407
  }
406
408
  }
407
- return fail('download-failed', `下载 frpc 失败:${attempts.length} 个源都不通(${attempts.join(';')})`);
409
+ if (bases.length === 1 && lastError) return fail(lastError.code || 'download-failed', lastError.message || String(lastError));
410
+ return fail('download-failed', `下载 frpc 失败:${attempts.length} 个源均失败(${attempts.join(';')})`);
408
411
  } catch (error) {
409
- fs.rmSync(staging, { recursive: true, force: true });
410
412
  return fail(error && error.code ? error.code : 'download-failed', error && error.message ? error.message : String(error));
413
+ } finally {
414
+ fs.rmSync(staging, { recursive: true, force: true });
411
415
  }
412
416
  });
413
417
  }