dsh-mobile-plugin 0.5.65 → 0.5.67
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 +3 -1
- package/lib/client.js +579 -97
- package/lib/frpc/runner.cjs +12 -6
- package/lib/impl.js +20 -0
- package/lib/mobile/host-bridge/session-model.js +7 -2
- package/lib/mobile/mux.js +231 -0
- package/lib/mobile/permissions.js +3 -0
- package/lib/panel/index.html +12 -13
- package/lib/relay/status.js +5 -1
- package/lib/routes/control-plane.js +17 -10
- package/lib/routes/mobile-api.js +5 -1
- package/lib/shell/updater.js +4 -1
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
* 本机和局域网入口直接访问管理页,公网入口保留两小时窗口。
|
|
5
5
|
*
|
|
6
6
|
* 五件事:桌面侧边栏的展开态与「读过了」报给宿主;手机端的已读回执应用回桌面绿点;
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* 手机),手机上的折叠只存在 App
|
|
7
|
+
* 设置里那一项「移动端」(一张薄卡,一颗「打开配置页面」);在侧边栏最底下那一行挂两颗
|
|
8
|
+
* 图标——手机图标(点一下等于那张卡上的按钮,进控制台)与它右边的电脑图标(进远程电脑页);
|
|
9
|
+
* 聊天嵌入页里按目标打开会话、守住它不被网页端启动时那次「恢复上次会话」顶掉,换目标则在
|
|
10
|
+
* 页面里切过去、不重新加载。方向是单向的(桌面 → 宿主 → 手机),手机上的折叠只存在 App
|
|
11
|
+
* 本地,不写回。
|
|
12
|
+
*
|
|
13
|
+
* 设置卡上另有两颗侧边栏图标(手机 / 电脑)的显示开关:默认全开、至少留一颗,选择写进
|
|
14
|
+
* 插件配置;同一页里两颗图标当场收起或回来,不必等下一次状态轮询。
|
|
11
15
|
*
|
|
12
16
|
* 本文件不经任何构建(package.json 直接收录 lib 下的 .js),所以不能写 JSX,统一用
|
|
13
17
|
* `React.createElement` 的别名 `h`;客户端插件按约定写成惰性工厂,定时器与页签在物化时才起。
|
|
@@ -41,6 +45,10 @@ window.__ModuleLoader__.load({
|
|
|
41
45
|
.dshm_footAction[aria-disabled="true"]{opacity:.45;cursor:default}
|
|
42
46
|
.dshm_footAction[aria-disabled="true"]:hover{background:transparent;color:var(--dsw-alias-label-secondary)}
|
|
43
47
|
.dshm_footActionRail{width:36px;height:36px;margin:2px 0;border-radius:var(--dsw-radius-md)}
|
|
48
|
+
/* 手机与电脑两颗图标合在同一只方框里:一个细边框圈成一组,两颗之间只留 2px 的缝。
|
|
49
|
+
进组后撤掉单颗各自的外边距,否则间距会翻倍、还会把边框撑松。 */
|
|
50
|
+
.dshm_footerGroup{flex:none;display:inline-flex;align-items:center;gap:2px;padding:1px 2px;border:1px solid var(--dsw-alias-settings-card-stroke);border-radius:var(--dsw-radius-md)}
|
|
51
|
+
.dshm_footerGroup .dshm_footAction{margin:0}
|
|
44
52
|
/* 宿主那一半没装载时:整颗转红,右上角那颗红点显出来(data-dshm-alert 是它的记号)。
|
|
45
53
|
悬停不换回普通颜色——告警态跟着鼠标变浅等于这一颗在说谎。 */
|
|
46
54
|
.dshm_footAction[data-dshm-alert],.dshm_footAction[data-dshm-alert]:hover{color:var(--dsw-alias-state-error-primary)}
|
|
@@ -49,10 +57,14 @@ window.__ModuleLoader__.load({
|
|
|
49
57
|
.dshm_footAction[data-dshm-warn],.dshm_footAction[data-dshm-warn]:hover{color:var(--dsw-alias-state-warning-primary)}
|
|
50
58
|
.dshm_alertDot{display:none}
|
|
51
59
|
.dshm_footAction[data-dshm-alert] .dshm_alertDot,.dshm_footAction[data-dshm-warn] .dshm_alertDot{display:inline}
|
|
52
|
-
.dshm_overlay{position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;padding:
|
|
53
|
-
.dshm_dialog{box-sizing:border-box;width:100%;max-width:560px;max-height:82vh;overflow:auto;display:flex;flex-direction:column;gap:10px;padding:18px 20px;border-radius:var(--dsw-radius-xl);border:.5px solid var(--dsw-alias-settings-card-stroke);background:var(--dsw-alias-settings-card-fill);color:var(--dsw-alias-label-primary);box-shadow:0 12px 40px rgba(0,0,0,.28)}
|
|
54
|
-
/*
|
|
55
|
-
|
|
60
|
+
.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)}
|
|
61
|
+
.dshm_dialog{box-sizing:border-box;width:100%;max-width:min(560px,100%);max-height:min(82vh,calc(100vh - 16px));overflow:auto;display:flex;flex-direction:column;gap:10px;padding:18px 20px;border-radius:var(--dsw-radius-xl);border:.5px solid var(--dsw-alias-settings-card-stroke);background:var(--dsw-alias-settings-card-fill);color:var(--dsw-alias-label-primary);box-shadow:0 12px 40px rgba(0,0,0,.28)}
|
|
62
|
+
/* 内容窗(嵌一整页):宽高都自适应——最宽 1040、再宽跟着视口收;高取视口的 88%,
|
|
63
|
+
矮屏上让出遮罩留白。旧版写死 82vh + 1040px,小窗口和大屏都不合适。
|
|
64
|
+
顶部留白收到 6px:窗口按钮已经搬进页面顶栏,外壳这层只留一圈薄边。 */
|
|
65
|
+
.dshm_dialogWide{max-width:min(1040px,100%);height:min(88vh,900px);max-height:calc(100vh - 16px);overflow:hidden;padding:6px;gap:0}
|
|
66
|
+
/* 空的说明行不占位:只有在浏览器被拦这类真要说话时才撑开一行。 */
|
|
67
|
+
.dshm_dialogNote:empty{display:none}
|
|
56
68
|
.dshm_dialogWide .dshm_frameWrap{flex:1;min-height:0;display:flex;position:relative}
|
|
57
69
|
.dshm_frame{flex:1;min-height:0;width:100%;border:0;border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-1)}
|
|
58
70
|
/* 加载提示由内嵌页就绪回执撤掉,不能只凭 iframe load。 */
|
|
@@ -81,6 +93,10 @@ window.__ModuleLoader__.load({
|
|
|
81
93
|
.dshm_btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}
|
|
82
94
|
.dshm_btn:disabled{cursor:default;opacity:.45}
|
|
83
95
|
.dshm_btnPrimary{background:var(--dsw-alias-state-business-primary);border-color:transparent;color:var(--dsw-alias-bg-layer-1)}
|
|
96
|
+
/* 侧边栏图标开关:沿用卡片里的字号与描边,不开第二种控件语言。 */
|
|
97
|
+
.dshm_iconRow{display:flex;align-items:center;justify-content:space-between;gap:12px;font-size:13px;line-height:20px}
|
|
98
|
+
.dshm_iconSwitch{border:.5px solid var(--dsw-alias-border-l3);border-radius:var(--dsw-radius-sm);background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer;font:inherit;font-size:12px;line-height:18px;min-width:48px;padding:3px 10px}
|
|
99
|
+
.dshm_iconSwitch[aria-checked="true"]{background:var(--dsw-alias-state-business-primary);border-color:transparent;color:var(--dsw-alias-bg-layer-1)}
|
|
84
100
|
`;
|
|
85
101
|
if (typeof document !== 'undefined' && document.querySelector(`style[data-plugin-css="${STYLE_ID}"]`) === null) {
|
|
86
102
|
const tag = document.createElement('style');
|
|
@@ -441,11 +457,20 @@ window.__ModuleLoader__.load({
|
|
|
441
457
|
cardPanel: '配置页面',
|
|
442
458
|
openPanel: '打开配置页面',
|
|
443
459
|
openHint: '配对、网络配置与插件更新都在这个页面里。',
|
|
460
|
+
iconsTitle: '侧边栏图标',
|
|
461
|
+
iconsHint: '选择桌面侧边栏底部显示哪颗入口;至少保留一颗。',
|
|
462
|
+
iconPhone: '手机图标',
|
|
463
|
+
iconComputer: '电脑图标',
|
|
464
|
+
iconShown: '显示',
|
|
465
|
+
iconHidden: '隐藏',
|
|
466
|
+
iconKeepOne: '至少要保留一颗图标',
|
|
467
|
+
iconSaveFailed: '保存图标设置失败',
|
|
444
468
|
panelPending: '正在读取页面地址…',
|
|
445
469
|
panelMissing: '宿主还没给出页面地址,稍后再打开这一页试试。',
|
|
446
470
|
loadFailed: '读取宿主状态失败',
|
|
447
471
|
openFailed: '打开配置页面失败',
|
|
448
472
|
footerOpen: '打开移动端插件配置网页',
|
|
473
|
+
footerRemoteOpen: '打开远程电脑',
|
|
449
474
|
footerPending: '网页地址还没就绪',
|
|
450
475
|
footerNoDevice: '还没配对过手机',
|
|
451
476
|
footerDeviceCount: '{count} 台设备',
|
|
@@ -459,12 +484,10 @@ window.__ModuleLoader__.load({
|
|
|
459
484
|
footerPublicConfirm: '这个地址位于公网。继续后会开放移动端插件的网页管理权限 2 小时;期间任何能访问该地址的人都可以操作面板。是否继续?',
|
|
460
485
|
footerLoadMissing: '插件宿主侧没有加载:把 DSH 完整退出再打开一次;还不行就在插件市场重装一遍插件。',
|
|
461
486
|
consoleTitle: '移动端插件控制台',
|
|
462
|
-
|
|
487
|
+
remoteConsoleTitle: '远程电脑',
|
|
463
488
|
consolePopupBlocked: '浏览器拦掉了新窗口,允许本站弹出窗口后再点一次。',
|
|
464
|
-
consoleOpenBrowser: '在浏览器里打开',
|
|
465
489
|
consoleLoading: '正在载入控制台…',
|
|
466
|
-
|
|
467
|
-
consoleFrameless: '控制台未能完成加载,请点「重新载入」重试,也可以在浏览器里打开。',
|
|
490
|
+
consoleFrameless: '控制台未能完成加载,请关闭后重新点图标,也可以在浏览器里打开。',
|
|
468
491
|
diagTitleLoad: '打不开移动端配置页',
|
|
469
492
|
diagTitleOpen: '开放网页管理失败',
|
|
470
493
|
diagChecking: '正在读取宿主状态…',
|
|
@@ -519,11 +542,20 @@ window.__ModuleLoader__.load({
|
|
|
519
542
|
cardPanel: 'Configuration page',
|
|
520
543
|
openPanel: 'Open the configuration page',
|
|
521
544
|
openHint: 'Pairing, network settings and plugin updates all live on this page.',
|
|
545
|
+
iconsTitle: 'Sidebar icons',
|
|
546
|
+
iconsHint: 'Choose which shortcut sits at the bottom of the desktop sidebar; keep at least one.',
|
|
547
|
+
iconPhone: 'Phone icon',
|
|
548
|
+
iconComputer: 'Computer icon',
|
|
549
|
+
iconShown: 'Shown',
|
|
550
|
+
iconHidden: 'Hidden',
|
|
551
|
+
iconKeepOne: 'Keep at least one icon',
|
|
552
|
+
iconSaveFailed: 'Could not save icon settings',
|
|
522
553
|
panelPending: 'Reading the page address…',
|
|
523
554
|
panelMissing: 'The host has not reported a page address yet — reopen this item in a moment.',
|
|
524
555
|
loadFailed: 'Failed to read host status',
|
|
525
556
|
openFailed: 'Could not open the configuration page',
|
|
526
557
|
footerOpen: 'Open the mobile plugin configuration page',
|
|
558
|
+
footerRemoteOpen: 'Open remote computers',
|
|
527
559
|
footerPending: 'The page address is not ready yet',
|
|
528
560
|
footerNoDevice: 'No phone paired yet',
|
|
529
561
|
footerDeviceCount: '{count} devices',
|
|
@@ -537,12 +569,10 @@ window.__ModuleLoader__.load({
|
|
|
537
569
|
footerPublicConfirm: 'This address is public. Continuing opens mobile plugin web management for 2 hours; anyone who can reach this address can operate the panel during that time. Continue?',
|
|
538
570
|
footerLoadMissing: 'The plugin host half is not loaded: quit and reopen DSH; if that does not help, reinstall the plugin from the market.',
|
|
539
571
|
consoleTitle: 'Mobile plugin console',
|
|
540
|
-
|
|
572
|
+
remoteConsoleTitle: 'Remote computers',
|
|
541
573
|
consolePopupBlocked: 'The browser blocked the new window — allow pop-ups for this site and press again.',
|
|
542
|
-
consoleOpenBrowser: 'Open in a browser',
|
|
543
574
|
consoleLoading: 'Loading the console…',
|
|
544
|
-
|
|
545
|
-
consoleFrameless: 'The console could not finish loading. Choose Reload to try again, or open it in a browser.',
|
|
575
|
+
consoleFrameless: 'The console could not finish loading. Close this pane and press the icon again, or open it in a browser.',
|
|
546
576
|
diagTitleLoad: 'Cannot open the mobile configuration page',
|
|
547
577
|
diagTitleOpen: 'Could not open web management',
|
|
548
578
|
diagChecking: 'Reading host status…',
|
|
@@ -589,6 +619,33 @@ window.__ModuleLoader__.load({
|
|
|
589
619
|
},
|
|
590
620
|
};
|
|
591
621
|
|
|
622
|
+
/* ── 侧边栏图标选择(同一页共享) ────────────────────────────────────────
|
|
623
|
+
* 设置卡和两颗图标各自物化,谁先谁后不定;选择放在这一份闭包里,开关一拨当场生效,
|
|
624
|
+
* 不必等下一轮 20 秒的 /status。状态先到者写入;用户拨过之后,在途的旧状态不再覆盖
|
|
625
|
+
* 他的选择(否则图标会先消失、再自己回来)。写盘失败时回滚并通知同一页的订阅者。
|
|
626
|
+
*/
|
|
627
|
+
let footerIcons = { phone: true, computer: true };
|
|
628
|
+
let footerIconsTouched = false;
|
|
629
|
+
const footerIconWatchers = new Set();
|
|
630
|
+
function setFooterIcons(next) {
|
|
631
|
+
footerIcons = next;
|
|
632
|
+
for (const watch of footerIconWatchers) watch(next);
|
|
633
|
+
}
|
|
634
|
+
function adoptFooterIcons(view) {
|
|
635
|
+
if (footerIconsTouched || !view) return;
|
|
636
|
+
const next = {
|
|
637
|
+
phone: view.desktopPhoneIcon !== false,
|
|
638
|
+
computer: view.desktopComputerIcon !== false,
|
|
639
|
+
};
|
|
640
|
+
if (footerIcons.phone === next.phone && footerIcons.computer === next.computer) return;
|
|
641
|
+
setFooterIcons(next);
|
|
642
|
+
}
|
|
643
|
+
function watchFooterIcons(watch) {
|
|
644
|
+
watch(footerIcons);
|
|
645
|
+
footerIconWatchers.add(watch);
|
|
646
|
+
return () => { footerIconWatchers.delete(watch); };
|
|
647
|
+
}
|
|
648
|
+
|
|
592
649
|
/* ── 诊断弹窗 ──────────────────────────────────────────────────────────
|
|
593
650
|
* 点这颗图标打不开配置页、或者开窗口失败时,不能只让用户「点了没反应」。
|
|
594
651
|
*
|
|
@@ -621,6 +678,8 @@ window.__ModuleLoader__.load({
|
|
|
621
678
|
*/
|
|
622
679
|
const PANEL_VISIBILITY = 'dsh-mobile-plugin:panel-visibility';
|
|
623
680
|
const PANEL_STATE = 'dsh-mobile-plugin:panel-state';
|
|
681
|
+
/** 内嵌页请外面那层窗做事:在浏览器里打开 / 关闭。按钮画在页面里,动作落在这里。 */
|
|
682
|
+
const PANEL_ACTION = 'dsh-mobile-plugin:panel-action';
|
|
624
683
|
const PANEL_LOAD_TIMEOUT_MS = 20000;
|
|
625
684
|
|
|
626
685
|
/** 通知嵌着的那一页:现在看得见 / 看不见。拿不到窗口就静默跳过。 */
|
|
@@ -729,12 +788,15 @@ window.__ModuleLoader__.load({
|
|
|
729
788
|
if (event && typeof event.stopPropagation === 'function') event.stopPropagation();
|
|
730
789
|
});
|
|
731
790
|
overlay.appendChild(card);
|
|
732
|
-
|
|
791
|
+
// 内容窗(嵌一整页):连标题也不画,留白收到最紧;窗口操作那两颗按钮在页面顶栏里,
|
|
792
|
+
// 通过 PANEL_ACTION 消息交回外壳执行。诊断窗保持原样。
|
|
793
|
+
const compact = Boolean(spec.compact && spec.frame && spec.frame.src);
|
|
794
|
+
if (!compact && spec.title) card.appendChild(make('h3', 'dshm_dialogTitle', spec.title));
|
|
733
795
|
if (spec.summary) card.appendChild(make('p', 'dshm_dialogLead', spec.summary));
|
|
734
796
|
// 自定义内容区(入口那两块就挂在这儿):节点由调用方造,这里只负责挂上。
|
|
735
797
|
if (spec.body) card.appendChild(spec.body);
|
|
736
|
-
//
|
|
737
|
-
// `src` 已经由调用方按同源地址算好(壳里是 `dsh-app://app/api/relay/panel/
|
|
798
|
+
// 内嵌一整页(控制台 / 远程电脑那一窗):外壳里 `window.open` 不可靠,所以把页面嵌进来。
|
|
799
|
+
// `src` 已经由调用方按同源地址算好(壳里是 `dsh-app://app/api/relay/panel/console`,
|
|
738
800
|
// 网页里是同源 http),远程浏览器的那两小时窗口也在拨号那一步开好了。
|
|
739
801
|
//
|
|
740
802
|
// load 只说明文档结束导航;空页、错误响应、脚本启动失败都不能算控制台就绪。
|
|
@@ -767,8 +829,16 @@ window.__ModuleLoader__.load({
|
|
|
767
829
|
const onMessage = (event) => {
|
|
768
830
|
if (!frame.contentWindow || event.source !== frame.contentWindow) return;
|
|
769
831
|
const data = event.data;
|
|
770
|
-
if (!data
|
|
771
|
-
if (data.
|
|
832
|
+
if (!data) return;
|
|
833
|
+
if (data.type === PANEL_STATE) {
|
|
834
|
+
if (data.state === 'ready' || data.state === 'error') update(data.state, data.message);
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
// 页面顶栏那两颗按钮只发动作、不碰窗本身;这里按同源 iframe 的来源校验后执行。
|
|
838
|
+
if (data.type === PANEL_ACTION && typeof spec.onAction === 'function'
|
|
839
|
+
&& (data.action === 'open-browser' || data.action === 'close')) {
|
|
840
|
+
spec.onAction(data.action);
|
|
841
|
+
}
|
|
772
842
|
};
|
|
773
843
|
host.addEventListener('message', onMessage);
|
|
774
844
|
frame.onload = () => {
|
|
@@ -811,20 +881,21 @@ window.__ModuleLoader__.load({
|
|
|
811
881
|
for (const step of spec.steps) steps.appendChild(make('li', null, step));
|
|
812
882
|
card.appendChild(steps);
|
|
813
883
|
}
|
|
814
|
-
//
|
|
815
|
-
// 重画整窗会把嵌进去的页面重新加载一遍。
|
|
884
|
+
// 说明行总挂上(`:empty` 时 CSS 不让它占位):弹窗被拦那句就地写进来,不重画整窗。
|
|
816
885
|
const note = make('p', 'dshm_dialogNote', spec.note || '');
|
|
817
886
|
card.appendChild(note);
|
|
818
|
-
const actions = make('div', 'dshm_dialogActions');
|
|
819
|
-
for (const action of spec.actions || []) {
|
|
820
|
-
const button = make('button', action.primary ? 'dshm_btn dshm_btnPrimary' : 'dshm_btn', action.label);
|
|
821
|
-
button.setAttribute('type', 'button');
|
|
822
|
-
if (action.disabled) button.disabled = true;
|
|
823
|
-
button.onclick = () => { void action.onClick(); };
|
|
824
|
-
actions.appendChild(button);
|
|
825
|
-
}
|
|
826
|
-
card.appendChild(actions);
|
|
827
887
|
noteEl = note;
|
|
888
|
+
if (!compact) {
|
|
889
|
+
const actions = make('div', 'dshm_dialogActions');
|
|
890
|
+
for (const action of spec.actions || []) {
|
|
891
|
+
const button = make('button', action.primary ? 'dshm_btn dshm_btnPrimary' : 'dshm_btn', action.label);
|
|
892
|
+
button.setAttribute('type', 'button');
|
|
893
|
+
if (action.disabled) button.disabled = true;
|
|
894
|
+
button.onclick = () => { void action.onClick(); };
|
|
895
|
+
actions.appendChild(button);
|
|
896
|
+
}
|
|
897
|
+
card.appendChild(actions);
|
|
898
|
+
}
|
|
828
899
|
return overlay;
|
|
829
900
|
};
|
|
830
901
|
/**
|
|
@@ -1118,6 +1189,22 @@ window.__ModuleLoader__.load({
|
|
|
1118
1189
|
const PHONE_GLYPH_WIDE = 20;
|
|
1119
1190
|
const PHONE_GLYPH_RAIL = 22;
|
|
1120
1191
|
|
|
1192
|
+
/**
|
|
1193
|
+
* 电脑图标(「显示器 + 底座」那一款):24 画布描边,与手机图标同一套笔画粗细。
|
|
1194
|
+
* 屏幕 3→21、4.4→16.6,底下一条底座加中柱。与面板里那颗 `DesktopIcon` 同形,
|
|
1195
|
+
* 只是这里的手写 DOM 不走构建。它是远程电脑页的入口,与手机图标并排。
|
|
1196
|
+
*/
|
|
1197
|
+
const COMPUTER_PATHS = [
|
|
1198
|
+
'M4.5 3.5h15A1.5 1.5 0 0 1 21 5v9.6A1.5 1.5 0 0 1 19.5 16.1h-15A1.5 1.5 0 0 1 3 14.6V5a1.5 1.5 0 0 1 1.5-1.5Z',
|
|
1199
|
+
'M9 20h6',
|
|
1200
|
+
'M12 16.5V20',
|
|
1201
|
+
];
|
|
1202
|
+
/** 第二颗图标自己的记号:同一页面里出现第二份实现时,靠它摘掉上一颗(与手机那颗分开)。 */
|
|
1203
|
+
const REMOTE_MARK = 'data-dshm-remote-web';
|
|
1204
|
+
/** 两颗图标那只方框的记号与类名:谁先落位谁造盒子,另一颗认记号挂进来。 */
|
|
1205
|
+
const GROUP_MARK = 'data-dshm-footer-group';
|
|
1206
|
+
const GROUP_CLASS = 'dshm_footerGroup';
|
|
1207
|
+
|
|
1121
1208
|
/** 造一颗手机图标(含那颗常驻的告警红点,显不显示看 `data-dshm-alert`)。文档没有 SVG 能力时返回 null,按钮照样成立(只剩无障碍名字)。 */
|
|
1122
1209
|
function phoneIcon(doc, size) {
|
|
1123
1210
|
if (!doc || typeof doc.createElementNS !== 'function') return null;
|
|
@@ -1146,7 +1233,29 @@ window.__ModuleLoader__.load({
|
|
|
1146
1233
|
return svg;
|
|
1147
1234
|
}
|
|
1148
1235
|
|
|
1149
|
-
/**
|
|
1236
|
+
/** 造电脑图标:与手机图标同一套画布、描边与底色。 */
|
|
1237
|
+
function computerIcon(doc, size) {
|
|
1238
|
+
if (!doc || typeof doc.createElementNS !== 'function') return null;
|
|
1239
|
+
const svg = doc.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
1240
|
+
svg.setAttribute('viewBox', '0 0 24 24');
|
|
1241
|
+
svg.setAttribute('width', String(size));
|
|
1242
|
+
svg.setAttribute('height', String(size));
|
|
1243
|
+
svg.setAttribute('fill', 'none');
|
|
1244
|
+
svg.setAttribute('stroke', 'currentColor');
|
|
1245
|
+
svg.setAttribute('stroke-width', '1.7');
|
|
1246
|
+
svg.setAttribute('stroke-linecap', 'round');
|
|
1247
|
+
svg.setAttribute('stroke-linejoin', 'round');
|
|
1248
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
1249
|
+
svg.setAttribute('focusable', 'false');
|
|
1250
|
+
for (const d of COMPUTER_PATHS) {
|
|
1251
|
+
const path = doc.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
1252
|
+
path.setAttribute('d', d);
|
|
1253
|
+
svg.appendChild(path);
|
|
1254
|
+
}
|
|
1255
|
+
return svg;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
/** 造那一颗手机按钮:28 点,与同一行里那几颗图标按钮同尺寸。 */
|
|
1150
1259
|
function createFooterIcon(doc) {
|
|
1151
1260
|
const anchor = doc.createElement('a');
|
|
1152
1261
|
anchor.className = 'dshm_footAction';
|
|
@@ -1158,6 +1267,18 @@ window.__ModuleLoader__.load({
|
|
|
1158
1267
|
return anchor;
|
|
1159
1268
|
}
|
|
1160
1269
|
|
|
1270
|
+
/** 造那一颗电脑按钮:与手机按钮同尺寸,紧跟在它右边。 */
|
|
1271
|
+
function createRemoteFooterIcon(doc) {
|
|
1272
|
+
const anchor = doc.createElement('a');
|
|
1273
|
+
anchor.className = 'dshm_footAction';
|
|
1274
|
+
anchor.setAttribute(REMOTE_MARK, '');
|
|
1275
|
+
anchor.setAttribute('target', '_blank');
|
|
1276
|
+
anchor.setAttribute('rel', 'noreferrer');
|
|
1277
|
+
const icon = computerIcon(doc, PHONE_GLYPH_WIDE);
|
|
1278
|
+
if (icon) anchor.appendChild(icon);
|
|
1279
|
+
return anchor;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1161
1282
|
/**
|
|
1162
1283
|
* 把「打开哪一页 / 现在是什么状态」同步到元素上。
|
|
1163
1284
|
*
|
|
@@ -1185,19 +1306,70 @@ window.__ModuleLoader__.load({
|
|
|
1185
1306
|
node.onclick = onClick;
|
|
1186
1307
|
}
|
|
1187
1308
|
|
|
1188
|
-
/**
|
|
1189
|
-
|
|
1309
|
+
/**
|
|
1310
|
+
* 在设置那一行找(或造)那只包住两颗图标的方框,紧跟头像出口。
|
|
1311
|
+
*
|
|
1312
|
+
* 两颗图标是两个组件分别物化的,谁先谁后不定:先到的造盒子并插到出口后,后到的认记号
|
|
1313
|
+
* 挂进同一个盒子。认不出那一行(座位不在)就返回 null,两颗各自退回自己一行。
|
|
1314
|
+
*/
|
|
1315
|
+
function ensureFooterGroup(doc) {
|
|
1190
1316
|
const outlet = typeof doc.querySelector === 'function' ? doc.querySelector(FOOTER_ANCHOR) : null;
|
|
1191
1317
|
const row = outlet && outlet.parentElement;
|
|
1192
|
-
if (!row || typeof row.insertBefore !== 'function') return
|
|
1318
|
+
if (!row || typeof row.insertBefore !== 'function') return null;
|
|
1193
1319
|
// 只认「侧栏底部那个座位里的 launcher」:头像那块万一被外壳渲染到别处(设置面板里、
|
|
1194
|
-
//
|
|
1195
|
-
if (typeof outlet.closest === 'function' && outlet.closest(FOOTER_SEAT) === null) return
|
|
1196
|
-
|
|
1197
|
-
|
|
1320
|
+
// 以后的新位置),按出口插进去就插错地方了。
|
|
1321
|
+
if (typeof outlet.closest === 'function' && outlet.closest(FOOTER_SEAT) === null) return null;
|
|
1322
|
+
let group = typeof doc.querySelector === 'function' ? doc.querySelector(`[${GROUP_MARK}]`) : null;
|
|
1323
|
+
// 认出的盒子得真在这一行里:别处遗留的同名盒子(认错座位)不能拿来用。
|
|
1324
|
+
if (group && group.parentElement !== row) group = null;
|
|
1325
|
+
if (!group) {
|
|
1326
|
+
group = doc.createElement('span');
|
|
1327
|
+
group.className = GROUP_CLASS;
|
|
1328
|
+
group.setAttribute(GROUP_MARK, '');
|
|
1329
|
+
row.insertBefore(group, outlet.nextSibling);
|
|
1330
|
+
}
|
|
1331
|
+
return group;
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
/** 把手机图标放回方框里的第一位。返回是否真在设置那一行里。 */
|
|
1335
|
+
function ensureFooterIcon(doc, node) {
|
|
1336
|
+
const group = ensureFooterGroup(doc);
|
|
1337
|
+
if (!group) return false;
|
|
1338
|
+
const first = group.children.length ? group.children[0] : null;
|
|
1339
|
+
// 手机永远是第一颗:盒子先被电脑图标占住时也要插到它前面,两颗的先后与渲染顺序无关。
|
|
1340
|
+
if (node.parentElement === group && first === node) return true;
|
|
1341
|
+
group.insertBefore(node, first);
|
|
1342
|
+
return true;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* 把电脑图标放进方框、紧跟手机图标右边(第二颗)。
|
|
1347
|
+
*
|
|
1348
|
+
* 盒子由 `ensureFooterGroup` 统一找或造;手机永远是第一颗,所以这里 append 到末尾即可。
|
|
1349
|
+
* 两颗各由一个组件物化、先后不定:电脑先到时它是盒里唯一一颗,手机后到会插到它前面。
|
|
1350
|
+
*/
|
|
1351
|
+
function ensureRemoteFooterIcon(doc, node) {
|
|
1352
|
+
const group = ensureFooterGroup(doc);
|
|
1353
|
+
if (!group) return false;
|
|
1354
|
+
if (node.parentElement === group && node === group.children[group.children.length - 1]) return true;
|
|
1355
|
+
group.insertBefore(node, null);
|
|
1198
1356
|
return true;
|
|
1199
1357
|
}
|
|
1200
1358
|
|
|
1359
|
+
/** 摘掉上一次物化留下的电脑图标(插件重装、同一页面里出现第二份实现)。 */
|
|
1360
|
+
function dropStaleRemoteIcons(doc) {
|
|
1361
|
+
if (!doc || typeof doc.querySelectorAll !== 'function') return;
|
|
1362
|
+
let stale = null;
|
|
1363
|
+
try {
|
|
1364
|
+
stale = doc.querySelectorAll(`[${REMOTE_MARK}]`);
|
|
1365
|
+
} catch {
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1368
|
+
for (const node of stale || []) {
|
|
1369
|
+
if (node && typeof node.remove === 'function') node.remove();
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1201
1373
|
/** 摘掉上一次物化留下的那一颗(插件重装、同一页面里出现第二份实现)。 */
|
|
1202
1374
|
function dropStaleFooterIcons(doc) {
|
|
1203
1375
|
if (!doc || typeof doc.querySelectorAll !== 'function') return;
|
|
@@ -1243,6 +1415,9 @@ window.__ModuleLoader__.load({
|
|
|
1243
1415
|
const [hint, setHint] = useState('');
|
|
1244
1416
|
/** 展开态是否已经插进设置那一行。插不上就自己占一行。 */
|
|
1245
1417
|
const [anchored, setAnchored] = useState(true);
|
|
1418
|
+
/** 用户在设置卡上有没有把这颗收起来;收起来时连插入的 DOM 一起撤掉。 */
|
|
1419
|
+
const [visible, setVisible] = useState(footerIcons.phone);
|
|
1420
|
+
useEffect(() => watchFooterIcons((next) => setVisible(next.phone)), []);
|
|
1246
1421
|
const nodeRef = useRef(null);
|
|
1247
1422
|
const dialogRef = useRef(null);
|
|
1248
1423
|
useEffect(() => () => {
|
|
@@ -1284,6 +1459,7 @@ window.__ModuleLoader__.load({
|
|
|
1284
1459
|
try {
|
|
1285
1460
|
const next = await call('/status');
|
|
1286
1461
|
const view = next && typeof next === 'object' ? next : {};
|
|
1462
|
+
adoptFooterIcons(view);
|
|
1287
1463
|
const summary = readStatusView(view);
|
|
1288
1464
|
setUrl(summary.panelUrl);
|
|
1289
1465
|
setWebAccess(summary.webAccess);
|
|
@@ -1372,7 +1548,7 @@ window.__ModuleLoader__.load({
|
|
|
1372
1548
|
* 跳过去,而是「它现在到底哪一环断了」——启动、装载、隧道、旁挂进程、自检全都在那一屏
|
|
1373
1549
|
* 里,比一个打不开的页面有用。跳转本身没取消,挪进了那一屏里的一颗按钮。
|
|
1374
1550
|
*
|
|
1375
|
-
* 那一屏的内容是网页版的 `/api/relay/panel/
|
|
1551
|
+
* 那一屏的内容是网页版的 `/api/relay/panel/console`(React 写的,改完刷新就见效),
|
|
1376
1552
|
* 这里只把同源地址算出来嵌进去。**必须先保证控制面认这个浏览器**,否则嵌进来的是一屏
|
|
1377
1553
|
* 423 JSON:所以公网入口先按 `panelScope` 开好两小时窗口,本机和局域网直接进入。
|
|
1378
1554
|
*
|
|
@@ -1424,7 +1600,6 @@ window.__ModuleLoader__.load({
|
|
|
1424
1600
|
const outcome = await openConfigurationPage({ view, loadStatus, t, target: null, confirmed: true, navigate: false });
|
|
1425
1601
|
if (!outcome.ok) return outcome;
|
|
1426
1602
|
const consolePage = panelPageUrlOf('console');
|
|
1427
|
-
const debugPage = panelPageUrlOf('debug');
|
|
1428
1603
|
if (!consolePage) return { ok: false, missing: false, status: 0, message: t('panelMissing') };
|
|
1429
1604
|
const dialog = diagnosisDialog();
|
|
1430
1605
|
|
|
@@ -1434,16 +1609,16 @@ window.__ModuleLoader__.load({
|
|
|
1434
1609
|
* 网页(`http(s)`)里用**同源推算**的地址(`panelPageUrlOf`):公网 / 域名 / 反代
|
|
1435
1610
|
* 子路径都能对上,宿主报的 `panelUrl` 反而常是 `127.0.0.1`,从公网打开的人点过去
|
|
1436
1611
|
* 必然打不开。桌面壳里那条同源地址是 `dsh-app://`,系统浏览器不认,只能换用宿主
|
|
1437
|
-
* 报的绝对 http(s) 地址(`outcome.url
|
|
1612
|
+
* 报的绝对 http(s) 地址(`outcome.url`)。
|
|
1438
1613
|
*/
|
|
1439
|
-
const browserPageUrl = (
|
|
1440
|
-
if (isWebPage(window)) return
|
|
1614
|
+
const browserPageUrl = () => {
|
|
1615
|
+
if (isWebPage(window)) return consolePage;
|
|
1441
1616
|
const root = String(outcome.url || '').replace(/\/console\/?$/, '').replace(/\/+$/, '');
|
|
1442
1617
|
if (!/^https?:\/\//i.test(root)) return '';
|
|
1443
|
-
return
|
|
1618
|
+
return root;
|
|
1444
1619
|
};
|
|
1445
|
-
const openBrowser = (
|
|
1446
|
-
const url = browserPageUrl(
|
|
1620
|
+
const openBrowser = () => {
|
|
1621
|
+
const url = browserPageUrl();
|
|
1447
1622
|
if (!url) {
|
|
1448
1623
|
dialog.note(t('consolePopupBlocked'));
|
|
1449
1624
|
return;
|
|
@@ -1463,14 +1638,13 @@ window.__ModuleLoader__.load({
|
|
|
1463
1638
|
};
|
|
1464
1639
|
|
|
1465
1640
|
/**
|
|
1466
|
-
*
|
|
1467
|
-
*
|
|
1468
|
-
* 看手机连没连上」。调试页没删,退到操作栏里的「报错调试」一颗次要按钮,那一屏排障用,
|
|
1469
|
-
* 不该跟日常那一屏抢第一眼。
|
|
1641
|
+
* 点一下手机图标,**直接就是这一屏控制台**:没有中间入口。调试页 2026-11-17 删了,
|
|
1642
|
+
* 窗口操作那两颗按钮也搬进了页面顶栏;这一窗的外壳只剩一圈薄边,不占嵌页的地方。
|
|
1470
1643
|
*/
|
|
1471
1644
|
dialog.open({
|
|
1472
1645
|
title: t('consoleTitle'),
|
|
1473
1646
|
wide: true,
|
|
1647
|
+
compact: true,
|
|
1474
1648
|
// 收起时不销毁(见 `hide`):再点一次图标就是热的,省掉一次整页重载。
|
|
1475
1649
|
keep: true,
|
|
1476
1650
|
frame: {
|
|
@@ -1479,48 +1653,15 @@ window.__ModuleLoader__.load({
|
|
|
1479
1653
|
loading: t('consoleLoading'),
|
|
1480
1654
|
hint: t('consoleFrameless'),
|
|
1481
1655
|
},
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
{ label: t('diagClose'), onClick: () => dialog.hide() },
|
|
1488
|
-
],
|
|
1656
|
+
// 窗口操作由页面顶栏那两颗按钮发消息过来;外壳这边只认消息、执行,不画按钮。
|
|
1657
|
+
onAction: (action) => {
|
|
1658
|
+
if (action === 'open-browser') openBrowser();
|
|
1659
|
+
else if (action === 'close') dialog.hide();
|
|
1660
|
+
},
|
|
1489
1661
|
});
|
|
1490
1662
|
return { ok: true, webAccess: outcome.webAccess };
|
|
1491
1663
|
}
|
|
1492
1664
|
|
|
1493
|
-
/** 把「复制诊断信息」那一套复用在控制台上:读的是嵌入页同样的几份,不另开一套。 */
|
|
1494
|
-
async function copyConsole() {
|
|
1495
|
-
const dialog = diagnosisDialog();
|
|
1496
|
-
const lines = ['dsh-mobile-plugin console'];
|
|
1497
|
-
lines.push(`panel_url=${url || ''}`);
|
|
1498
|
-
lines.push(`panel_scope=${panelScope || ''}`);
|
|
1499
|
-
try {
|
|
1500
|
-
const view = await call('/status');
|
|
1501
|
-
const next = view && typeof view === 'object' ? view : {};
|
|
1502
|
-
lines.push(`plugin_version=${next.appVersion || ''}`);
|
|
1503
|
-
lines.push(`tunnel=${next.tunnel && next.tunnel.state ? next.tunnel.state : ''}`);
|
|
1504
|
-
lines.push(`lan=${next.lan && next.lan.state ? next.lan.state : ''}`);
|
|
1505
|
-
lines.push(`sidecar=${next.sidecar && next.sidecar.state ? next.sidecar.state : ''}`);
|
|
1506
|
-
lines.push(`last_mobile_at=${next.lastMobileAt || 0}`);
|
|
1507
|
-
} catch (error) {
|
|
1508
|
-
lines.push(`status_error=${String((error && error.message) || error)}`);
|
|
1509
|
-
}
|
|
1510
|
-
try {
|
|
1511
|
-
const picture = await call(HOST_HALF_ENDPOINT);
|
|
1512
|
-
const half = picture && picture.half && typeof picture.half === 'object' ? picture.half : {};
|
|
1513
|
-
lines.push(`plugin_source=${half.source || ''}`);
|
|
1514
|
-
lines.push(`host_last_error=${half.lastError || ''}`);
|
|
1515
|
-
} catch {
|
|
1516
|
-
lines.push('host_half=unavailable');
|
|
1517
|
-
}
|
|
1518
|
-
if (typeof navigator !== 'undefined' && navigator.userAgent) lines.push(`user_agent=${navigator.userAgent}`);
|
|
1519
|
-
const ok = await copyDiagnosisText(document, lines.join('\n'));
|
|
1520
|
-
// 复制结果就地提示一下即可,不必重画整窗(重画会把嵌着的页面重新加载一遍)。
|
|
1521
|
-
dialog.note(ok ? t('diagCopied') : t('diagCopyFailed'));
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
1665
|
/**
|
|
1525
1666
|
* 把这一轮的现场摆成一屏**能自己动手**的自查。
|
|
1526
1667
|
*
|
|
@@ -1736,8 +1877,9 @@ window.__ModuleLoader__.load({
|
|
|
1736
1877
|
useEffect(() => {
|
|
1737
1878
|
if (typeof document === 'undefined') return undefined;
|
|
1738
1879
|
const doc = document;
|
|
1739
|
-
//
|
|
1740
|
-
|
|
1880
|
+
// 窄条那一行塞不下第二颗:不插,自己占一行。用户在设置卡上收起来时同样不插,
|
|
1881
|
+
// 走下面的清理把已插的那颗摘掉;观察器也不能再把它捡回来。
|
|
1882
|
+
if (!wide || !visible) {
|
|
1741
1883
|
setAnchored(false);
|
|
1742
1884
|
return undefined;
|
|
1743
1885
|
}
|
|
@@ -1785,7 +1927,7 @@ window.__ModuleLoader__.load({
|
|
|
1785
1927
|
frame = 0;
|
|
1786
1928
|
try {
|
|
1787
1929
|
sync();
|
|
1788
|
-
setAnchored(ensureFooterIcon(doc, node));
|
|
1930
|
+
setAnchored(visible ? ensureFooterIcon(doc, node) : false);
|
|
1789
1931
|
} catch {
|
|
1790
1932
|
setAnchored(false);
|
|
1791
1933
|
}
|
|
@@ -1798,9 +1940,11 @@ window.__ModuleLoader__.load({
|
|
|
1798
1940
|
if (frame !== 0 && typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame);
|
|
1799
1941
|
if (typeof node.remove === 'function' && node.parentElement) node.remove();
|
|
1800
1942
|
};
|
|
1801
|
-
}, [wide, url, openLabel, loadMissingLabel, pendingLabel, problem, panelScope, webAccess, hint, fault]);
|
|
1943
|
+
}, [wide, visible, url, openLabel, loadMissingLabel, pendingLabel, problem, panelScope, webAccess, hint, fault]);
|
|
1802
1944
|
|
|
1803
1945
|
// 窄条,或者这一版外壳里认不出那一行:自己占一行,入口不能因为认不出位置就消失。
|
|
1946
|
+
// 收起来的那一颗例外:它这一页里根本不该再有入口。
|
|
1947
|
+
if (!visible) return null;
|
|
1804
1948
|
if (!wide || !anchored) {
|
|
1805
1949
|
const state = footerState();
|
|
1806
1950
|
return h('a', {
|
|
@@ -1839,6 +1983,284 @@ window.__ModuleLoader__.load({
|
|
|
1839
1983
|
return null;
|
|
1840
1984
|
}
|
|
1841
1985
|
|
|
1986
|
+
/**
|
|
1987
|
+
* 侧边栏底部那颗电脑图标(远程电脑独立页的入口)。
|
|
1988
|
+
*
|
|
1989
|
+
* 与手机图标并排,共用同一套状态读数与两小时窗口逻辑:地址、网络类别、窗口状态都从
|
|
1990
|
+
* 同一条 `/status` 来。它只是打开另一条面板页(`/api/relay/panel/remote`),所以没有
|
|
1991
|
+
* 手机图标那一套链路告警着色——这一颗是纯入口,状态色交给旁边那颗去说。
|
|
1992
|
+
*
|
|
1993
|
+
* 点下去和手机图标一样弹一扇内嵌窗(不是跳走):公网地址先按 `panelScope` 开好两小时
|
|
1994
|
+
* 窗口,本机与局域网直接进。打不开时落到诊断窗,不许「点了没反应」。
|
|
1995
|
+
*/
|
|
1996
|
+
function RemoteWebEntry({ wide, t }) {
|
|
1997
|
+
const [url, setUrl] = useState(null);
|
|
1998
|
+
const [webAccess, setWebAccess] = useState(null);
|
|
1999
|
+
const [panelScope, setPanelScope] = useState('');
|
|
2000
|
+
const [problem, setProblem] = useState(null);
|
|
2001
|
+
const [anchored, setAnchored] = useState(true);
|
|
2002
|
+
const [visible, setVisible] = useState(footerIcons.computer);
|
|
2003
|
+
useEffect(() => watchFooterIcons((next) => setVisible(next.computer)), []);
|
|
2004
|
+
const nodeRef = useRef(null);
|
|
2005
|
+
const dialogRef = useRef(null);
|
|
2006
|
+
useEffect(() => () => {
|
|
2007
|
+
if (dialogRef.current) dialogRef.current.dispose();
|
|
2008
|
+
dialogRef.current = null;
|
|
2009
|
+
}, []);
|
|
2010
|
+
|
|
2011
|
+
const openLabel = t('footerRemoteOpen');
|
|
2012
|
+
const pendingLabel = t('footerPending');
|
|
2013
|
+
|
|
2014
|
+
/** 拉一次状态;电脑图标只要地址与窗口类别,不碰设备数与链路告警。 */
|
|
2015
|
+
async function refreshStatus() {
|
|
2016
|
+
try {
|
|
2017
|
+
const next = await call('/status');
|
|
2018
|
+
const view = readStatusView(next);
|
|
2019
|
+
adoptFooterIcons(next);
|
|
2020
|
+
setUrl(view.panelUrl);
|
|
2021
|
+
setWebAccess(view.webAccess);
|
|
2022
|
+
setPanelScope(view.panelScope);
|
|
2023
|
+
setProblem(null);
|
|
2024
|
+
return { ok: true, status: next };
|
|
2025
|
+
} catch (error) {
|
|
2026
|
+
const failed = {
|
|
2027
|
+
status: Number(error && error.status) || 0,
|
|
2028
|
+
message: String((error && error.message) || error),
|
|
2029
|
+
};
|
|
2030
|
+
setProblem(failed);
|
|
2031
|
+
return { ok: false, problem: failed };
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
/** 诊断窗单例:与手机图标那扇分开,两扇互不顶掉。 */
|
|
2036
|
+
function diagnosisDialog() {
|
|
2037
|
+
if (!dialogRef.current) {
|
|
2038
|
+
dialogRef.current = createDiagnosisDialog(typeof document !== 'undefined' ? document : null);
|
|
2039
|
+
}
|
|
2040
|
+
return dialogRef.current;
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
/** 打不开时落到诊断窗:宿主与外壳各说了什么、能一键试的重试与复制读数。 */
|
|
2044
|
+
async function openDiagnosis(failure) {
|
|
2045
|
+
if (typeof document === 'undefined') return;
|
|
2046
|
+
const view = diagnosisDialog();
|
|
2047
|
+
let current = failure || problem || null;
|
|
2048
|
+
let half = null;
|
|
2049
|
+
const snapshot = {
|
|
2050
|
+
url: typeof url === 'string' ? url : '',
|
|
2051
|
+
scope: panelScope || 'unknown',
|
|
2052
|
+
access: webAccess,
|
|
2053
|
+
};
|
|
2054
|
+
const closeAction = { label: t('diagClose'), onClick: () => view.hide() };
|
|
2055
|
+
const readHalf = async () => {
|
|
2056
|
+
try {
|
|
2057
|
+
const picture = await call(HOST_HALF_ENDPOINT);
|
|
2058
|
+
half = picture && picture.half && typeof picture.half === 'object' ? picture.half : { unavailable: true };
|
|
2059
|
+
} catch {
|
|
2060
|
+
half = { unavailable: true };
|
|
2061
|
+
}
|
|
2062
|
+
};
|
|
2063
|
+
const facts = () => {
|
|
2064
|
+
const rows = [];
|
|
2065
|
+
if (current) {
|
|
2066
|
+
rows.push({ key: 'host_returned', label: t('diagFactReturned'), value: current.message });
|
|
2067
|
+
rows.push({ key: 'http_status', label: t('diagFactStatus'), value: current.status ? String(current.status) : '—' });
|
|
2068
|
+
}
|
|
2069
|
+
rows.push({ key: 'panel_url', label: t('diagFactPanelUrl'), value: snapshot.url || '—' });
|
|
2070
|
+
rows.push({ key: 'panel_scope', label: t('diagFactScope'), value: snapshot.scope });
|
|
2071
|
+
if (half && half.lastError) rows.push({ key: 'host_last_error', label: t('diagFactReason'), value: half.lastError });
|
|
2072
|
+
return rows;
|
|
2073
|
+
};
|
|
2074
|
+
const render = (note) => {
|
|
2075
|
+
view.open({
|
|
2076
|
+
title: t('diagTitleOpen'),
|
|
2077
|
+
summary: current ? t('diagSummaryOpenFailed') : t('diagChecking'),
|
|
2078
|
+
factsHeading: t('diagHeadingFacts'),
|
|
2079
|
+
facts: facts(),
|
|
2080
|
+
actions: [closeAction],
|
|
2081
|
+
note,
|
|
2082
|
+
});
|
|
2083
|
+
};
|
|
2084
|
+
view.open({ title: t('diagTitleOpen'), actions: [closeAction] });
|
|
2085
|
+
await readHalf();
|
|
2086
|
+
render(null);
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
/**
|
|
2090
|
+
* 点电脑图标:公网先确认并开两小时窗口,然后弹一扇内嵌远程电脑页的窗。
|
|
2091
|
+
*
|
|
2092
|
+
* 与手机图标走的是同一条 `openConfigurationPage` 拨号(地址、窗口、公网确认全在那儿),
|
|
2093
|
+
* 区别只在内嵌的是 `/remote` 那一页。新窗口不在这里开:`navigate:false` 只确认访问,
|
|
2094
|
+
* 页面本身嵌进诊断窗的 iframe。
|
|
2095
|
+
*/
|
|
2096
|
+
function openRemote(event) {
|
|
2097
|
+
if (event && typeof event.preventDefault === 'function') event.preventDefault();
|
|
2098
|
+
const willOpenWindow = panelScope !== 'loopback' && panelScope !== 'private' && !(webAccess && webAccess.enabled);
|
|
2099
|
+
if (panelScope === 'public' && url && willOpenWindow
|
|
2100
|
+
&& typeof window !== 'undefined' && typeof window.confirm === 'function'
|
|
2101
|
+
&& !window.confirm(t('footerPublicConfirm'))) return;
|
|
2102
|
+
void (async () => {
|
|
2103
|
+
const outcome = await openConfigurationPage({
|
|
2104
|
+
view: { panelUrl: url || '', panelScope, webAccess },
|
|
2105
|
+
loadStatus: problem ? problem.status : 0,
|
|
2106
|
+
t,
|
|
2107
|
+
target: null,
|
|
2108
|
+
confirmed: true,
|
|
2109
|
+
navigate: false,
|
|
2110
|
+
});
|
|
2111
|
+
if (!outcome.ok) {
|
|
2112
|
+
if (outcome.missing) void openDiagnosis({ status: outcome.status || 404, message: '' });
|
|
2113
|
+
else void openDiagnosis({ status: outcome.status || 0, message: outcome.message });
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
if (outcome.webAccess) setWebAccess(outcome.webAccess);
|
|
2117
|
+
const remotePage = panelPageUrlOf('remote');
|
|
2118
|
+
if (!remotePage) {
|
|
2119
|
+
void openDiagnosis({ status: 0, message: t('panelMissing') });
|
|
2120
|
+
return;
|
|
2121
|
+
}
|
|
2122
|
+
const dialog = diagnosisDialog();
|
|
2123
|
+
const browserOpen = () => {
|
|
2124
|
+
if (typeof window === 'undefined' || typeof window.open !== 'function') return;
|
|
2125
|
+
const opened = window.open(remotePage, '_blank', 'noreferrer');
|
|
2126
|
+
if (opened) dialog.dispose();
|
|
2127
|
+
else dialog.note(t('consolePopupBlocked'));
|
|
2128
|
+
};
|
|
2129
|
+
dialog.open({
|
|
2130
|
+
title: t('remoteConsoleTitle'),
|
|
2131
|
+
wide: true,
|
|
2132
|
+
compact: true,
|
|
2133
|
+
keep: true,
|
|
2134
|
+
frame: { src: remotePage, title: t('remoteConsoleTitle'), loading: t('consoleLoading') },
|
|
2135
|
+
onAction: (action) => {
|
|
2136
|
+
if (action === 'open-browser') browserOpen();
|
|
2137
|
+
else if (action === 'close') dialog.hide();
|
|
2138
|
+
},
|
|
2139
|
+
});
|
|
2140
|
+
})();
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
// 页面一打开就问一次地址:点下去要么进窗、要么先开窗再读。取到就停,没取到后台重试。
|
|
2144
|
+
useEffect(() => {
|
|
2145
|
+
let alive = true;
|
|
2146
|
+
let timer = null;
|
|
2147
|
+
const load = async () => {
|
|
2148
|
+
const outcome = await refreshStatus();
|
|
2149
|
+
if (!alive || !outcome.ok) return;
|
|
2150
|
+
const next = outcome.status || {};
|
|
2151
|
+
if (typeof next.panelUrl === 'string' && next.panelUrl && timer !== null) {
|
|
2152
|
+
clearInterval(timer);
|
|
2153
|
+
timer = null;
|
|
2154
|
+
}
|
|
2155
|
+
};
|
|
2156
|
+
void load();
|
|
2157
|
+
if (timer === null) {
|
|
2158
|
+
timer = setInterval(() => {
|
|
2159
|
+
if (typeof document !== 'undefined' && document.hidden) return;
|
|
2160
|
+
void load();
|
|
2161
|
+
}, FOOTER_URL_RETRY_MS);
|
|
2162
|
+
}
|
|
2163
|
+
return () => {
|
|
2164
|
+
alive = false;
|
|
2165
|
+
if (timer !== null) clearInterval(timer);
|
|
2166
|
+
};
|
|
2167
|
+
}, []);
|
|
2168
|
+
|
|
2169
|
+
// 展开态:纯 DOM 插进设置那一行,紧跟手机图标;认不出位置就退回自己一行。
|
|
2170
|
+
// 收起来时不插,也不让观察器把它捡回来(已插的那颗在 effect 清理里摘掉)。
|
|
2171
|
+
useEffect(() => {
|
|
2172
|
+
if (typeof document === 'undefined') return undefined;
|
|
2173
|
+
const doc = document;
|
|
2174
|
+
if (!wide || !visible) {
|
|
2175
|
+
setAnchored(false);
|
|
2176
|
+
return undefined;
|
|
2177
|
+
}
|
|
2178
|
+
let node = nodeRef.current;
|
|
2179
|
+
if (!node) {
|
|
2180
|
+
try {
|
|
2181
|
+
dropStaleRemoteIcons(doc);
|
|
2182
|
+
node = createRemoteFooterIcon(doc);
|
|
2183
|
+
} catch {
|
|
2184
|
+
node = null;
|
|
2185
|
+
}
|
|
2186
|
+
nodeRef.current = node;
|
|
2187
|
+
}
|
|
2188
|
+
if (!node) {
|
|
2189
|
+
setAnchored(false);
|
|
2190
|
+
return undefined;
|
|
2191
|
+
}
|
|
2192
|
+
const sync = () => {
|
|
2193
|
+
node.setAttribute('aria-label', openLabel);
|
|
2194
|
+
node.setAttribute('title', openLabel);
|
|
2195
|
+
node.setAttribute('aria-disabled', 'false');
|
|
2196
|
+
if (url) node.setAttribute('href', url);
|
|
2197
|
+
else node.removeAttribute('href');
|
|
2198
|
+
node.onclick = openRemote;
|
|
2199
|
+
};
|
|
2200
|
+
let attached = false;
|
|
2201
|
+
try {
|
|
2202
|
+
attached = ensureRemoteFooterIcon(doc, node);
|
|
2203
|
+
sync();
|
|
2204
|
+
} catch {
|
|
2205
|
+
attached = false;
|
|
2206
|
+
}
|
|
2207
|
+
setAnchored(attached);
|
|
2208
|
+
const Observer = typeof window !== 'undefined' ? window.MutationObserver : undefined;
|
|
2209
|
+
let observer = null;
|
|
2210
|
+
let frame = 0;
|
|
2211
|
+
if (typeof Observer === 'function' && doc.body) {
|
|
2212
|
+
observer = new Observer(() => {
|
|
2213
|
+
if (frame !== 0) return;
|
|
2214
|
+
const raf = typeof requestAnimationFrame === 'function'
|
|
2215
|
+
? requestAnimationFrame
|
|
2216
|
+
: (fn) => setTimeout(fn, 16);
|
|
2217
|
+
frame = raf(() => {
|
|
2218
|
+
frame = 0;
|
|
2219
|
+
try {
|
|
2220
|
+
sync();
|
|
2221
|
+
setAnchored(visible ? ensureRemoteFooterIcon(doc, node) : false);
|
|
2222
|
+
} catch {
|
|
2223
|
+
setAnchored(false);
|
|
2224
|
+
}
|
|
2225
|
+
});
|
|
2226
|
+
});
|
|
2227
|
+
observer.observe(doc.body, { childList: true, subtree: true });
|
|
2228
|
+
}
|
|
2229
|
+
return () => {
|
|
2230
|
+
if (observer !== null) observer.disconnect();
|
|
2231
|
+
if (frame !== 0 && typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame);
|
|
2232
|
+
if (typeof node.remove === 'function' && node.parentElement) node.remove();
|
|
2233
|
+
};
|
|
2234
|
+
}, [wide, visible, url, openLabel, problem, panelScope, webAccess]);
|
|
2235
|
+
|
|
2236
|
+
// 窄条,或认不出那一行:自己占一行,入口不能因为认不出位置就消失。
|
|
2237
|
+
if (!visible) return null;
|
|
2238
|
+
if (!wide || !anchored) {
|
|
2239
|
+
return h('a', {
|
|
2240
|
+
className: 'dshm_footAction dshm_footActionRail',
|
|
2241
|
+
href: url || undefined,
|
|
2242
|
+
target: '_blank',
|
|
2243
|
+
rel: 'noreferrer',
|
|
2244
|
+
'aria-label': openLabel,
|
|
2245
|
+
title: openLabel,
|
|
2246
|
+
'aria-disabled': 'false',
|
|
2247
|
+
onClick: openRemote,
|
|
2248
|
+
}, h('svg', {
|
|
2249
|
+
viewBox: '0 0 24 24',
|
|
2250
|
+
width: PHONE_GLYPH_RAIL,
|
|
2251
|
+
height: PHONE_GLYPH_RAIL,
|
|
2252
|
+
fill: 'none',
|
|
2253
|
+
stroke: 'currentColor',
|
|
2254
|
+
strokeWidth: 1.7,
|
|
2255
|
+
strokeLinecap: 'round',
|
|
2256
|
+
strokeLinejoin: 'round',
|
|
2257
|
+
'aria-hidden': 'true',
|
|
2258
|
+
focusable: 'false',
|
|
2259
|
+
}, COMPUTER_PATHS.map((d) => h('path', { key: d, d }))));
|
|
2260
|
+
}
|
|
2261
|
+
return null;
|
|
2262
|
+
}
|
|
2263
|
+
|
|
1842
2264
|
/**
|
|
1843
2265
|
* 客户端半边的自检上报:每 10s 把「这一半到底看见了什么」报给宿主。
|
|
1844
2266
|
*
|
|
@@ -2018,8 +2440,9 @@ window.__ModuleLoader__.load({
|
|
|
2018
2440
|
* 这一张是设置里的正规入口):介绍产品时说的入口就是「设置 → 移动端」,只留图标会让从
|
|
2019
2441
|
* 网页版进来的人不知道配置在哪。
|
|
2020
2442
|
*
|
|
2021
|
-
*
|
|
2022
|
-
*
|
|
2443
|
+
* 刻意只放轻量的设置:界面本体全在网页版里(A3-37),在这里再画一套等于长期维护第二套 UI,
|
|
2444
|
+
* 而两套迟早会打架。配置页卡只做两件事——说清配置在哪、把那一页开出来;开不出来就在卡上写
|
|
2445
|
+
* 原因。2026-11-17 用户要在这一页选侧边栏那两颗图标,才添了第二张小卡。
|
|
2023
2446
|
*/
|
|
2024
2447
|
function MobileSettingsSection({ t }) {
|
|
2025
2448
|
/** null = 还在问宿主;'' = 问到了但宿主没给地址(老版本或还没起来)。 */
|
|
@@ -2028,6 +2451,10 @@ window.__ModuleLoader__.load({
|
|
|
2028
2451
|
const [access, setAccess] = useState(null);
|
|
2029
2452
|
/** `null` = 这一次没出错;否则 `{ kind: 'load' | 'open', message }`。 */
|
|
2030
2453
|
const [failure, setFailure] = useState(null);
|
|
2454
|
+
/** 侧边栏两颗图标的选择,与那两颗图标共享同一份状态。 */
|
|
2455
|
+
const [icons, setIcons] = useState(footerIcons);
|
|
2456
|
+
const [iconError, setIconError] = useState('');
|
|
2457
|
+
useEffect(() => watchFooterIcons(setIcons), []);
|
|
2031
2458
|
|
|
2032
2459
|
useEffect(() => {
|
|
2033
2460
|
let alive = true;
|
|
@@ -2036,6 +2463,7 @@ window.__ModuleLoader__.load({
|
|
|
2036
2463
|
const next = await call('/status');
|
|
2037
2464
|
if (!alive) return;
|
|
2038
2465
|
const view = next && typeof next === 'object' ? next : {};
|
|
2466
|
+
adoptFooterIcons(view);
|
|
2039
2467
|
setUrl(typeof view.panelUrl === 'string' ? view.panelUrl : '');
|
|
2040
2468
|
setScope(typeof view.panelScope === 'string' ? view.panelScope : '');
|
|
2041
2469
|
setAccess(view.webAccess && typeof view.webAccess.enabled === 'boolean' ? view.webAccess : null);
|
|
@@ -2088,6 +2516,33 @@ window.__ModuleLoader__.load({
|
|
|
2088
2516
|
})();
|
|
2089
2517
|
}
|
|
2090
2518
|
|
|
2519
|
+
/**
|
|
2520
|
+
* 拨一颗图标的开关。至少留一颗:两颗都收起来,侧边栏就没有桌面入口了,用户回到这一页
|
|
2521
|
+
* 才能改回来——这不是「都关掉也行」的偏好,是别把人锁在门外。
|
|
2522
|
+
* 先改共享状态让图标当场跟着变,再落盘;写失败就把两颗都还原,并说清原因。
|
|
2523
|
+
*/
|
|
2524
|
+
async function toggleIcon(key) {
|
|
2525
|
+
const before = { ...icons };
|
|
2526
|
+
const other = key === 'phone' ? 'computer' : 'phone';
|
|
2527
|
+
if (before[key] && !before[other]) {
|
|
2528
|
+
setIconError(t('iconKeepOne'));
|
|
2529
|
+
return;
|
|
2530
|
+
}
|
|
2531
|
+
const next = { ...before, [key]: !before[key] };
|
|
2532
|
+
footerIconsTouched = true;
|
|
2533
|
+
setFooterIcons(next);
|
|
2534
|
+
setIconError('');
|
|
2535
|
+
try {
|
|
2536
|
+
await postJson('/config', {
|
|
2537
|
+
desktopPhoneIcon: next.phone,
|
|
2538
|
+
desktopComputerIcon: next.computer,
|
|
2539
|
+
});
|
|
2540
|
+
} catch (error) {
|
|
2541
|
+
setFooterIcons(before);
|
|
2542
|
+
setIconError(`${t('iconSaveFailed')}:${String((error && error.message) || error)}`);
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2091
2546
|
const hint = url === null ? t('panelPending') : url === '' ? t('panelMissing') : t('openHint');
|
|
2092
2547
|
return h('div', { className: 'dshm_root' },
|
|
2093
2548
|
h('h2', { className: 'dshm_heading' }, t('heading')),
|
|
@@ -2106,7 +2561,24 @@ window.__ModuleLoader__.load({
|
|
|
2106
2561
|
failure
|
|
2107
2562
|
? h('p', { className: 'dshm_error' },
|
|
2108
2563
|
`${failure.kind === 'load' ? t('loadFailed') : t('openFailed')}:${failure.message}`)
|
|
2109
|
-
: null)
|
|
2564
|
+
: null),
|
|
2565
|
+
h('div', { className: 'dshm_card' },
|
|
2566
|
+
h('h3', { className: 'dshm_cardTitle' }, t('iconsTitle')),
|
|
2567
|
+
h('p', { className: 'dshm_note' }, t('iconsHint')),
|
|
2568
|
+
[['phone', 'iconPhone'], ['computer', 'iconComputer']].map(([key, label]) => h('div', {
|
|
2569
|
+
key,
|
|
2570
|
+
className: 'dshm_iconRow',
|
|
2571
|
+
},
|
|
2572
|
+
h('span', {}, t(label)),
|
|
2573
|
+
h('button', {
|
|
2574
|
+
type: 'button',
|
|
2575
|
+
className: 'dshm_iconSwitch',
|
|
2576
|
+
role: 'switch',
|
|
2577
|
+
'aria-checked': icons[key] ? 'true' : 'false',
|
|
2578
|
+
'aria-label': t(label),
|
|
2579
|
+
onClick: () => void toggleIcon(key),
|
|
2580
|
+
}, t(icons[key] ? 'iconShown' : 'iconHidden')))),
|
|
2581
|
+
iconError ? h('p', { className: 'dshm_error' }, iconError) : null));
|
|
2110
2582
|
}
|
|
2111
2583
|
|
|
2112
2584
|
/* ── 聊天嵌入页:把网页定位到顶栏那条会话 ───────────────────────────────
|
|
@@ -2371,6 +2843,16 @@ window.__ModuleLoader__.load({
|
|
|
2371
2843
|
locale: NS,
|
|
2372
2844
|
inject: () => ({ t }),
|
|
2373
2845
|
}, MobileWebEntry));
|
|
2846
|
+
// 手机图标右边那颗电脑图标:远程电脑独立页的入口。展开态由组件自己插到手机图标
|
|
2847
|
+
// 后面(两个组件分别物化、谁先谁后不定,认手机图标的记号定位),窄条态各占一行。
|
|
2848
|
+
ctx.slots.inject(FOOTER_SLOT, () => ctx.slots.register({
|
|
2849
|
+
name: FOOTER_SLOT,
|
|
2850
|
+
id: 'remote-web',
|
|
2851
|
+
order: 11,
|
|
2852
|
+
label: () => t('footerRemoteOpen'),
|
|
2853
|
+
locale: NS,
|
|
2854
|
+
inject: () => ({ t }),
|
|
2855
|
+
}, RemoteWebEntry));
|
|
2374
2856
|
},
|
|
2375
2857
|
};
|
|
2376
2858
|
},
|