dsh-mobile-plugin 0.5.66 → 0.5.68
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 +20 -1
- package/lib/client.js +127 -16
- package/lib/frpc/provision.cjs +76 -12
- package/lib/impl.js +20 -0
- package/lib/mobile/file-read.js +65 -36
- package/lib/mobile/mux.js +231 -0
- package/lib/mobile/permissions.js +4 -0
- package/lib/mobile/session-models.js +6 -1
- package/lib/panel/index.html +12 -13
- package/lib/relay/status.js +5 -1
- package/lib/routes/control-plane.js +11 -10
- package/lib/routes/mobile-api.js +7 -1
- package/lib/shell/updater.js +4 -1
- package/package.json +1 -1
|
@@ -13,6 +13,23 @@
|
|
|
13
13
|
> 把扩展目录放进插件包,发到 npm 或你自己的仓库 → 用户自己装这个插件 → 手机从他那台电脑
|
|
14
14
|
> 把包拉下来。我们不审、不登记,也没有提 PR 这一步。
|
|
15
15
|
|
|
16
|
+
## 这份文档怎么维护(维护者看,作者可跳过)
|
|
17
|
+
|
|
18
|
+
这一节写给改这份文档的人。几条规矩定死,免得文档越写越大之后自己乱掉:
|
|
19
|
+
|
|
20
|
+
- **这里唯一是来源**。改这份,别改插件包里那份 `docs/extension-authoring.md` 与
|
|
21
|
+
`docs/extension-sample/` —— 那是发布前从这儿同步过去的副本,手改会被下次同步盖掉。
|
|
22
|
+
改完到 `dsh-mobile-plugin/` 跑 `node scripts/sync-author-docs.mjs` 把副本跟上;发版预检
|
|
23
|
+
会比对两边,对不上发不了。
|
|
24
|
+
- **节号只增不改、不重排**。新内容往后追加新号,已经写出去的节号钉死不动 —— 正文里几十处
|
|
25
|
+
写死「见第 X 节」,重排一次引用全断。引用时顺带说清讲的是什么,别只甩一个节号。2.05 /
|
|
26
|
+
2.06 排在 2.02 前面、3.5 / 3.6 与 3.1 不同层,是历次追加留下的,别回头 renumber。
|
|
27
|
+
- **新内容按主题归位**。能力、协议、行为的规则写进对应主题那一节;真机上撞过的坑写清现象、
|
|
28
|
+
原因、判据,归到对应主题或「9.6 这些现在做不到,别按它设计」附近。App 内部实现细节不进
|
|
29
|
+
这份文档。
|
|
30
|
+
- **反馈确认解决就补,不必再吩咐**。用户反馈、GitHub issue、自己写扩展踩到又解决的问题,
|
|
31
|
+
只要确认解决无误、属于作者会撞上的约束或坑,就照上面归位补进来,不用等谁再说一遍。
|
|
32
|
+
|
|
16
33
|
## 0. 先给「帮你写的那个 AI」看这一段
|
|
17
34
|
|
|
18
35
|
**先把说明书和样例拿到手**:它们随 `dsh-mobile-plugin` 这个 npm 包发布 —— 装上那个插件,你
|
|
@@ -218,7 +235,9 @@ libs/… 你自己的库、样式、字体,相对路径引用
|
|
|
218
235
|
|
|
219
236
|
**导航是自动认的,不需要登记任何东西。** 声明了 `pageOrigin` 之后,App 会把「指向你这个
|
|
220
237
|
本源、以及它下面任何站内路径」的跳转都留在页面里(`/canvas/abc`、`?x=1`、`#hash` 都算),
|
|
221
|
-
|
|
238
|
+
**只有真的往外走的外链才交给 App 的内置浏览器打开**(官网、GitHub 这类照常能点开)。
|
|
239
|
+
页面里直接写 `<a href="https://…">` 就行,不用加任何声明、也不用调接口 —— 外链会在内置
|
|
240
|
+
浏览器里显示,既不跳去系统浏览器,也不会把扩展页本身带走。
|
|
222
241
|
|
|
223
242
|
这条判据是按「这个地址是不是你自己的」算的,不认识具体哪个扩展 —— 所以你不用申请、不用
|
|
224
243
|
等我们加白名单,声明了就自动生效。反过来说,**别指望它当成外链跳板**:到了别的域名就是
|
package/lib/client.js
CHANGED
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
* 页面里切过去、不重新加载。方向是单向的(桌面 → 宿主 → 手机),手机上的折叠只存在 App
|
|
11
11
|
* 本地,不写回。
|
|
12
12
|
*
|
|
13
|
+
* 设置卡上另有两颗侧边栏图标(手机 / 电脑)的显示开关:默认全开、至少留一颗,选择写进
|
|
14
|
+
* 插件配置;同一页里两颗图标当场收起或回来,不必等下一次状态轮询。
|
|
15
|
+
*
|
|
13
16
|
* 本文件不经任何构建(package.json 直接收录 lib 下的 .js),所以不能写 JSX,统一用
|
|
14
17
|
* `React.createElement` 的别名 `h`;客户端插件按约定写成惰性工厂,定时器与页签在物化时才起。
|
|
15
18
|
*/
|
|
@@ -90,6 +93,10 @@ window.__ModuleLoader__.load({
|
|
|
90
93
|
.dshm_btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}
|
|
91
94
|
.dshm_btn:disabled{cursor:default;opacity:.45}
|
|
92
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)}
|
|
93
100
|
`;
|
|
94
101
|
if (typeof document !== 'undefined' && document.querySelector(`style[data-plugin-css="${STYLE_ID}"]`) === null) {
|
|
95
102
|
const tag = document.createElement('style');
|
|
@@ -450,6 +457,14 @@ window.__ModuleLoader__.load({
|
|
|
450
457
|
cardPanel: '配置页面',
|
|
451
458
|
openPanel: '打开配置页面',
|
|
452
459
|
openHint: '配对、网络配置与插件更新都在这个页面里。',
|
|
460
|
+
iconsTitle: '侧边栏图标',
|
|
461
|
+
iconsHint: '选择桌面侧边栏底部显示哪颗入口;至少保留一颗。',
|
|
462
|
+
iconPhone: '手机图标',
|
|
463
|
+
iconComputer: '电脑图标',
|
|
464
|
+
iconShown: '显示',
|
|
465
|
+
iconHidden: '隐藏',
|
|
466
|
+
iconKeepOne: '至少要保留一颗图标',
|
|
467
|
+
iconSaveFailed: '保存图标设置失败',
|
|
453
468
|
panelPending: '正在读取页面地址…',
|
|
454
469
|
panelMissing: '宿主还没给出页面地址,稍后再打开这一页试试。',
|
|
455
470
|
loadFailed: '读取宿主状态失败',
|
|
@@ -527,6 +542,14 @@ window.__ModuleLoader__.load({
|
|
|
527
542
|
cardPanel: 'Configuration page',
|
|
528
543
|
openPanel: 'Open the configuration page',
|
|
529
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',
|
|
530
553
|
panelPending: 'Reading the page address…',
|
|
531
554
|
panelMissing: 'The host has not reported a page address yet — reopen this item in a moment.',
|
|
532
555
|
loadFailed: 'Failed to read host status',
|
|
@@ -596,6 +619,33 @@ window.__ModuleLoader__.load({
|
|
|
596
619
|
},
|
|
597
620
|
};
|
|
598
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
|
+
|
|
599
649
|
/* ── 诊断弹窗 ──────────────────────────────────────────────────────────
|
|
600
650
|
* 点这颗图标打不开配置页、或者开窗口失败时,不能只让用户「点了没反应」。
|
|
601
651
|
*
|
|
@@ -745,8 +795,8 @@ window.__ModuleLoader__.load({
|
|
|
745
795
|
if (spec.summary) card.appendChild(make('p', 'dshm_dialogLead', spec.summary));
|
|
746
796
|
// 自定义内容区(入口那两块就挂在这儿):节点由调用方造,这里只负责挂上。
|
|
747
797
|
if (spec.body) card.appendChild(spec.body);
|
|
748
|
-
//
|
|
749
|
-
// `src` 已经由调用方按同源地址算好(壳里是 `dsh-app://app/api/relay/panel/
|
|
798
|
+
// 内嵌一整页(控制台 / 远程电脑那一窗):外壳里 `window.open` 不可靠,所以把页面嵌进来。
|
|
799
|
+
// `src` 已经由调用方按同源地址算好(壳里是 `dsh-app://app/api/relay/panel/console`,
|
|
750
800
|
// 网页里是同源 http),远程浏览器的那两小时窗口也在拨号那一步开好了。
|
|
751
801
|
//
|
|
752
802
|
// load 只说明文档结束导航;空页、错误响应、脚本启动失败都不能算控制台就绪。
|
|
@@ -1365,6 +1415,9 @@ window.__ModuleLoader__.load({
|
|
|
1365
1415
|
const [hint, setHint] = useState('');
|
|
1366
1416
|
/** 展开态是否已经插进设置那一行。插不上就自己占一行。 */
|
|
1367
1417
|
const [anchored, setAnchored] = useState(true);
|
|
1418
|
+
/** 用户在设置卡上有没有把这颗收起来;收起来时连插入的 DOM 一起撤掉。 */
|
|
1419
|
+
const [visible, setVisible] = useState(footerIcons.phone);
|
|
1420
|
+
useEffect(() => watchFooterIcons((next) => setVisible(next.phone)), []);
|
|
1368
1421
|
const nodeRef = useRef(null);
|
|
1369
1422
|
const dialogRef = useRef(null);
|
|
1370
1423
|
useEffect(() => () => {
|
|
@@ -1406,6 +1459,7 @@ window.__ModuleLoader__.load({
|
|
|
1406
1459
|
try {
|
|
1407
1460
|
const next = await call('/status');
|
|
1408
1461
|
const view = next && typeof next === 'object' ? next : {};
|
|
1462
|
+
adoptFooterIcons(view);
|
|
1409
1463
|
const summary = readStatusView(view);
|
|
1410
1464
|
setUrl(summary.panelUrl);
|
|
1411
1465
|
setWebAccess(summary.webAccess);
|
|
@@ -1494,7 +1548,7 @@ window.__ModuleLoader__.load({
|
|
|
1494
1548
|
* 跳过去,而是「它现在到底哪一环断了」——启动、装载、隧道、旁挂进程、自检全都在那一屏
|
|
1495
1549
|
* 里,比一个打不开的页面有用。跳转本身没取消,挪进了那一屏里的一颗按钮。
|
|
1496
1550
|
*
|
|
1497
|
-
* 那一屏的内容是网页版的 `/api/relay/panel/
|
|
1551
|
+
* 那一屏的内容是网页版的 `/api/relay/panel/console`(React 写的,改完刷新就见效),
|
|
1498
1552
|
* 这里只把同源地址算出来嵌进去。**必须先保证控制面认这个浏览器**,否则嵌进来的是一屏
|
|
1499
1553
|
* 423 JSON:所以公网入口先按 `panelScope` 开好两小时窗口,本机和局域网直接进入。
|
|
1500
1554
|
*
|
|
@@ -1584,9 +1638,8 @@ window.__ModuleLoader__.load({
|
|
|
1584
1638
|
};
|
|
1585
1639
|
|
|
1586
1640
|
/**
|
|
1587
|
-
*
|
|
1588
|
-
*
|
|
1589
|
-
* 与「关闭」两颗图标,剩下的操作都在页面里,不占嵌页的地方。
|
|
1641
|
+
* 点一下手机图标,**直接就是这一屏控制台**:没有中间入口。调试页 2026-11-17 删了,
|
|
1642
|
+
* 窗口操作那两颗按钮也搬进了页面顶栏;这一窗的外壳只剩一圈薄边,不占嵌页的地方。
|
|
1590
1643
|
*/
|
|
1591
1644
|
dialog.open({
|
|
1592
1645
|
title: t('consoleTitle'),
|
|
@@ -1824,8 +1877,9 @@ window.__ModuleLoader__.load({
|
|
|
1824
1877
|
useEffect(() => {
|
|
1825
1878
|
if (typeof document === 'undefined') return undefined;
|
|
1826
1879
|
const doc = document;
|
|
1827
|
-
//
|
|
1828
|
-
|
|
1880
|
+
// 窄条那一行塞不下第二颗:不插,自己占一行。用户在设置卡上收起来时同样不插,
|
|
1881
|
+
// 走下面的清理把已插的那颗摘掉;观察器也不能再把它捡回来。
|
|
1882
|
+
if (!wide || !visible) {
|
|
1829
1883
|
setAnchored(false);
|
|
1830
1884
|
return undefined;
|
|
1831
1885
|
}
|
|
@@ -1873,7 +1927,7 @@ window.__ModuleLoader__.load({
|
|
|
1873
1927
|
frame = 0;
|
|
1874
1928
|
try {
|
|
1875
1929
|
sync();
|
|
1876
|
-
setAnchored(ensureFooterIcon(doc, node));
|
|
1930
|
+
setAnchored(visible ? ensureFooterIcon(doc, node) : false);
|
|
1877
1931
|
} catch {
|
|
1878
1932
|
setAnchored(false);
|
|
1879
1933
|
}
|
|
@@ -1886,9 +1940,11 @@ window.__ModuleLoader__.load({
|
|
|
1886
1940
|
if (frame !== 0 && typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame);
|
|
1887
1941
|
if (typeof node.remove === 'function' && node.parentElement) node.remove();
|
|
1888
1942
|
};
|
|
1889
|
-
}, [wide, url, openLabel, loadMissingLabel, pendingLabel, problem, panelScope, webAccess, hint, fault]);
|
|
1943
|
+
}, [wide, visible, url, openLabel, loadMissingLabel, pendingLabel, problem, panelScope, webAccess, hint, fault]);
|
|
1890
1944
|
|
|
1891
1945
|
// 窄条,或者这一版外壳里认不出那一行:自己占一行,入口不能因为认不出位置就消失。
|
|
1946
|
+
// 收起来的那一颗例外:它这一页里根本不该再有入口。
|
|
1947
|
+
if (!visible) return null;
|
|
1892
1948
|
if (!wide || !anchored) {
|
|
1893
1949
|
const state = footerState();
|
|
1894
1950
|
return h('a', {
|
|
@@ -1943,6 +1999,8 @@ window.__ModuleLoader__.load({
|
|
|
1943
1999
|
const [panelScope, setPanelScope] = useState('');
|
|
1944
2000
|
const [problem, setProblem] = useState(null);
|
|
1945
2001
|
const [anchored, setAnchored] = useState(true);
|
|
2002
|
+
const [visible, setVisible] = useState(footerIcons.computer);
|
|
2003
|
+
useEffect(() => watchFooterIcons((next) => setVisible(next.computer)), []);
|
|
1946
2004
|
const nodeRef = useRef(null);
|
|
1947
2005
|
const dialogRef = useRef(null);
|
|
1948
2006
|
useEffect(() => () => {
|
|
@@ -1958,6 +2016,7 @@ window.__ModuleLoader__.load({
|
|
|
1958
2016
|
try {
|
|
1959
2017
|
const next = await call('/status');
|
|
1960
2018
|
const view = readStatusView(next);
|
|
2019
|
+
adoptFooterIcons(next);
|
|
1961
2020
|
setUrl(view.panelUrl);
|
|
1962
2021
|
setWebAccess(view.webAccess);
|
|
1963
2022
|
setPanelScope(view.panelScope);
|
|
@@ -2108,10 +2167,11 @@ window.__ModuleLoader__.load({
|
|
|
2108
2167
|
}, []);
|
|
2109
2168
|
|
|
2110
2169
|
// 展开态:纯 DOM 插进设置那一行,紧跟手机图标;认不出位置就退回自己一行。
|
|
2170
|
+
// 收起来时不插,也不让观察器把它捡回来(已插的那颗在 effect 清理里摘掉)。
|
|
2111
2171
|
useEffect(() => {
|
|
2112
2172
|
if (typeof document === 'undefined') return undefined;
|
|
2113
2173
|
const doc = document;
|
|
2114
|
-
if (!wide) {
|
|
2174
|
+
if (!wide || !visible) {
|
|
2115
2175
|
setAnchored(false);
|
|
2116
2176
|
return undefined;
|
|
2117
2177
|
}
|
|
@@ -2158,7 +2218,7 @@ window.__ModuleLoader__.load({
|
|
|
2158
2218
|
frame = 0;
|
|
2159
2219
|
try {
|
|
2160
2220
|
sync();
|
|
2161
|
-
setAnchored(ensureRemoteFooterIcon(doc, node));
|
|
2221
|
+
setAnchored(visible ? ensureRemoteFooterIcon(doc, node) : false);
|
|
2162
2222
|
} catch {
|
|
2163
2223
|
setAnchored(false);
|
|
2164
2224
|
}
|
|
@@ -2171,9 +2231,10 @@ window.__ModuleLoader__.load({
|
|
|
2171
2231
|
if (frame !== 0 && typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame);
|
|
2172
2232
|
if (typeof node.remove === 'function' && node.parentElement) node.remove();
|
|
2173
2233
|
};
|
|
2174
|
-
}, [wide, url, openLabel, problem, panelScope, webAccess]);
|
|
2234
|
+
}, [wide, visible, url, openLabel, problem, panelScope, webAccess]);
|
|
2175
2235
|
|
|
2176
2236
|
// 窄条,或认不出那一行:自己占一行,入口不能因为认不出位置就消失。
|
|
2237
|
+
if (!visible) return null;
|
|
2177
2238
|
if (!wide || !anchored) {
|
|
2178
2239
|
return h('a', {
|
|
2179
2240
|
className: 'dshm_footAction dshm_footActionRail',
|
|
@@ -2379,8 +2440,9 @@ window.__ModuleLoader__.load({
|
|
|
2379
2440
|
* 这一张是设置里的正规入口):介绍产品时说的入口就是「设置 → 移动端」,只留图标会让从
|
|
2380
2441
|
* 网页版进来的人不知道配置在哪。
|
|
2381
2442
|
*
|
|
2382
|
-
*
|
|
2383
|
-
*
|
|
2443
|
+
* 刻意只放轻量的设置:界面本体全在网页版里(A3-37),在这里再画一套等于长期维护第二套 UI,
|
|
2444
|
+
* 而两套迟早会打架。配置页卡只做两件事——说清配置在哪、把那一页开出来;开不出来就在卡上写
|
|
2445
|
+
* 原因。2026-11-17 用户要在这一页选侧边栏那两颗图标,才添了第二张小卡。
|
|
2384
2446
|
*/
|
|
2385
2447
|
function MobileSettingsSection({ t }) {
|
|
2386
2448
|
/** null = 还在问宿主;'' = 问到了但宿主没给地址(老版本或还没起来)。 */
|
|
@@ -2389,6 +2451,10 @@ window.__ModuleLoader__.load({
|
|
|
2389
2451
|
const [access, setAccess] = useState(null);
|
|
2390
2452
|
/** `null` = 这一次没出错;否则 `{ kind: 'load' | 'open', message }`。 */
|
|
2391
2453
|
const [failure, setFailure] = useState(null);
|
|
2454
|
+
/** 侧边栏两颗图标的选择,与那两颗图标共享同一份状态。 */
|
|
2455
|
+
const [icons, setIcons] = useState(footerIcons);
|
|
2456
|
+
const [iconError, setIconError] = useState('');
|
|
2457
|
+
useEffect(() => watchFooterIcons(setIcons), []);
|
|
2392
2458
|
|
|
2393
2459
|
useEffect(() => {
|
|
2394
2460
|
let alive = true;
|
|
@@ -2397,6 +2463,7 @@ window.__ModuleLoader__.load({
|
|
|
2397
2463
|
const next = await call('/status');
|
|
2398
2464
|
if (!alive) return;
|
|
2399
2465
|
const view = next && typeof next === 'object' ? next : {};
|
|
2466
|
+
adoptFooterIcons(view);
|
|
2400
2467
|
setUrl(typeof view.panelUrl === 'string' ? view.panelUrl : '');
|
|
2401
2468
|
setScope(typeof view.panelScope === 'string' ? view.panelScope : '');
|
|
2402
2469
|
setAccess(view.webAccess && typeof view.webAccess.enabled === 'boolean' ? view.webAccess : null);
|
|
@@ -2449,6 +2516,33 @@ window.__ModuleLoader__.load({
|
|
|
2449
2516
|
})();
|
|
2450
2517
|
}
|
|
2451
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
|
+
|
|
2452
2546
|
const hint = url === null ? t('panelPending') : url === '' ? t('panelMissing') : t('openHint');
|
|
2453
2547
|
return h('div', { className: 'dshm_root' },
|
|
2454
2548
|
h('h2', { className: 'dshm_heading' }, t('heading')),
|
|
@@ -2467,7 +2561,24 @@ window.__ModuleLoader__.load({
|
|
|
2467
2561
|
failure
|
|
2468
2562
|
? h('p', { className: 'dshm_error' },
|
|
2469
2563
|
`${failure.kind === 'load' ? t('loadFailed') : t('openFailed')}:${failure.message}`)
|
|
2470
|
-
: 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));
|
|
2471
2582
|
}
|
|
2472
2583
|
|
|
2473
2584
|
/* ── 聊天嵌入页:把网页定位到顶栏那条会话 ───────────────────────────────
|
package/lib/frpc/provision.cjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// 2026-11-18:下载加国内镜像回退(官方不通自动换源,仍按同一份 sha256 校验),失败文案挖出 cause 真话。
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* 在用户电脑上「弄到一份能用的 frpc」:先看用户自己有没有,再看有没有缓存,都没有就按平台
|
|
5
7
|
* 从官方 release 拉一份、校验、解包、落到缓存目录。
|
|
@@ -12,9 +14,12 @@
|
|
|
12
14
|
* ① 用户指定的路径(环境变量 `DSHM_FRPC_BIN`)或系统 PATH 里已有的 frpc —— 直接用,不下载;
|
|
13
15
|
* ② 以前下载过的缓存(按「版本 + 平台」存)—— 直接用;
|
|
14
16
|
* ③ 都没有 —— 按当前系统与架构从官方 release 下载对应包,sha256 校验通过后再解包落盘。
|
|
17
|
+
* 国内常连不上 GitHub,下载这一步会依次回退几条公开加速镜像;镜像只换传输路径,
|
|
18
|
+
* 仍是同一份资产、同一份钉死的 sha256,校验不符当场拒掉,不因为「换源」放松验证。
|
|
15
19
|
*
|
|
16
20
|
* 失败一律走返回值(`{ ok: false, reason, message }`),从不抛给调用方:这条只是可选能力,
|
|
17
|
-
* 弄不到就等于「这台机器没有 frpc
|
|
21
|
+
* 弄不到就等于「这台机器没有 frpc」,插件其它功能一点不受影响。全源都不通时把每条源的
|
|
22
|
+
* 底层原因(从 undici 的 `cause` 里挖出来的真话,而不是一句 `fetch failed`)一并列出来。
|
|
18
23
|
*
|
|
19
24
|
* 纯 Node 实现,不依赖系统 tar/unzip:下载的是官方 .tar.gz(Linux/macOS)或 .zip(Windows),
|
|
20
25
|
* 两种解包都在本文件里手写,只挑出里面那个 frpc 可执行文件,其余(frps、LICENSE…)不落盘。
|
|
@@ -29,9 +34,47 @@ const { dshHome } = require('../shared/paths.js');
|
|
|
29
34
|
/** 钉死的 frp 版本。换版本时改这一个常量,并把下面的文件名与 sha256 一起更新。 */
|
|
30
35
|
const FRP_VERSION = '0.72.0';
|
|
31
36
|
|
|
32
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* 官方 release 的下载根;国内常连不上,下面挂着几条公开加速镜像,按顺序回退。
|
|
39
|
+
* 只换「同一份字节的传输路径」,资产与 sha256 不变——镜像给错内容照样在校验那步被拒。
|
|
40
|
+
* 镜像是第三方服务,会失效也会变,所以做成一张可替换的表,且永远最后才动失败文案。
|
|
41
|
+
*/
|
|
33
42
|
const DEFAULT_BASE_URL = `https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}`;
|
|
34
43
|
|
|
44
|
+
const MIRROR_BASE_URLS = [
|
|
45
|
+
`https://gh-proxy.com/https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}`,
|
|
46
|
+
`https://ghfast.top/https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}`,
|
|
47
|
+
`https://ghproxy.net/https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}`,
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 这一轮下载要按顺序试的根地址。
|
|
52
|
+
*
|
|
53
|
+
* 优先级:`baseUrl`(部署方/测试显式钉死,只试这一条)> 官方 + 镜像。任何一环给出的
|
|
54
|
+
* 字节都要过同一份 sha256,镜像进不了「少校验」的捷径。
|
|
55
|
+
*/
|
|
56
|
+
function baseUrlsOf(options = {}) {
|
|
57
|
+
if (typeof options.baseUrl === 'string' && options.baseUrl) return [options.baseUrl];
|
|
58
|
+
return [DEFAULT_BASE_URL, ...MIRROR_BASE_URLS];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* undici 把真正的 syscall 错塞在 `cause` 里,表层只有一句没信息的 `fetch failed`。
|
|
63
|
+
* 沿 cause 链找第一句比 "fetch failed" 更具体的话(connect ETIMEDOUT / ENOTFOUND /
|
|
64
|
+
* ECONNREFUSED / 证书问题…);找不到就退回表层那句,不凭空编。
|
|
65
|
+
*/
|
|
66
|
+
function fetchErrorMessage(error) {
|
|
67
|
+
let cursor = error;
|
|
68
|
+
let generic = '';
|
|
69
|
+
for (let depth = 0; depth < 4 && cursor; depth += 1) {
|
|
70
|
+
const message = typeof cursor.message === 'string' ? cursor.message.trim() : '';
|
|
71
|
+
if (message && message.toLowerCase() !== 'fetch failed') return message;
|
|
72
|
+
if (message) generic = message;
|
|
73
|
+
cursor = cursor.cause;
|
|
74
|
+
}
|
|
75
|
+
return generic || (error && error.message ? error.message : String(error));
|
|
76
|
+
}
|
|
77
|
+
|
|
35
78
|
/**
|
|
36
79
|
* 支持的平台 → 资产描述。
|
|
37
80
|
*
|
|
@@ -221,7 +264,7 @@ async function downloadTo({ url, asset, dir, fetchImpl, timeoutMs = DOWNLOAD_TIM
|
|
|
221
264
|
try {
|
|
222
265
|
response = await doFetch(url, controller ? { signal: controller.signal } : {});
|
|
223
266
|
} catch (error) {
|
|
224
|
-
throw codedError('download-failed', `下载 frpc 失败:${error
|
|
267
|
+
throw codedError('download-failed', `下载 frpc 失败:${fetchErrorMessage(error)}`);
|
|
225
268
|
} finally {
|
|
226
269
|
if (timer) clearTimeout(timer);
|
|
227
270
|
}
|
|
@@ -334,16 +377,34 @@ async function ensureFrpc(options = {}) {
|
|
|
334
377
|
}
|
|
335
378
|
const root = options.cacheRoot || cacheRoot(options);
|
|
336
379
|
const staging = path.join(root, `.staging-${process.pid}-${crypto.randomBytes(6).toString('hex')}`);
|
|
337
|
-
const
|
|
338
|
-
const
|
|
380
|
+
const bases = baseUrlsOf(options);
|
|
381
|
+
const attempts = [];
|
|
382
|
+
// 整轮回退共用一份时间预算(与过去单源超时相同):否则 GitHub 卡住不吃不吐时,
|
|
383
|
+
// 逐源各等满 120 秒会把面板晾八分钟。排在后面的镜像只拿得到「剩下的时间」。
|
|
384
|
+
const budgetMs = Number(options.timeoutMs) > 0 ? Number(options.timeoutMs) : DOWNLOAD_TIMEOUT_MS;
|
|
385
|
+
const deadline = Date.now() + budgetMs;
|
|
339
386
|
try {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
387
|
+
for (const base of bases) {
|
|
388
|
+
const remaining = deadline - Date.now();
|
|
389
|
+
if (remaining <= 0) break;
|
|
390
|
+
const url = `${String(base).replace(/\/+$/, '')}/${asset.file}`;
|
|
391
|
+
try {
|
|
392
|
+
await downloadTo({ url, asset, dir: staging, fetchImpl: options.fetchImpl, timeoutMs: remaining });
|
|
393
|
+
// 先剔掉可能残留的旧目录,再把暂存目录原子换上。
|
|
394
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
395
|
+
fs.mkdirSync(path.dirname(dir), { recursive: true });
|
|
396
|
+
moveDir(staging, dir);
|
|
397
|
+
pruneOldVersions(root, version);
|
|
398
|
+
return { ok: true, path: binaryPath, source: 'downloaded', version, platform };
|
|
399
|
+
} catch (error) {
|
|
400
|
+
const reason = error && error.message ? error.message : String(error);
|
|
401
|
+
attempts.push(reason.replace(/^下载 frpc 失败:/, ''));
|
|
402
|
+
// 校验不符不是「网络不通」:字节到了却对不上钉死的 sha256,换镜像也是同一份坏包,
|
|
403
|
+
// 继续试只会让人以为在尽力。当场拒掉,和过去单源的行为一致。
|
|
404
|
+
if (error && error.code === 'checksum') throw error;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return fail('download-failed', `下载 frpc 失败:${attempts.length} 个源都不通(${attempts.join(';')})`);
|
|
347
408
|
} catch (error) {
|
|
348
409
|
fs.rmSync(staging, { recursive: true, force: true });
|
|
349
410
|
return fail(error && error.code ? error.code : 'download-failed', error && error.message ? error.message : String(error));
|
|
@@ -372,6 +433,9 @@ module.exports = {
|
|
|
372
433
|
FRP_VERSION,
|
|
373
434
|
ASSETS,
|
|
374
435
|
DEFAULT_BASE_URL,
|
|
436
|
+
MIRROR_BASE_URLS,
|
|
437
|
+
baseUrlsOf,
|
|
438
|
+
fetchErrorMessage,
|
|
375
439
|
platformId,
|
|
376
440
|
cacheRoot,
|
|
377
441
|
cacheDirOf,
|
package/lib/impl.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* (`test/assembly-layer.test.cjs` 钉着)。
|
|
7
7
|
*/
|
|
8
8
|
// 远程电脑入口独立装配,手机端路由与权限保持原有边界。
|
|
9
|
+
// 桌面侧边栏两颗图标的显示偏好也落在这份 relay.json 里(默认全开)。
|
|
9
10
|
import { createRequire } from 'node:module'
|
|
10
11
|
import os from 'node:os'
|
|
11
12
|
import path from 'node:path'
|
|
@@ -42,6 +43,7 @@ const { mountP2P } = require('./p2p/wiring.cjs') // 点对点隧道:助手会
|
|
|
42
43
|
// FRP 直连:用面板导入的配置拉起本地 frpc(见 lib/frpc/runner.cjs)。
|
|
43
44
|
const { createFrpcRunner } = require('./frpc/runner.cjs')
|
|
44
45
|
const { createPreviewService } = require('./relay/preview.js')
|
|
46
|
+
const { createMuxService } = require('./mobile/mux.js')
|
|
45
47
|
const { mountRemoteComputers } = require('./remote/runtime.cjs')
|
|
46
48
|
// 手机打开「电脑上的网页版」时用的那枚一次性登录令牌(见 mobile/host-web.js)。
|
|
47
49
|
const hostWeb = require('./mobile/host-web.js')
|
|
@@ -121,6 +123,10 @@ export const RemoteControlSettingsSchema = z.object({
|
|
|
121
123
|
// 新配对设备的权限档位(只读 / 可答审批 / 全权)。配对时在电脑侧选定,展开成 permissions
|
|
122
124
|
// 写进凭据记录(见 lib/mobile/permissions.js)。缺省 full = 与今天单 token 全给等价。
|
|
123
125
|
pairingTier: z.union(permissions.TIER_NAMES.map(t => z.const(t))).default(permissions.DEFAULT_TIER), approvalAutoReview: z.boolean().default(false), // 审批自动审阅档(默认关,见 mobile/auto-review.js)
|
|
126
|
+
// 桌面设置页那两颗侧边栏图标(手机 / 电脑)的可见性。默认全开;老 relay.json 没这两格时
|
|
127
|
+
// 由 configOf 收成 true,界面不会在升级后突然少一颗。只给桌面控制面写,手机端配置口不收。
|
|
128
|
+
desktopPhoneIcon: z.boolean().default(true),
|
|
129
|
+
desktopComputerIcon: z.boolean().default(true),
|
|
124
130
|
// 中转注册密钥(对偶于中转的 TUNNEL_REGISTER_SECRET)。桌面版拿不到 shell
|
|
125
131
|
// 环境变量,所以它和其他配置一样存在 relay.json(0600),由 /api/relay/config
|
|
126
132
|
// 在回环上写入;status / pairing / 二维码都不回显它。
|
|
@@ -155,6 +161,9 @@ function configOf(state) {
|
|
|
155
161
|
pairingPolicy: pairingApproval.normalize(state.pairingPolicy),
|
|
156
162
|
pairingTier: permissions.isKnownTier(state.pairingTier) ? state.pairingTier : permissions.DEFAULT_TIER, // 未知值收敛回 full
|
|
157
163
|
approvalAutoReview: state.approvalAutoReview === true, // 非 true 一律当关
|
|
164
|
+
// 没写过的老配置按显示处理:这两颗是入口,不因为升级就凭空消失。
|
|
165
|
+
desktopPhoneIcon: state.desktopPhoneIcon !== false,
|
|
166
|
+
desktopComputerIcon: state.desktopComputerIcon !== false,
|
|
158
167
|
// 密钥只往 sidecar 和状态文件走:status() / pairingPayload() 都单独取字段,
|
|
159
168
|
// 不会把它回显给手机、二维码或日志。
|
|
160
169
|
registerSecret: typeof state.registerSecret === 'string' ? state.registerSecret : '',
|
|
@@ -544,6 +553,16 @@ function apply(ctx) {
|
|
|
544
553
|
})
|
|
545
554
|
ctx.effect(() => () => preview.close(), `${name}: preview pipes`)
|
|
546
555
|
|
|
556
|
+
// 对话页长连接(mux):一条手机 WS 上按 id 多路复用,逐条转成本地回环请求打到移动 API。
|
|
557
|
+
// 鉴权口径与预览升级路由同一套(设备凭据有效即可);逐路由权限仍由回环 HTTP 的 guarded 判,
|
|
558
|
+
// mux 只是搬运工,不另立权限面。帧契约见 `docs/mux-long-connection-design.md` §11。
|
|
559
|
+
const muxPermission = permissions.createUpgradePermission({ credentials, instanceId: state.instanceId, presentedCredential })
|
|
560
|
+
const mux = createMuxService({
|
|
561
|
+
upstream: { host: '127.0.0.1', port: ctx.webServer.port },
|
|
562
|
+
authorize: (req) => { try { return Boolean(muxPermission.recordOf(req)) } catch { return false } },
|
|
563
|
+
onLog: (message) => ctx.logger?.info?.(`${name}: %s`, message),
|
|
564
|
+
})
|
|
565
|
+
|
|
547
566
|
const remoteComputers = mount('远程电脑', () => mountRemoteComputers({ ctx, state, credentials, registerRoute, lanPortInUse: advertisedLanPort, tailcat, p2p, log: warn }))
|
|
548
567
|
|
|
549
568
|
// 移动端路由表在 lib/routes/mobile-api.js:那里是一张可以对着 App 侧 apiPaths.ts
|
|
@@ -559,6 +578,7 @@ function apply(ctx) {
|
|
|
559
578
|
// 一样必须包在 ctx.effect 里,否则插件重载时重复注册会直接抛错。
|
|
560
579
|
registerUpgradeRoute: (route) => mountRoute(route, true),
|
|
561
580
|
preview,
|
|
581
|
+
mux,
|
|
562
582
|
// 网页版登录令牌那条:handler 在这里造好、按依赖交给路由表,理由与 preview 一样——
|
|
563
583
|
// 它要读的是本进程的 `ctx.webServer` 与 `ctx.get('connection')`。
|
|
564
584
|
hostWeb: hostWeb.handleHostWeb,
|