dsh-mobile-plugin 0.5.93 → 0.5.94
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/lib/client.js +53 -162
- package/lib/panel/index.html +5 -5
- package/lib/remote/routes.cjs +7 -5
- package/lib/routes/control-plane.js +19 -152
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 用途:桌面端入口与诊断反馈;打开配置页失败附带稳定原因码,不外发原始错误和访问凭据。
|
|
2
2
|
/**
|
|
3
3
|
* 移动端插件提供电脑插件页面目录;标准页面保留宿主上下文并支持直接导航。
|
|
4
4
|
* 聊天嵌入服务合并顶部栏显示声明,随提供方与消费方生命周期释放。
|
|
5
|
-
*
|
|
5
|
+
* 入口不看到达来源:本机、局域网、公网、反代后面都能直接进管理页。
|
|
6
6
|
*
|
|
7
7
|
* 五件事:桌面侧边栏的展开态与「读过了」报给宿主;手机端的已读回执应用回桌面绿点;
|
|
8
8
|
* 设置里那一项「移动端」(一张薄卡,一颗「打开配置页面」);在侧边栏最底下那一行挂两颗
|
|
@@ -280,22 +280,6 @@ window.__ModuleLoader__.load({
|
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
-
/**
|
|
284
|
-
* 打开那两小时网页管理窗口。
|
|
285
|
-
*
|
|
286
|
-
* 公网浏览器需要它:窗口关闭时面板会回 423。本机与局域网直连无需开窗。设置卡与
|
|
287
|
-
* 侧边栏图标都走这一份实现 —— 各写一遍迟早会在「窗口开着没有」上判得不一样,而这两种
|
|
288
|
-
* 判法对应的是「多开一次」与「跳过去吃一个 423」。
|
|
289
|
-
*
|
|
290
|
-
* 返回值是宿主回的新窗口状态,交给调用方存进自己的 state。
|
|
291
|
-
*/
|
|
292
|
-
async function requestAccessWindow() {
|
|
293
|
-
const next = await postJson('/web-access', { enabled: true });
|
|
294
|
-
return next && next.webAccess && typeof next.webAccess.enabled === 'boolean'
|
|
295
|
-
? next.webAccess
|
|
296
|
-
: { enabled: true, expiresAt: 0 };
|
|
297
|
-
}
|
|
298
|
-
|
|
299
283
|
/* ── 三:侧边栏未读绿点的双向同步 ───────────────────────────────────────
|
|
300
284
|
* 两端的绿点是两份互不相干的状态:
|
|
301
285
|
* - 手机端 = 宿主按设备维度维护的完成提醒(lib/mobile/completion.js),
|
|
@@ -598,7 +582,6 @@ window.__ModuleLoader__.load({
|
|
|
598
582
|
footerAgoMinutes: '{count} 分钟前',
|
|
599
583
|
footerAgoHours: '{count} 小时前',
|
|
600
584
|
footerAgoDays: '{count} 天前',
|
|
601
|
-
footerPublicConfirm: '这个地址位于公网。继续后会开放移动端插件的网页管理权限 2 小时;期间任何能访问该地址的人都可以操作面板。是否继续?',
|
|
602
585
|
footerLoadMissing: '插件宿主侧没有加载:把 DSH 完整退出再打开一次;还不行就在插件市场重装一遍插件。',
|
|
603
586
|
consoleTitle: '移动端插件控制台',
|
|
604
587
|
remoteConsoleTitle: '远程电脑',
|
|
@@ -606,7 +589,7 @@ window.__ModuleLoader__.load({
|
|
|
606
589
|
consoleLoading: '正在载入控制台…',
|
|
607
590
|
consoleFrameless: '控制台未能完成加载,请关闭后重新点图标,也可以在浏览器里打开。',
|
|
608
591
|
diagTitleLoad: '打不开移动端配置页',
|
|
609
|
-
diagTitleOpen: '
|
|
592
|
+
diagTitleOpen: '打开配置页面失败',
|
|
610
593
|
diagChecking: '正在读取宿主状态…',
|
|
611
594
|
diagBusy: '正在重读状态…',
|
|
612
595
|
diagHeadingFacts: '诊断读数(可直接复制发给维护者)',
|
|
@@ -625,8 +608,8 @@ window.__ModuleLoader__.load({
|
|
|
625
608
|
diagSummaryUnreachable: '宿主没有回应状态查询,这一版插件可能还没带自检口。',
|
|
626
609
|
diagSummaryNoError: '宿主自检说没报错,控制面路由却不在:多半是同一份 DSH 里跑着两份插件。',
|
|
627
610
|
diagSummaryLoadFailed: '读取宿主状态失败。',
|
|
628
|
-
diagSummaryOpenFailed: '
|
|
629
|
-
diagPopupBlocked: '
|
|
611
|
+
diagSummaryOpenFailed: '打开配置页面失败,所以没有跳转。',
|
|
612
|
+
diagPopupBlocked: '浏览器拦掉了这个新窗口。允许本站打开弹窗后再点一次图标。',
|
|
630
613
|
diagSummaryRestored: '状态已经读到了,可以再点一次图标。',
|
|
631
614
|
diagStepRestart: '把 DSH 完整退出(不是只关窗口)再打开一次——装完插件没重启是最常见的原因。',
|
|
632
615
|
diagStepReinstall: '还不行就在插件市场把这个插件重装一遍,装完再完整重启一次 DSH。',
|
|
@@ -647,7 +630,6 @@ window.__ModuleLoader__.load({
|
|
|
647
630
|
diagFactReason: '宿主侧原因',
|
|
648
631
|
diagFactPanelUrl: '面板地址',
|
|
649
632
|
diagFactScope: '地址类别',
|
|
650
|
-
diagFactWindow: '两小时窗口',
|
|
651
633
|
},
|
|
652
634
|
en: {
|
|
653
635
|
pluginPages: 'Computer plugins',
|
|
@@ -688,7 +670,6 @@ window.__ModuleLoader__.load({
|
|
|
688
670
|
footerAgoMinutes: '{count} min ago',
|
|
689
671
|
footerAgoHours: '{count} h ago',
|
|
690
672
|
footerAgoDays: '{count} d ago',
|
|
691
|
-
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?',
|
|
692
673
|
footerLoadMissing: 'The plugin host half is not loaded: quit and reopen DSH; if that does not help, reinstall the plugin from the market.',
|
|
693
674
|
consoleTitle: 'Mobile plugin console',
|
|
694
675
|
remoteConsoleTitle: 'Remote computers',
|
|
@@ -696,7 +677,7 @@ window.__ModuleLoader__.load({
|
|
|
696
677
|
consoleLoading: 'Loading the console…',
|
|
697
678
|
consoleFrameless: 'The console could not finish loading. Close this pane and press the icon again, or open it in a browser.',
|
|
698
679
|
diagTitleLoad: 'Cannot open the mobile configuration page',
|
|
699
|
-
diagTitleOpen: 'Could not open
|
|
680
|
+
diagTitleOpen: 'Could not open the configuration page',
|
|
700
681
|
diagChecking: 'Reading host status…',
|
|
701
682
|
diagBusy: 'Reading host status again…',
|
|
702
683
|
diagHeadingFacts: 'Diagnostics (copy and send these to the maintainer)',
|
|
@@ -715,8 +696,8 @@ window.__ModuleLoader__.load({
|
|
|
715
696
|
diagSummaryUnreachable: 'The host did not answer the status query; this plugin build may not ship the self-check route yet.',
|
|
716
697
|
diagSummaryNoError: 'The host self-check reports no error, yet the control-plane routes are missing: most likely two copies of the plugin in one DSH.',
|
|
717
698
|
diagSummaryLoadFailed: 'Reading the host status failed.',
|
|
718
|
-
diagSummaryOpenFailed: '
|
|
719
|
-
diagPopupBlocked: '
|
|
699
|
+
diagSummaryOpenFailed: 'Could not open the configuration page, so nothing was opened.',
|
|
700
|
+
diagPopupBlocked: 'The browser blocked the new window. Allow pop-ups for this site, then press the icon again.',
|
|
720
701
|
diagSummaryRestored: 'Status is readable again — try the icon once more.',
|
|
721
702
|
diagStepRestart: 'Quit DSH completely (not just the window) and open it again — not restarting after installing is the most common cause.',
|
|
722
703
|
diagStepReinstall: 'If that does not help, reinstall the plugin from the market, then restart DSH completely.',
|
|
@@ -737,7 +718,6 @@ window.__ModuleLoader__.load({
|
|
|
737
718
|
diagFactReason: 'Host-side reason',
|
|
738
719
|
diagFactPanelUrl: 'Panel URL',
|
|
739
720
|
diagFactScope: 'Address class',
|
|
740
|
-
diagFactWindow: 'Two-hour window',
|
|
741
721
|
},
|
|
742
722
|
};
|
|
743
723
|
|
|
@@ -1021,7 +1001,7 @@ window.__ModuleLoader__.load({
|
|
|
1021
1001
|
if (spec.body) card.appendChild(spec.body);
|
|
1022
1002
|
// 内嵌一整页(控制台 / 远程电脑那一窗):外壳里 `window.open` 不可靠,所以把页面嵌进来。
|
|
1023
1003
|
// `src` 已经由调用方按同源地址算好(壳里是 `dsh-app://app/api/relay/panel/console`,
|
|
1024
|
-
// 网页里是同源 http
|
|
1004
|
+
// 网页里是同源 http)。
|
|
1025
1005
|
//
|
|
1026
1006
|
// load 只说明文档结束导航;空页、错误响应、脚本启动失败都不能算控制台就绪。
|
|
1027
1007
|
if (spec.frame && spec.frame.src) {
|
|
@@ -1204,7 +1184,6 @@ window.__ModuleLoader__.load({
|
|
|
1204
1184
|
return {
|
|
1205
1185
|
panelUrl: typeof value.panelUrl === 'string' ? value.panelUrl : '',
|
|
1206
1186
|
panelScope: typeof value.panelScope === 'string' ? value.panelScope : '',
|
|
1207
|
-
webAccess: value.webAccess && typeof value.webAccess.enabled === 'boolean' ? value.webAccess : null,
|
|
1208
1187
|
// 图标与入口那一句要用的现场:配了几台手机、链路有没有断。与上面三样同一条 `/status`,
|
|
1209
1188
|
// 不多打一次接口 —— 那份读数本来就是「此刻这台宿主怎么样」。
|
|
1210
1189
|
devices: value.devices && typeof value.devices === 'object' ? value.devices : null,
|
|
@@ -1264,8 +1243,7 @@ window.__ModuleLoader__.load({
|
|
|
1264
1243
|
* **2026-11-13 起地址只认这一条**:云服务器上用户是用公网 IP / 域名打开 DSH 的,而宿主
|
|
1265
1244
|
* 按 Host 头拼出来的 `panelUrl` 常常是 `127.0.0.1:<端口>` —— 拿它去开窗,浏览器就跑到
|
|
1266
1245
|
* 用户自己那台电脑上找服务,必然打不开。`baseURI` 是**用户此刻正在用的地址**,公网打开
|
|
1267
|
-
*
|
|
1268
|
-
* 不再决定「开到哪儿去」。
|
|
1246
|
+
* 就是公网、反代子路径自带前缀,这才是对的。
|
|
1269
1247
|
*/
|
|
1270
1248
|
function panelPageUrlOf(page) {
|
|
1271
1249
|
try {
|
|
@@ -1280,24 +1258,18 @@ window.__ModuleLoader__.load({
|
|
|
1280
1258
|
}
|
|
1281
1259
|
|
|
1282
1260
|
/**
|
|
1283
|
-
*
|
|
1284
|
-
*
|
|
1285
|
-
* 为什么不能只读一次 `/status`:那条接口自己也在窗口门后面(`WEB_ACCESS_ROUTES`),
|
|
1286
|
-
* 窗口关着时公网浏览器只拿得到 423。而客户端原先规定「没地址就不去开窗口」,
|
|
1287
|
-
* 两边互相锁死 —— 远程用户点了只会看到「网页地址还没就绪」,没有任何顺序能走通。
|
|
1288
|
-
* 所以读不到地址时正确的动作不是放弃,而是**先开窗**:
|
|
1289
|
-
* 那条开关接口本来就对同源页面豁免,开完再读一次,地址与类别就都有了。
|
|
1261
|
+
* 一次「打开配置页面」的完整拨号:取地址、把地址交出去。
|
|
1290
1262
|
*
|
|
1291
1263
|
* 地址优先用宿主给的 `panelUrl`,拿不到再用页面自己的同源地址(见 `sameOriginPanelUrl`)。
|
|
1264
|
+
* 读不到地址时补读一次:可能只是页面上那次读取还没回来,或者刚才网络抖了一下。
|
|
1292
1265
|
*
|
|
1293
1266
|
* 新窗口必须由调用方在**点击那一帧**开出来(`window.open('')`),这里只负责导航它;
|
|
1294
|
-
*
|
|
1295
|
-
* 不再问第二遍;地址是自救拿到的,类别此前不知道,所以在这里补问)。
|
|
1267
|
+
* 等接口回来再开会被弹窗拦截器吃掉。
|
|
1296
1268
|
*
|
|
1297
|
-
* @returns {Promise<{ok: true, cancelled?: boolean, url: string
|
|
1269
|
+
* @returns {Promise<{ok: true, cancelled?: boolean, url: string}
|
|
1298
1270
|
* | {ok: false, missing: boolean, status: number, message: string}>}
|
|
1299
1271
|
*/
|
|
1300
|
-
async function openConfigurationPage({ view, loadStatus = 0, t, target = null,
|
|
1272
|
+
async function openConfigurationPage({ view, loadStatus = 0, t, target = null, navigate = true }) {
|
|
1301
1273
|
let state = readStatusView(view);
|
|
1302
1274
|
const failed = (error) => ({
|
|
1303
1275
|
ok: false,
|
|
@@ -1317,14 +1289,7 @@ window.__ModuleLoader__.load({
|
|
|
1317
1289
|
if ((Number(error && error.status) || 0) === 404) {
|
|
1318
1290
|
return { ok: false, missing: true, status: 404, message: '' };
|
|
1319
1291
|
}
|
|
1320
|
-
|
|
1321
|
-
// 也正因为原先把这一步排在了「拿到地址之后」,两个条件互等,谁都过不去。
|
|
1322
|
-
try {
|
|
1323
|
-
const opened = await requestAccessWindow();
|
|
1324
|
-
state = { ...readStatusView(await call('/status')), webAccess: opened };
|
|
1325
|
-
} catch (inner) {
|
|
1326
|
-
return failed(inner);
|
|
1327
|
-
}
|
|
1292
|
+
return failed(error);
|
|
1328
1293
|
}
|
|
1329
1294
|
if (!state.panelUrl) {
|
|
1330
1295
|
return { ok: false, missing: false, status: 0, code: 'panel-url-missing', message: t('panelMissing') };
|
|
@@ -1334,37 +1299,21 @@ window.__ModuleLoader__.load({
|
|
|
1334
1299
|
const url = state.panelUrl || sameOriginPanelUrl();
|
|
1335
1300
|
if (!url) return { ok: false, missing: false, status: 0, code: 'panel-url-missing', message: t('panelMissing') };
|
|
1336
1301
|
|
|
1337
|
-
if (state.panelScope === 'public'
|
|
1338
|
-
&& !confirmed
|
|
1339
|
-
&& typeof window !== 'undefined'
|
|
1340
|
-
&& typeof window.confirm === 'function'
|
|
1341
|
-
&& !window.confirm(t('footerPublicConfirm'))) {
|
|
1342
|
-
return { ok: true, cancelled: true, url, webAccess: state.webAccess };
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
if (state.panelScope !== 'loopback' && state.panelScope !== 'private' && !(state.webAccess && state.webAccess.enabled)) {
|
|
1346
|
-
try {
|
|
1347
|
-
state.webAccess = await requestAccessWindow();
|
|
1348
|
-
} catch (error) {
|
|
1349
|
-
return failed(error);
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
1302
|
if (target) {
|
|
1354
1303
|
target.location.href = url;
|
|
1355
|
-
return { ok: true, url
|
|
1304
|
+
return { ok: true, url };
|
|
1356
1305
|
}
|
|
1357
|
-
// `navigate: false` =
|
|
1306
|
+
// `navigate: false` = 只要地址,别开任何窗口:
|
|
1358
1307
|
// 控制台那一窗是把这一页**嵌进来**,多开一个浏览器窗口等于点了就跳走。
|
|
1359
|
-
if (navigate === false) return { ok: true, url
|
|
1308
|
+
if (navigate === false) return { ok: true, url };
|
|
1360
1309
|
if (!isWebPage(window)) {
|
|
1361
1310
|
// 交回给页面导航:壳会把外部 http(s) 地址转给系统浏览器。
|
|
1362
1311
|
window.location.href = url;
|
|
1363
|
-
return { ok: true, url
|
|
1312
|
+
return { ok: true, url };
|
|
1364
1313
|
}
|
|
1365
1314
|
const opened = typeof window.open === 'function' ? window.open(url, '_blank', 'noreferrer') : null;
|
|
1366
1315
|
if (!opened) return { ok: false, missing: false, status: 0, code: 'popup-blocked', message: t('diagPopupBlocked') };
|
|
1367
|
-
return { ok: true, url
|
|
1316
|
+
return { ok: true, url };
|
|
1368
1317
|
}
|
|
1369
1318
|
|
|
1370
1319
|
/* ── 侧边栏底部那颗手机图标 ────────────────────────────────────────────
|
|
@@ -1564,13 +1513,13 @@ window.__ModuleLoader__.load({
|
|
|
1564
1513
|
* 把「打开哪一页 / 现在是什么状态」同步到元素上。
|
|
1565
1514
|
*
|
|
1566
1515
|
* 没有地址时**不写 href**(没有地址可写,别挂死链),但**点击处理照样挂上**:那颗图标的
|
|
1567
|
-
*
|
|
1568
|
-
*
|
|
1516
|
+
* 点击会自己补读一次地址(见 `openConfigurationPage`)。别把 `onclick` 一起摘掉 ——
|
|
1517
|
+
* 摘了就是「点了完全没反应」。
|
|
1569
1518
|
*
|
|
1570
1519
|
* `tone` 三档:`''` 正常、`'warn'` 有问题但插件没坏(琥珀)、`'error'` 真故障(红)。
|
|
1571
1520
|
* 换的只是记号与颜色,图形和尺寸一个像素都不动 —— 那一行是外壳的,动尺寸就会挤到别人。
|
|
1572
1521
|
*
|
|
1573
|
-
*
|
|
1522
|
+
* 地址与网络类别都由 effect 往上同步,组件重渲染不会把它丢掉。
|
|
1574
1523
|
*/
|
|
1575
1524
|
function syncFooterIcon(node, { href, label, onClick, tone }) {
|
|
1576
1525
|
node.setAttribute('aria-label', label);
|
|
@@ -1580,8 +1529,8 @@ window.__ModuleLoader__.load({
|
|
|
1580
1529
|
else node.removeAttribute(FOOTER_ALERT);
|
|
1581
1530
|
if (tone === 'warn') node.setAttribute(FOOTER_WARN, '');
|
|
1582
1531
|
else node.removeAttribute(FOOTER_WARN);
|
|
1583
|
-
// 有地址时仍然写 `href`:普通链接照旧能中键 /
|
|
1584
|
-
//
|
|
1532
|
+
// 有地址时仍然写 `href`:普通链接照旧能中键 / 新标签打开。地址还没读到时才拦下来
|
|
1533
|
+
// 补读一次,见 `openPanel`。
|
|
1585
1534
|
if (href) node.setAttribute('href', href);
|
|
1586
1535
|
else node.removeAttribute('href');
|
|
1587
1536
|
node.onclick = onClick;
|
|
@@ -1697,8 +1646,7 @@ window.__ModuleLoader__.load({
|
|
|
1697
1646
|
*
|
|
1698
1647
|
* 点下去做什么:宿主在 `/status` 上按请求 Host 报一个
|
|
1699
1648
|
* `panelScope`,图标据此分流:
|
|
1700
|
-
* - `loopback` / `private
|
|
1701
|
-
* - `public`:公网入口先确认,再开启两小时只读管理窗口。
|
|
1649
|
+
* - `loopback` / `private` / `public`:都直接进入控制台,不再按来源分流。
|
|
1702
1650
|
*
|
|
1703
1651
|
* **打不开的时候不许「点了没反应」**:一律弹诊断窗——宿主与外壳各说了什么、用户自己
|
|
1704
1652
|
* 能做的几步检查、能一键试的修复(重新装载 / 重读状态),以及一段可复制的读数。
|
|
@@ -1771,7 +1719,6 @@ window.__ModuleLoader__.load({
|
|
|
1771
1719
|
function MobileWebEntry({ wide, t, tf }) {
|
|
1772
1720
|
/** null = 还没问到;'' = 问到了但宿主没给地址(老版本或还没起来)。 */
|
|
1773
1721
|
const [url, setUrl] = useState(null);
|
|
1774
|
-
const [webAccess, setWebAccess] = useState(null);
|
|
1775
1722
|
/** 面板地址落在哪类网络上:`loopback` / `private` / `public`(宿主算好给的)。 */
|
|
1776
1723
|
const [panelScope, setPanelScope] = useState('');
|
|
1777
1724
|
/** 最近一次读状态失败的原因(`null` = 没失败过);`status: 404` = 实现那一半没装载。 */
|
|
@@ -1802,13 +1749,12 @@ window.__ModuleLoader__.load({
|
|
|
1802
1749
|
const openLabel = t('footerOpen');
|
|
1803
1750
|
const pendingLabel = t('footerPending');
|
|
1804
1751
|
const loadMissingLabel = t('footerLoadMissing');
|
|
1805
|
-
const publicConfirm = t('footerPublicConfirm');
|
|
1806
1752
|
/** 「需要重启」那颗按钮的无障碍名字/悬停提示。 */
|
|
1807
1753
|
const restartLabel = t('restartNoticeButton');
|
|
1808
1754
|
/**
|
|
1809
1755
|
* 宿主那一半没装载(`/status` 404):点了也打不开、重装前谁也修不好,所以这一种是
|
|
1810
1756
|
* **真故障**,那颗图标转红告警;标题也换成更具体的那一句。地址只是还没读到(后台
|
|
1811
|
-
*
|
|
1757
|
+
* 重试中),都不是插件坏了,不红。
|
|
1812
1758
|
*/
|
|
1813
1759
|
const hostMissing = Boolean(problem && problem.status === 404);
|
|
1814
1760
|
|
|
@@ -1821,7 +1767,7 @@ window.__ModuleLoader__.load({
|
|
|
1821
1767
|
}
|
|
1822
1768
|
|
|
1823
1769
|
/**
|
|
1824
|
-
* 拉一次宿主状态,把地址 / 分类 /
|
|
1770
|
+
* 拉一次宿主状态,把地址 / 分类 / 失败原因同步进 state。
|
|
1825
1771
|
*
|
|
1826
1772
|
* 返回值给调用方用(诊断窗要拿最新那一份读数,不能读组件里那份可能还没更新的状态):
|
|
1827
1773
|
* `{ ok: true, status }` 或 `{ ok: false, problem }`。
|
|
@@ -1833,7 +1779,6 @@ window.__ModuleLoader__.load({
|
|
|
1833
1779
|
adoptFooterIcons(view);
|
|
1834
1780
|
const summary = readStatusView(view);
|
|
1835
1781
|
setUrl(summary.panelUrl);
|
|
1836
|
-
setWebAccess(summary.webAccess);
|
|
1837
1782
|
setPanelScope(summary.panelScope);
|
|
1838
1783
|
setFault(summary.fault);
|
|
1839
1784
|
setHint(hintOf(summary));
|
|
@@ -1878,7 +1823,7 @@ window.__ModuleLoader__.load({
|
|
|
1878
1823
|
* 三档状态:正常 / 有问题(琥珀)/ 真故障(红)。
|
|
1879
1824
|
*
|
|
1880
1825
|
* 红只留给「点了也没用」的那一种(宿主那一半没装载);链路报错是琥珀——面板还能开,
|
|
1881
|
-
*
|
|
1826
|
+
* 只是现在连不通。地址还没读到(后台重试中)也算正常态:
|
|
1882
1827
|
* 那种情况每开一次页面都会出现,一有它就变脸等于天天报假警。
|
|
1883
1828
|
*/
|
|
1884
1829
|
function footerState() {
|
|
@@ -1906,15 +1851,6 @@ window.__ModuleLoader__.load({
|
|
|
1906
1851
|
return t('footerAgoDays', { count: Math.floor(hours / 24) });
|
|
1907
1852
|
}
|
|
1908
1853
|
|
|
1909
|
-
/**
|
|
1910
|
-
* 点下去要做什么,取决于面板地址落在哪一类网络上(宿主在 `/status` 上算的 `panelScope`)。
|
|
1911
|
-
*
|
|
1912
|
-
* 有地址且来自本机或局域网:普通链接,交给浏览器自己开。
|
|
1913
|
-
* 公网页面或还没读到地址时,需要先取得管理窗口:
|
|
1914
|
-
* 新窗口必须在**点击这一帧**开出来(`window.open('', '_blank')`),等接口回来再开会被
|
|
1915
|
-
* 浏览器的弹窗拦截器吃掉;地址确认到之后才把那个空窗口导航过去,失败就关掉它并弹诊断。
|
|
1916
|
-
* 只有**网页**(`http(s)`)才需要这一手:桌面壳里那个函数一定被拒,见 `isWebPage`。
|
|
1917
|
-
*/
|
|
1918
1854
|
/**
|
|
1919
1855
|
* 点下去做什么。
|
|
1920
1856
|
*
|
|
@@ -1923,36 +1859,23 @@ window.__ModuleLoader__.load({
|
|
|
1923
1859
|
* 里,比一个打不开的页面有用。跳转本身没取消,挪进了那一屏里的一颗按钮。
|
|
1924
1860
|
*
|
|
1925
1861
|
* 那一屏的内容是网页版的 `/api/relay/panel/console`(React 写的,改完刷新就见效),
|
|
1926
|
-
*
|
|
1927
|
-
* 423 JSON:所以公网入口先按 `panelScope` 开好两小时窗口,本机和局域网直接进入。
|
|
1862
|
+
* 这里只把同源地址算出来嵌进去。控制面现在不按来源拦,嵌进来的就是面板本身。
|
|
1928
1863
|
*
|
|
1929
1864
|
* 三种走不通的情况一律回到诊断窗(外壳里 `window.open` 不可靠、宿主那一半没装载、
|
|
1930
1865
|
* 窗口开不出来)—— 不许「点了没反应」。
|
|
1931
1866
|
*/
|
|
1932
1867
|
function openPanel(event) {
|
|
1933
1868
|
if (event && typeof event.preventDefault === 'function') event.preventDefault();
|
|
1934
|
-
// 公网地址先问一句——但**只在真要开那两小时窗口的时候问**:窗口已经开着,
|
|
1935
|
-
// 这一下没有扩大任何权限,再弹一次只是把上一轮点过的确认重问一遍。
|
|
1936
|
-
const willOpenWindow = panelScope !== 'loopback' && panelScope !== 'private' && !(webAccess && webAccess.enabled);
|
|
1937
|
-
if (panelScope === 'public'
|
|
1938
|
-
&& url
|
|
1939
|
-
&& willOpenWindow
|
|
1940
|
-
&& typeof window !== 'undefined'
|
|
1941
|
-
&& typeof window.confirm === 'function'
|
|
1942
|
-
&& !window.confirm(publicConfirm)) return;
|
|
1943
1869
|
// 桌面壳(`dsh-app://app`)里不嵌:往自定义协议页里塞一条 http(s) iframe,多半被
|
|
1944
1870
|
// 当成混合内容挡掉,用户看到的是一窗空白。那种环境仍走「交给系统浏览器」那条老路
|
|
1945
1871
|
//(`navigate` 默认 true,壳的 `will-navigate` 会把它转给系统浏览器)。
|
|
1946
1872
|
void (async () => {
|
|
1947
1873
|
const outcome = await openConsole({
|
|
1948
|
-
view: { panelUrl: url || '', panelScope
|
|
1874
|
+
view: { panelUrl: url || '', panelScope },
|
|
1949
1875
|
loadStatus: problem ? problem.status : 0,
|
|
1950
1876
|
t,
|
|
1951
1877
|
});
|
|
1952
|
-
if (outcome.ok)
|
|
1953
|
-
if (outcome.webAccess) setWebAccess(outcome.webAccess);
|
|
1954
|
-
return;
|
|
1955
|
-
}
|
|
1878
|
+
if (outcome.ok) return;
|
|
1956
1879
|
// 宿主那一半压根没装载:那是一屏「装完没重启」,不是这一屏能修的。
|
|
1957
1880
|
if (outcome.missing) {
|
|
1958
1881
|
void openDiagnosis('load', { status: outcome.status || 404, message: (problem && problem.message) || '' });
|
|
@@ -1966,12 +1889,12 @@ window.__ModuleLoader__.load({
|
|
|
1966
1889
|
* 把「控制台」那一屏画出来:标题 + 一颗「在浏览器里打开」+ 内嵌的调试页。
|
|
1967
1890
|
*
|
|
1968
1891
|
* 嵌的是同一台宿主吐的页面(同源),所以它读 `/api/relay/*` 和面板页一模一样,
|
|
1969
|
-
* 不需要 token
|
|
1970
|
-
*
|
|
1892
|
+
* 不需要 token、也不新增接口。`openConfigurationPage` 只确认地址可用(`target` 传 null,
|
|
1893
|
+
* 不导航任何地方),页面本身由下面这扇窗嵌进来。
|
|
1971
1894
|
*/
|
|
1972
1895
|
async function openConsole({ view, loadStatus, t }) {
|
|
1973
1896
|
if (typeof document === 'undefined') return { ok: false, missing: false, status: 0, code: 'panel-url-missing', message: t('panelMissing') };
|
|
1974
|
-
const outcome = await openConfigurationPage({ view, loadStatus, t, target: null,
|
|
1897
|
+
const outcome = await openConfigurationPage({ view, loadStatus, t, target: null, navigate: false });
|
|
1975
1898
|
if (!outcome.ok) return outcome;
|
|
1976
1899
|
const consolePage = panelPageUrlOf('console');
|
|
1977
1900
|
if (!consolePage) return { ok: false, missing: false, status: 0, code: 'panel-url-missing', message: t('panelMissing') };
|
|
@@ -2033,14 +1956,14 @@ window.__ModuleLoader__.load({
|
|
|
2033
1956
|
else if (action === 'close') dialog.hide();
|
|
2034
1957
|
},
|
|
2035
1958
|
});
|
|
2036
|
-
return { ok: true
|
|
1959
|
+
return { ok: true };
|
|
2037
1960
|
}
|
|
2038
1961
|
|
|
2039
1962
|
/**
|
|
2040
1963
|
* 把这一轮的现场摆成一屏**能自己动手**的自查。
|
|
2041
1964
|
*
|
|
2042
|
-
* `kind` 两种:`'load'`(连状态都读不到,所以没有地址可去)、`'open'
|
|
2043
|
-
*
|
|
1965
|
+
* `kind` 两种:`'load'`(连状态都读不到,所以没有地址可去)、`'open'`(地址读到了但
|
|
1966
|
+
* 页面没开成)。前者的首要原因是「装完没重启」,后者先重试再看反代。
|
|
2044
1967
|
*
|
|
2045
1968
|
* 这一屏的三个层次,顺序就是用户该想的顺序:
|
|
2046
1969
|
* 1. 谁说了什么(宿主返回的原文 + 外壳自检那份快照,含版本/来源/后台重试/要不要重启);
|
|
@@ -2054,7 +1977,6 @@ window.__ModuleLoader__.load({
|
|
|
2054
1977
|
const snapshot = {
|
|
2055
1978
|
url: typeof url === 'string' ? url : '',
|
|
2056
1979
|
scope: panelScope || 'unknown',
|
|
2057
|
-
access: webAccess,
|
|
2058
1980
|
};
|
|
2059
1981
|
let current = failure || problem || null;
|
|
2060
1982
|
let half = null;
|
|
@@ -2067,7 +1989,6 @@ window.__ModuleLoader__.load({
|
|
|
2067
1989
|
const next = status && typeof status === 'object' ? status : {};
|
|
2068
1990
|
snapshot.url = typeof next.panelUrl === 'string' ? next.panelUrl : '';
|
|
2069
1991
|
snapshot.scope = typeof next.panelScope === 'string' ? next.panelScope : 'unknown';
|
|
2070
|
-
snapshot.access = next.webAccess && typeof next.webAccess.enabled === 'boolean' ? next.webAccess : null;
|
|
2071
1992
|
};
|
|
2072
1993
|
|
|
2073
1994
|
/** 问外壳那份自检(实现挂了它还在):原因、版本、后台重试都在这儿。 */
|
|
@@ -2109,11 +2030,6 @@ window.__ModuleLoader__.load({
|
|
|
2109
2030
|
}
|
|
2110
2031
|
rows.push({ key: 'panel_url', label: t('diagFactPanelUrl'), value: snapshot.url || '—' });
|
|
2111
2032
|
rows.push({ key: 'panel_scope', label: t('diagFactScope'), value: snapshot.scope });
|
|
2112
|
-
rows.push({
|
|
2113
|
-
key: 'web_access',
|
|
2114
|
-
label: t('diagFactWindow'),
|
|
2115
|
-
value: snapshot.access && snapshot.access.enabled ? `open → ${new Date(snapshot.access.expiresAt).toISOString()}` : 'closed',
|
|
2116
|
-
});
|
|
2117
2033
|
return rows;
|
|
2118
2034
|
};
|
|
2119
2035
|
|
|
@@ -2374,7 +2290,7 @@ window.__ModuleLoader__.load({
|
|
|
2374
2290
|
if (frame !== 0 && typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame);
|
|
2375
2291
|
if (typeof node.remove === 'function' && node.parentElement) node.remove();
|
|
2376
2292
|
};
|
|
2377
|
-
}, [wide, visible, url, openLabel, loadMissingLabel, pendingLabel, problem, panelScope,
|
|
2293
|
+
}, [wide, visible, url, openLabel, loadMissingLabel, pendingLabel, problem, panelScope, hint, fault, restartPending, restartLabel]);
|
|
2378
2294
|
|
|
2379
2295
|
// 窄条,或者这一版外壳里认不出那一行:自己占一行,入口不能因为认不出位置就消失。
|
|
2380
2296
|
// 收起来的那一颗例外:它这一页里根本不该再有入口。
|
|
@@ -2422,16 +2338,14 @@ window.__ModuleLoader__.load({
|
|
|
2422
2338
|
/**
|
|
2423
2339
|
* 侧边栏底部那颗电脑图标(远程电脑独立页的入口)。
|
|
2424
2340
|
*
|
|
2425
|
-
*
|
|
2426
|
-
* 同一条 `/status` 来。它只是打开另一条面板页(`/api/relay/panel/remote`),所以没有
|
|
2341
|
+
* 与手机图标并排,共用同一套状态读数:地址与网络类别都从同一条 `/status` 来。它只是打开另一条面板页(`/api/relay/panel/remote`),所以没有
|
|
2427
2342
|
* 手机图标那一套链路告警着色——这一颗是纯入口,状态色交给旁边那颗去说。
|
|
2428
2343
|
*
|
|
2429
|
-
*
|
|
2430
|
-
*
|
|
2344
|
+
* 点下去和手机图标一样弹一扇内嵌窗(不是跳走),不再按来源分流。打不开时落到诊断窗,
|
|
2345
|
+
* 不许「点了没反应」。
|
|
2431
2346
|
*/
|
|
2432
2347
|
function RemoteWebEntry({ wide, t, tf }) {
|
|
2433
2348
|
const [url, setUrl] = useState(null);
|
|
2434
|
-
const [webAccess, setWebAccess] = useState(null);
|
|
2435
2349
|
const [panelScope, setPanelScope] = useState('');
|
|
2436
2350
|
const [problem, setProblem] = useState(null);
|
|
2437
2351
|
const [anchored, setAnchored] = useState(true);
|
|
@@ -2447,14 +2361,13 @@ window.__ModuleLoader__.load({
|
|
|
2447
2361
|
const openLabel = t('footerRemoteOpen');
|
|
2448
2362
|
const pendingLabel = t('footerPending');
|
|
2449
2363
|
|
|
2450
|
-
/**
|
|
2364
|
+
/** 拉一次状态;电脑图标只要地址,不碰设备数与链路告警。 */
|
|
2451
2365
|
async function refreshStatus() {
|
|
2452
2366
|
try {
|
|
2453
2367
|
const next = await call('/status');
|
|
2454
2368
|
const view = readStatusView(next);
|
|
2455
2369
|
adoptFooterIcons(next);
|
|
2456
2370
|
setUrl(view.panelUrl);
|
|
2457
|
-
setWebAccess(view.webAccess);
|
|
2458
2371
|
setPanelScope(view.panelScope);
|
|
2459
2372
|
setProblem(null);
|
|
2460
2373
|
return { ok: true, status: next };
|
|
@@ -2487,7 +2400,6 @@ window.__ModuleLoader__.load({
|
|
|
2487
2400
|
const snapshot = {
|
|
2488
2401
|
url: typeof url === 'string' ? url : '',
|
|
2489
2402
|
scope: panelScope || 'unknown',
|
|
2490
|
-
access: webAccess,
|
|
2491
2403
|
};
|
|
2492
2404
|
const closeAction = { label: t('diagClose'), onClick: () => view.hide() };
|
|
2493
2405
|
const readHalf = async () => {
|
|
@@ -2564,25 +2476,20 @@ window.__ModuleLoader__.load({
|
|
|
2564
2476
|
}
|
|
2565
2477
|
|
|
2566
2478
|
/**
|
|
2567
|
-
*
|
|
2479
|
+
* 点电脑图标:弹一扇内嵌远程电脑页的窗。
|
|
2568
2480
|
*
|
|
2569
|
-
* 与手机图标走的是同一条 `openConfigurationPage`
|
|
2570
|
-
* 区别只在内嵌的是 `/remote` 那一页。新窗口不在这里开:`navigate:false`
|
|
2481
|
+
* 与手机图标走的是同一条 `openConfigurationPage` 拨号(只确认地址可用),
|
|
2482
|
+
* 区别只在内嵌的是 `/remote` 那一页。新窗口不在这里开:`navigate:false` 只确认地址,
|
|
2571
2483
|
* 页面本身嵌进诊断窗的 iframe。
|
|
2572
2484
|
*/
|
|
2573
2485
|
function openRemote(event) {
|
|
2574
2486
|
if (event && typeof event.preventDefault === 'function') event.preventDefault();
|
|
2575
|
-
const willOpenWindow = panelScope !== 'loopback' && panelScope !== 'private' && !(webAccess && webAccess.enabled);
|
|
2576
|
-
if (panelScope === 'public' && url && willOpenWindow
|
|
2577
|
-
&& typeof window !== 'undefined' && typeof window.confirm === 'function'
|
|
2578
|
-
&& !window.confirm(t('footerPublicConfirm'))) return;
|
|
2579
2487
|
void (async () => {
|
|
2580
2488
|
const outcome = await openConfigurationPage({
|
|
2581
|
-
view: { panelUrl: url || '', panelScope
|
|
2489
|
+
view: { panelUrl: url || '', panelScope },
|
|
2582
2490
|
loadStatus: problem ? problem.status : 0,
|
|
2583
2491
|
t,
|
|
2584
2492
|
target: null,
|
|
2585
|
-
confirmed: true,
|
|
2586
2493
|
navigate: false,
|
|
2587
2494
|
});
|
|
2588
2495
|
if (!outcome.ok) {
|
|
@@ -2590,7 +2497,6 @@ window.__ModuleLoader__.load({
|
|
|
2590
2497
|
else void openDiagnosis({ status: outcome.status || 0, code: outcome.code || '', message: outcome.message });
|
|
2591
2498
|
return;
|
|
2592
2499
|
}
|
|
2593
|
-
if (outcome.webAccess) setWebAccess(outcome.webAccess);
|
|
2594
2500
|
const remotePage = panelPageUrlOf('remote');
|
|
2595
2501
|
if (!remotePage) {
|
|
2596
2502
|
void openDiagnosis({ status: 0, message: t('panelMissing') });
|
|
@@ -2712,7 +2618,7 @@ window.__ModuleLoader__.load({
|
|
|
2712
2618
|
if (frame !== 0 && typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame);
|
|
2713
2619
|
if (typeof node.remove === 'function' && node.parentElement) node.remove();
|
|
2714
2620
|
};
|
|
2715
|
-
}, [wide, visible, url, openLabel, problem, panelScope
|
|
2621
|
+
}, [wide, visible, url, openLabel, problem, panelScope]);
|
|
2716
2622
|
|
|
2717
2623
|
// 窄条,或认不出那一行:自己占一行,入口不能因为认不出位置就消失。
|
|
2718
2624
|
if (!visible) return null;
|
|
@@ -2929,7 +2835,6 @@ window.__ModuleLoader__.load({
|
|
|
2929
2835
|
/** null = 还在问宿主;'' = 问到了但宿主没给地址(老版本或还没起来)。 */
|
|
2930
2836
|
const [url, setUrl] = useState(null);
|
|
2931
2837
|
const [scope, setScope] = useState('');
|
|
2932
|
-
const [access, setAccess] = useState(null);
|
|
2933
2838
|
/** `null` = 这一次没出错;否则 `{ kind: 'load' | 'open', message }`。 */
|
|
2934
2839
|
const [failure, setFailure] = useState(null);
|
|
2935
2840
|
/** 侧边栏两颗图标的选择,与那两颗图标共享同一份状态。 */
|
|
@@ -2947,7 +2852,6 @@ window.__ModuleLoader__.load({
|
|
|
2947
2852
|
adoptFooterIcons(view);
|
|
2948
2853
|
setUrl(typeof view.panelUrl === 'string' ? view.panelUrl : '');
|
|
2949
2854
|
setScope(typeof view.panelScope === 'string' ? view.panelScope : '');
|
|
2950
|
-
setAccess(view.webAccess && typeof view.webAccess.enabled === 'boolean' ? view.webAccess : null);
|
|
2951
2855
|
setFailure(null);
|
|
2952
2856
|
} catch (error) {
|
|
2953
2857
|
if (!alive) return;
|
|
@@ -2959,37 +2863,24 @@ window.__ModuleLoader__.load({
|
|
|
2959
2863
|
}, []);
|
|
2960
2864
|
|
|
2961
2865
|
/**
|
|
2962
|
-
*
|
|
2963
|
-
* 地址还没读到时也照样
|
|
2964
|
-
* 走这条路——它会自己开窗再读一次(见 `openConfigurationPage`),不是干等。
|
|
2965
|
-
*
|
|
2866
|
+
* 拨到面板。地址还没读到时补读一次再开(见 `openConfigurationPage`),不是干等。
|
|
2966
2867
|
* 新窗口必须在**点击这一帧**开出来,等到接口回来再开会被弹窗拦截器吃掉。
|
|
2967
2868
|
*/
|
|
2968
2869
|
function openPanel(event) {
|
|
2969
|
-
|
|
2970
|
-
const needsWindow = !knowsUrl || (scope !== 'loopback' && scope !== 'private' && !(access && access.enabled));
|
|
2971
|
-
if (!needsWindow) return; // 普通链接,交给浏览器自己开
|
|
2870
|
+
if (typeof url === 'string' && url !== '') return; // 普通链接,交给浏览器自己开
|
|
2972
2871
|
if (event && typeof event.preventDefault === 'function') event.preventDefault();
|
|
2973
|
-
if (knowsUrl
|
|
2974
|
-
&& scope === 'public'
|
|
2975
|
-
&& typeof window !== 'undefined'
|
|
2976
|
-
&& typeof window.confirm === 'function'
|
|
2977
|
-
&& !window.confirm(t('footerPublicConfirm'))) return;
|
|
2978
2872
|
const target = isWebPage(window) && typeof window.open === 'function'
|
|
2979
2873
|
? window.open('', '_blank')
|
|
2980
2874
|
: null;
|
|
2981
2875
|
void (async () => {
|
|
2982
2876
|
const outcome = await openConfigurationPage({
|
|
2983
|
-
view: { panelUrl:
|
|
2877
|
+
view: { panelUrl: '', panelScope: scope },
|
|
2984
2878
|
loadStatus: failure && failure.kind === 'load' ? failure.status || 0 : 0,
|
|
2985
2879
|
t,
|
|
2986
2880
|
target,
|
|
2987
|
-
confirmed: knowsUrl,
|
|
2988
2881
|
});
|
|
2989
2882
|
if (outcome.ok) {
|
|
2990
|
-
|
|
2991
|
-
if (outcome.webAccess) setAccess(outcome.webAccess);
|
|
2992
|
-
if (!outcome.cancelled) setFailure(null);
|
|
2883
|
+
setFailure(null);
|
|
2993
2884
|
return;
|
|
2994
2885
|
}
|
|
2995
2886
|
if (target && typeof target.close === 'function') target.close();
|