dsh-plugin-mesh 0.5.4 → 0.5.6

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/client/client.js CHANGED
@@ -29,6 +29,10 @@ window.__ModuleLoader__.load({
29
29
 
30
30
  const PANEL_ID = "mesh";
31
31
  const API = "/mesh/api";
32
+ // 对端 DSH Web 的监听端口:dsh-web-app 的部署默认值就是 3080。对端用
33
+ // `--port` 改过的话,在本机 localStorage 写 mesh.webPort 覆盖。
34
+ const DSH_WEB_PORT = 3080;
35
+ const WEB_PORT_KEY = "mesh.webPort";
32
36
  const inject = ["slots"];
33
37
  const TS_KEYS_URL = "https://console.tailscale.com/admin/settings/keys";
34
38
  const TRANSFER_KEY = "mesh.transfers.v1";
@@ -185,6 +189,123 @@ window.__ModuleLoader__.load({
185
189
  return ep ? shortAddress(ep.host, ep.port) : "地址未知";
186
190
  }
187
191
 
192
+ /** 对端的局域网主机名/IP(不带 mesh 端口):优先 peer.host,其次第一个 endpoint。 */
193
+ function peerHost(peer) {
194
+ if (!peer) return "";
195
+ if (peer.host) return String(peer.host);
196
+ const eps = Array.isArray(peer.endpoints) ? peer.endpoints : [];
197
+ const ep = eps.find((x) => x && x.host);
198
+ return ep ? String(ep.host) : "";
199
+ }
200
+
201
+ /** 对端 DSH Web 的地址;没有地址时返回空串(不编一个出来)。 */
202
+ function dshWebUrl(peer) {
203
+ const host = peerHost(peer);
204
+ if (!host) return "";
205
+ let port = DSH_WEB_PORT;
206
+ try {
207
+ const custom = Number(localStorage.getItem(WEB_PORT_KEY));
208
+ if (Number.isFinite(custom) && custom > 0 && custom < 65536) port = Math.floor(custom);
209
+ } catch {
210
+ /* 存储不可用就用默认端口 */
211
+ }
212
+ return `http://${host}:${port}/`;
213
+ }
214
+
215
+ /**
216
+ * 要一条能直接打开的地址。
217
+ *
218
+ * 优先问本机宿主(/mesh/api/web-url):它去对端的配对通道里取一条带启动
219
+ * token 的地址,端口和 bind 都是对端自报的真值。对端是老版本插件、或者
220
+ * 取不到时,退回按约定拼出来的 http://<host>:3080/——那种情况浏览器会
221
+ * 停在 401 页,提示用户去对端取一次 token 地址。
222
+ * @returns {{ url: string, source: string, lanReachable?: boolean, reason?: string }}
223
+ */
224
+ async function resolveWebUrl(peer) {
225
+ const fallback = dshWebUrl(peer);
226
+ try {
227
+ const r = await api("/web-url", { peer: (peer && (peer.machine || peer.id)) || "" });
228
+ if (r && r.ok === true && typeof r.url === "string" && r.url)
229
+ return { url: r.url, source: "host", lanReachable: r.lanReachable === true };
230
+ return { url: fallback, source: "computed", reason: (r && r.error) || "" };
231
+ } catch (error) {
232
+ return { url: fallback, source: "computed", reason: String((error && error.message) || error) };
233
+ }
234
+ }
235
+
236
+ /**
237
+ * 壳里的原生浏览器是否可用(只读探测)。
238
+ *
239
+ * 这台 Android 壳会明确报 browserWebViewAvailable=false(工位 WebView 未就绪),
240
+ * 此时开 browser 页签只会落到一个"浏览器不可用"的空页面 —— 那比直接退回
241
+ * 外部浏览器更糟。所以先问一句:**壳明确说不可用才降级**,问不出来照常试。
242
+ */
243
+ function nativeBrowserUsable(sessionId) {
244
+ try {
245
+ const bridge = window.androidBridge;
246
+ if (!bridge || typeof bridge.browserHostCommand !== "function") return false;
247
+ if (!sessionId) return true; // 没有会话就无从判断,按可用处理
248
+ const raw = bridge.browserHostCommand(
249
+ JSON.stringify({ action: "status", session: sessionId, uiTabId: "mesh-probe" }),
250
+ );
251
+ if (typeof raw !== "string" || raw === "") return true; // 没答上来:不据此降级
252
+ const value = JSON.parse(raw);
253
+ return !(value && value.available === false);
254
+ } catch {
255
+ return true;
256
+ }
257
+ }
258
+
259
+ /**
260
+ * 在对端的 DSH Web 上开一个页面。
261
+ * 先走应用内浏览器(sidebar.right 的 browser 页签)——它就是壳里的那个
262
+ * WebView,不跳出 DSH;浏览器页不可用时退回外部浏览器。
263
+ * @returns {Promise<{ ok: boolean, how: string, url: string, lanReachable?: boolean, reason?: string }>}
264
+ */
265
+ async function openDshWebPage(peer) {
266
+ const resolved = await resolveWebUrl(peer);
267
+ const url = resolved.url;
268
+ if (!url) return { ok: false, how: "none", url: "", reason: resolved.reason || "这台设备没有上报地址" };
269
+ const extra = {
270
+ lanReachable: resolved.lanReachable,
271
+ viaHost: resolved.source === "host",
272
+ };
273
+ const sidebar = pluginCtx && pluginCtx.get ? pluginCtx.get("sidebarRight") : null;
274
+ const sessionId = currentSessionId();
275
+ const browserUsable = nativeBrowserUsable(sessionId);
276
+ // 先试强校验的 openTab(没有在屏会话会抛),再退化到按 session 的 openTabIn。
277
+ try {
278
+ if (browserUsable && sidebar && typeof sidebar.openTab === "function") {
279
+ sidebar.openTab("browser", { params: { url }, revealIfOpened: false });
280
+ return { ok: true, how: "browser", url, ...extra };
281
+ }
282
+ } catch {
283
+ /* 落到 openTabIn */
284
+ }
285
+ try {
286
+ if (browserUsable && sidebar && typeof sidebar.openTabIn === "function" && sessionId) {
287
+ sidebar.openTabIn(sessionId, "browser", { params: { url }, revealIfOpened: false });
288
+ return { ok: true, how: "browser", url, ...extra };
289
+ }
290
+ } catch {
291
+ /* 落到外部浏览器 */
292
+ }
293
+ const bridge = window.androidBridge;
294
+ if (bridge && typeof bridge.openExternalLink === "function") {
295
+ try {
296
+ bridge.openExternalLink(url);
297
+ return { ok: true, how: "external", url, ...extra, browserUnavailable: !browserUsable };
298
+ } catch {
299
+ return { ok: false, how: "none", url, reason: "外部浏览器也打不开" };
300
+ }
301
+ }
302
+ if (typeof window.open === "function") {
303
+ window.open(url, "_blank");
304
+ return { ok: true, how: "window", url, ...extra };
305
+ }
306
+ return { ok: false, how: "none", url, reason: "没有可用的打开方式" };
307
+ }
308
+
188
309
  function apiErr(r) {
189
310
  return (r && (r.error || r.message)) || "未知错误";
190
311
  }
@@ -650,6 +771,86 @@ window.__ModuleLoader__.load({
650
771
  background: var(--mesh-bg);
651
772
  }
652
773
  .mesh-brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
774
+ /* 主面板的"出口":宿主只给插件管理页注入返回键,Mesh 面板得自己带一个。 */
775
+ .mesh-panel-back {
776
+ flex: 0 0 auto;
777
+ display: inline-flex; align-items: center; gap: 4px;
778
+ height: 30px; padding: 0 10px 0 7px;
779
+ border: 1px solid var(--mesh-line); border-radius: 8px;
780
+ background: var(--mesh-surface); color: var(--mesh-muted);
781
+ font-size: 12px; line-height: 1; cursor: pointer;
782
+ transition: background var(--mesh-dur-fast) var(--mesh-ease-out),
783
+ color var(--mesh-dur-fast) var(--mesh-ease-out),
784
+ transform var(--mesh-dur-press) var(--mesh-ease-out);
785
+ }
786
+ .mesh-panel-back:hover { background: var(--mesh-surface-2); color: var(--mesh-fg); }
787
+ .mesh-panel-back:active { transform: scale(0.97); }
788
+ .mesh-panel-back:focus-visible { outline: 2px solid var(--mesh-accent); outline-offset: 2px; }
789
+ /* ── 对端 DSH Web 的应用内面板 ── */
790
+ .mesh-web-layer {
791
+ position: absolute; inset: 0; z-index: 60;
792
+ display: flex; flex-direction: column;
793
+ background: var(--mesh-bg);
794
+ }
795
+ .mesh-web-bar {
796
+ flex: 0 0 auto;
797
+ display: flex; align-items: center; gap: 8px;
798
+ padding: 6px 10px;
799
+ border-bottom: 1px solid var(--mesh-line);
800
+ background: var(--mesh-bg);
801
+ }
802
+ .mesh-web-title {
803
+ flex: 1 1 auto; min-width: 0;
804
+ font-size: 12.5px; font-weight: 600;
805
+ white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
806
+ }
807
+ .mesh-web-sub { color: var(--mesh-muted); font-weight: 400; }
808
+ .mesh-web-mark { flex: 0 0 auto; display: inline-flex; align-items: center; color: var(--mesh-fg); }
809
+ .mesh-web-frame { flex: 1 1 auto; width: 100%; min-height: 0; border: 0; background: var(--mesh-bg); }
810
+ .mesh-web-status {
811
+ flex: 0 0 auto;
812
+ display: flex; align-items: center; gap: 6px;
813
+ padding: 8px 12px;
814
+ font-size: 11.5px; line-height: 1.5;
815
+ color: var(--mesh-muted);
816
+ }
817
+ .mesh-web-status.is-warn { color: var(--mesh-warn); }
818
+
819
+ /* ── SSH 终端面板 ── */
820
+ .mesh-ssh-form { display: flex; flex-direction: column; gap: 10px; padding: 16px; max-width: 520px; }
821
+ .mesh-ssh-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--mesh-muted); }
822
+ .mesh-ssh-field input {
823
+ height: 36px; padding: 0 10px;
824
+ border: 1px solid var(--mesh-line-2); border-radius: 8px;
825
+ background: var(--mesh-surface); color: var(--mesh-fg); font-size: 14px;
826
+ }
827
+ .mesh-ssh-note { font-size: 11.5px; color: var(--mesh-muted); line-height: 1.5; }
828
+ .mesh-ssh-error { font-size: 12px; color: var(--mesh-err); }
829
+ .mesh-ssh-out {
830
+ flex: 1 1 auto; min-height: 0; margin: 0; padding: 10px 12px;
831
+ overflow: auto; white-space: pre-wrap; word-break: break-all;
832
+ background: #111418; color: #d7dde5;
833
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
834
+ font-size: 11.5px; line-height: 1.5;
835
+ }
836
+ .mesh-ssh-inputrow {
837
+ flex: 0 0 auto; display: flex; align-items: center; gap: 6px;
838
+ padding: 8px 10px; border-top: 1px solid var(--mesh-line);
839
+ background: var(--mesh-bg);
840
+ }
841
+ .mesh-ssh-inputrow input {
842
+ flex: 1 1 auto; min-width: 0; height: 36px; padding: 0 10px;
843
+ border: 1px solid var(--mesh-line-2); border-radius: 8px;
844
+ background: var(--mesh-surface); color: var(--mesh-fg);
845
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
846
+ }
847
+ .mesh-ssh-key, .mesh-ssh-send {
848
+ flex: 0 0 auto; height: 36px; padding: 0 10px;
849
+ border: 1px solid var(--mesh-line-2); border-radius: 8px;
850
+ background: var(--mesh-surface); color: var(--mesh-fg); font-size: 12px; cursor: pointer;
851
+ }
852
+ .mesh-ssh-send { background: var(--mesh-fg); color: var(--mesh-bg); border-color: transparent; }
853
+
653
854
  .mesh-logo {
654
855
  width: 26px; height: 26px; border-radius: 8px;
655
856
  display: grid; place-items: center;
@@ -1248,6 +1449,43 @@ window.__ModuleLoader__.load({
1248
1449
  .mesh-actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
1249
1450
  .mesh-divider { height: 1px; background: var(--mesh-line); margin: 14px 0; }
1250
1451
 
1452
+ /* ── 一键关闭(kill switch)── */
1453
+ .mesh-switch-list {
1454
+ display: flex; flex-direction: column; gap: 8px; margin-top: 12px;
1455
+ }
1456
+ .mesh-switch-row {
1457
+ display: flex; align-items: flex-start; gap: 12px;
1458
+ padding: 12px 14px;
1459
+ border: 1px solid var(--mesh-line); border-radius: 11px;
1460
+ background: var(--mesh-surface);
1461
+ transition: border-color var(--mesh-dur-fast) ease, background var(--mesh-dur-fast) ease;
1462
+ }
1463
+ /* 关闭中的一行用左侧警示条标出来:列表里三行很像,必须一眼看出哪条关了 */
1464
+ .mesh-switch-row.is-off { border-left: 2px solid var(--mesh-warn); }
1465
+ .mesh-switch-row-icon {
1466
+ flex: 0 0 auto; width: 26px; height: 26px; border-radius: 8px;
1467
+ display: grid; place-items: center;
1468
+ color: var(--mesh-accent);
1469
+ background: color-mix(in srgb, var(--mesh-accent) 8%, transparent);
1470
+ }
1471
+ .mesh-switch-row.is-off .mesh-switch-row-icon { color: var(--mesh-warn); background: color-mix(in srgb, var(--mesh-warn) 10%, transparent); }
1472
+ .mesh-switch-row-main { flex: 1; min-width: 0; }
1473
+ .mesh-switch-row-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
1474
+ .mesh-switch-row-title { font-size: 12.5px; font-weight: 600; }
1475
+ .mesh-switch-row-desc { margin-top: 3px; font-size: 11px; line-height: 1.6; color: var(--mesh-muted); }
1476
+ .mesh-switch-row-meta {
1477
+ margin-top: 5px;
1478
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
1479
+ font-size: 10px; color: var(--mesh-muted);
1480
+ word-break: break-word;
1481
+ }
1482
+ .mesh-switch-row-action { flex: 0 0 auto; align-self: center; }
1483
+ @media (max-width: 560px) {
1484
+ .mesh-switch-row { flex-wrap: wrap; }
1485
+ .mesh-switch-row-action { width: 100%; }
1486
+ .mesh-switch-row-action .mesh-btn { width: 100%; }
1487
+ }
1488
+
1251
1489
  /* ── 主页(卡片工作台) ── */
1252
1490
  .mesh-home { flex: 1; min-height: 0; overflow-y: auto; }
1253
1491
  .mesh-home-inner { max-width: 1040px; margin: 0 auto; padding: 26px 30px 60px; }
@@ -1303,10 +1541,47 @@ window.__ModuleLoader__.load({
1303
1541
  .mesh-hero-stat { display: flex; flex-direction: column; gap: 2px; min-width: 54px; }
1304
1542
  .mesh-hero-stat-value { font-size: 17px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
1305
1543
  .mesh-hero-stat-label { font-size: 10px; color: var(--mesh-muted); }
1544
+
1545
+ /* ── 概览卡上的一键关闭快捷条 ── */
1546
+ .mesh-home-switch {
1547
+ display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
1548
+ margin-top: 14px; padding-top: 11px;
1549
+ border-top: 1px dashed var(--mesh-line);
1550
+ }
1551
+ .mesh-home-switch-label {
1552
+ font-size: 10px; color: var(--mesh-muted); letter-spacing: .02em;
1553
+ margin-right: 2px;
1554
+ }
1555
+ .mesh-home-switch-pill {
1556
+ display: inline-flex; align-items: center; gap: 5px;
1557
+ padding: 3px 9px;
1558
+ border: 1px solid var(--mesh-line); border-radius: 999px;
1559
+ background: var(--mesh-surface-2); color: var(--mesh-fg);
1560
+ font-size: 11px; line-height: 1.5; cursor: pointer;
1561
+ transition: border-color var(--mesh-dur-fast) ease, background var(--mesh-dur-fast) ease,
1562
+ transform var(--mesh-dur-press) var(--mesh-ease-out);
1563
+ }
1564
+ .mesh-home-switch-pill:hover { border-color: var(--mesh-accent); }
1565
+ .mesh-home-switch-pill:active { transform: scale(0.97); }
1566
+ .mesh-home-switch-pill:disabled { cursor: progress; opacity: .7; }
1567
+ .mesh-home-switch-pill.is-off { border-color: var(--mesh-warn); }
1568
+ .mesh-home-switch-pill.is-off .mesh-home-switch-name { color: var(--mesh-warn); }
1569
+ .mesh-home-switch-pill.is-stalled { border-color: var(--mesh-warn); }
1570
+ .mesh-home-switch-name { font-weight: 600; }
1571
+ .mesh-home-switch-state { color: var(--mesh-muted); font-variant-numeric: tabular-nums; }
1572
+ .mesh-home.is-dense .mesh-home-switch { margin-top: 9px; padding-top: 8px; gap: 4px; }
1306
1573
  .mesh-mini-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-top: 1px solid var(--mesh-line); font-size: 11.5px; min-width: 0; }
1307
1574
  .mesh-mini-row:first-child { border-top: 0; padding-top: 0; }
1308
1575
  .mesh-mini-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
1309
1576
  .mesh-mini-meta { flex: 0 0 auto; font-size: 10.5px; color: var(--mesh-muted); }
1577
+ .mesh-mini-actions { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; }
1578
+ .mesh-mini-act {
1579
+ width: 28px; height: 28px; display: grid; place-items: center;
1580
+ border: 1px solid var(--mesh-line); border-radius: 7px;
1581
+ background: var(--mesh-surface); color: var(--mesh-muted); cursor: pointer;
1582
+ }
1583
+ .mesh-mini-act:active:not(:disabled) { transform: scale(0.95); }
1584
+ .mesh-mini-act:disabled { opacity: .4; cursor: not-allowed; }
1310
1585
  .mesh-home-hidden {
1311
1586
  margin-top: 18px; padding-top: 14px;
1312
1587
  border-top: 1px solid var(--mesh-line);
@@ -1701,6 +1976,7 @@ window.__ModuleLoader__.load({
1701
1976
  gap: 8px;
1702
1977
  }
1703
1978
  .mesh-brand { order: 1; }
1979
+ .mesh-panel-back { order: 0; height: 28px; padding: 0 8px 0 6px; font-size: 11.5px; }
1704
1980
  .mesh-topright { order: 2; }
1705
1981
  .mesh-tabs { order: 3; flex: 0 0 100%; width: 100%; }
1706
1982
  .mesh-tab { flex: 1 1 0; justify-content: center; padding: 7px 6px; }
@@ -1772,6 +2048,7 @@ window.__ModuleLoader__.load({
1772
2048
  .mesh-task-row {
1773
2049
  touch-action: manipulation;
1774
2050
  }
2051
+ .mesh-panel-back { touch-action: manipulation; }
1775
2052
  .mesh-tab { min-height: 44px; }
1776
2053
  .mesh-btn,
1777
2054
  .mesh-btn--sm,
@@ -2223,6 +2500,8 @@ window.__ModuleLoader__.load({
2223
2500
  ];
2224
2501
  case "chevron":
2225
2502
  return [h("path", { key: "a", d: "M9 6l6 6-6 6" })];
2503
+ case "back":
2504
+ return [h("path", { key: "a", d: "M15 6l-6 6 6 6" })];
2226
2505
  case "close":
2227
2506
  return [
2228
2507
  h("path", { key: "a", d: "M6 6l12 12" }),
@@ -2266,6 +2545,11 @@ window.__ModuleLoader__.load({
2266
2545
  h("path", { key: "b", d: "M8.5 16a5 5 0 0 1 7 0" }),
2267
2546
  h("path", { key: "c", d: "M12 19h.01" }),
2268
2547
  ];
2548
+ case "power":
2549
+ return [
2550
+ h("path", { key: "a", d: "M12 3v9" }),
2551
+ h("path", { key: "b", d: "M6.3 6.8a8 8 0 1 0 11.4 0" }),
2552
+ ];
2269
2553
  case "key":
2270
2554
  return [
2271
2555
  h("circle", { key: "a", cx: 8, cy: 15, r: 4 }),
@@ -2298,6 +2582,25 @@ window.__ModuleLoader__.load({
2298
2582
  }
2299
2583
  }
2300
2584
 
2585
+ const DSHPATH =
2586
+ "M48.8354 10.0479C48.3232 9.79199 48.1025 10.2798 47.8032 10.5278C47.7007 10.6079 47.6143 10.7119 47.5273 10.8076C46.7793 11.624 45.9048 12.1597 44.7622 12.0957C43.0923 12 41.666 12.5356 40.4058 13.8398C40.1377 12.2319 39.2476 11.272 37.8926 10.6558C37.1836 10.3359 36.4668 10.0156 35.9702 9.31982C35.6235 8.82373 35.5293 8.27197 35.356 7.72754C35.2456 7.3999 35.1353 7.06396 34.7651 7.00781C34.3633 6.94385 34.2056 7.2876 34.0479 7.57568C33.418 8.75195 33.1733 10.0479 33.1973 11.3599C33.2524 14.312 34.4736 16.6641 36.8999 18.3359C37.1758 18.5278 37.2466 18.7197 37.1597 19C36.9946 19.5757 36.7974 20.1357 36.624 20.7119C36.5137 21.0801 36.3486 21.1597 35.9624 21C34.6309 20.4321 33.481 19.5918 32.4644 18.5757C30.7393 16.8721 29.1792 14.9917 27.2334 13.52C26.7764 13.1758 26.3193 12.856 25.8467 12.5518C23.8618 10.584 26.1069 8.96777 26.627 8.77588C27.1704 8.57568 26.8159 7.8877 25.0591 7.896C23.3022 7.90381 21.6953 8.50391 19.647 9.30371C19.3477 9.42383 19.0322 9.51172 18.7095 9.58398C16.8501 9.22363 14.9199 9.14355 12.9033 9.37598C9.10596 9.80762 6.07275 11.6396 3.84326 14.7681C1.16455 18.5278 0.53418 22.7998 1.30664 27.2559C2.11768 31.9521 4.46582 35.8398 8.07373 38.8799C11.8159 42.0322 16.1255 43.5762 21.041 43.2803C24.0269 43.104 27.3516 42.6963 31.1016 39.4561C32.0469 39.936 33.0396 40.1279 34.686 40.272C35.9546 40.3921 37.1758 40.208 38.1211 40.0078C39.6021 39.688 39.4995 38.2881 38.9639 38.0322C34.623 35.9678 35.5762 36.8081 34.71 36.1279C36.9155 33.4639 40.2402 30.6958 41.54 21.728C41.6426 21.0161 41.5557 20.5679 41.54 19.9917C41.5322 19.6396 41.6108 19.5039 42.0049 19.4639C43.0923 19.3359 44.1479 19.0317 45.1167 18.4878C47.9292 16.9199 49.064 14.3438 49.3315 11.2559C49.3711 10.7837 49.3237 10.2959 48.8354 10.0479ZM24.3262 37.8398C20.1196 34.4639 18.0791 33.3521 17.2358 33.3999C16.4482 33.4482 16.5898 34.3682 16.7632 34.9678C16.9443 35.5601 17.1812 35.9683 17.5117 36.4878C17.7402 36.832 17.8979 37.3442 17.2832 37.728C15.9282 38.584 13.5728 37.4399 13.4624 37.3838C10.7207 35.7358 8.42822 33.5601 6.81348 30.584C5.25342 27.7197 4.34766 24.6479 4.19775 21.3677C4.1582 20.5757 4.38672 20.2959 5.15869 20.1519C6.17529 19.96 7.22314 19.9199 8.23926 20.0718C12.5327 20.7119 16.1885 22.6719 19.2529 25.7759C21.002 27.5439 22.3252 29.6558 23.6885 31.7202C25.1377 33.9121 26.6978 36 28.6831 37.7119C29.3843 38.312 29.9434 38.7681 30.479 39.104C28.8643 39.2881 26.1699 39.3281 24.3262 37.8398ZM26.3433 24.6001C26.3433 24.248 26.6191 23.9678 26.9658 23.9678C27.0444 23.9678 27.1152 23.9839 27.1782 24.0078C27.2651 24.04 27.3438 24.0879 27.4067 24.1602C27.5171 24.272 27.5801 24.4321 27.5801 24.6001C27.5801 24.9521 27.3042 25.2319 26.9575 25.2319C26.6108 25.2319 26.3433 24.9521 26.3433 24.6001ZM32.6064 27.8799C32.2046 28.0479 31.8027 28.1919 31.4165 28.208C30.8179 28.2397 30.1641 27.9922 29.8096 27.688C29.2583 27.2158 28.8643 26.9521 28.6987 26.1279C28.6279 25.7759 28.6675 25.2319 28.7305 24.9199C28.8721 24.248 28.7144 23.8159 28.2495 23.4238C27.8716 23.104 27.3911 23.0161 26.8633 23.0161C26.666 23.0161 26.4849 22.9277 26.3511 22.856C26.1304 22.7441 25.9492 22.4639 26.1226 22.1201C26.1777 22.0078 26.4458 21.7358 26.5088 21.688C27.2256 21.272 28.0527 21.4077 28.8169 21.7197C29.5259 22.0161 30.0615 22.5601 30.834 23.3281C31.6216 24.2559 31.7632 24.5117 32.2124 25.208C32.5669 25.752 32.8901 26.312 33.1104 26.9521C33.2446 27.3521 33.0713 27.6802 32.6064 27.8799Z";
2587
+
2588
+ /** DSH 官方图标(来自 dist/favicon.svg 的单条 path),颜色跟随 currentColor。 */
2589
+ function DshMark({ size }) {
2590
+ return h(
2591
+ "svg",
2592
+ {
2593
+ width: size || 16,
2594
+ height: size || 16,
2595
+ viewBox: "0 0 50 50",
2596
+ fill: "none",
2597
+ "aria-hidden": "true",
2598
+ focusable: "false",
2599
+ },
2600
+ h("path", { d: DSHPATH, fill: "currentColor" }),
2601
+ );
2602
+ }
2603
+
2301
2604
  function Icon({ name, size, stroke, className }) {
2302
2605
  return h(
2303
2606
  "svg",
@@ -2336,7 +2639,7 @@ window.__ModuleLoader__.load({
2336
2639
  );
2337
2640
  }
2338
2641
 
2339
- function IconButton({ icon, label, onClick, disabled, loading, active, badge }) {
2642
+ function IconButton({ icon, iconNode, label, onClick, disabled, loading, active, badge }) {
2340
2643
  return h(
2341
2644
  "button",
2342
2645
  {
@@ -2348,7 +2651,7 @@ window.__ModuleLoader__.load({
2348
2651
  "aria-label": label,
2349
2652
  "aria-pressed": active === undefined ? undefined : !!active,
2350
2653
  },
2351
- loading ? h("span", { className: "mesh-spinner" }) : h(Icon, { name: icon, size: 15 }),
2654
+ loading ? h("span", { className: "mesh-spinner" }) : iconNode || h(Icon, { name: icon, size: 15 }),
2352
2655
  badge ? h("span", { className: "mesh-icon-badge" }, badge > 9 ? "9+" : String(badge)) : null,
2353
2656
  );
2354
2657
  }
@@ -2826,16 +3129,28 @@ window.__ModuleLoader__.load({
2826
3129
  );
2827
3130
  }
2828
3131
 
2829
- function DeviceRow({ peer, isSelf, active, onSelect, now, index }) {
3132
+ function DeviceRow({ peer, isSelf, active, onSelect, onWeb, onSsh, now, index }) {
2830
3133
  const online = !!peer.online || !!isSelf;
2831
3134
  const name = peer.machine || "未命名设备";
3135
+ const webUrl = isSelf ? "" : dshWebUrl(peer);
3136
+ const select = () => onSelect(peer.id);
2832
3137
  return h(
2833
- "button",
3138
+ "div",
2834
3139
  {
2835
- type: "button",
3140
+ role: "button",
3141
+ tabIndex: 0,
2836
3142
  className: cls("mesh-row", active && "is-active", !online && "is-offline"),
2837
- onClick: () => onSelect(peer.id),
3143
+ onClick: select,
3144
+ onKeyDown: (event) => {
3145
+ // 只处理落在行本身上的回车/空格;行内按钮自己处理自己的键盘事件。
3146
+ if (event.target !== event.currentTarget) return;
3147
+ if (event.key === "Enter" || event.key === " " || event.key === "Spacebar") {
3148
+ event.preventDefault();
3149
+ select();
3150
+ }
3151
+ },
2838
3152
  "aria-label": `${name},${online ? "在线" : "离线"}`,
3153
+ "aria-pressed": !!active,
2839
3154
  "data-mesh-view": "devices",
2840
3155
  "data-mesh-peer": peer.machine || "",
2841
3156
  "data-mesh-instance": peer.instanceId || peer.id || "",
@@ -2861,11 +3176,40 @@ window.__ModuleLoader__.load({
2861
3176
  h("span", null, isSelf ? "现在" : ago(peer.lastSeen, now)),
2862
3177
  ),
2863
3178
  ),
2864
- h("span", { className: "mesh-row-side" }, h(Icon, { name: "chevron", size: 13 })),
3179
+ h(
3180
+ "span",
3181
+ { className: "mesh-row-side" },
3182
+ // 「访问 DSH Web」:不选中设备,直接在对端的 DSH Web 上开一个页面。
3183
+ webUrl && onWeb
3184
+ ? h(IconButton, {
3185
+ // 用 DSH 官方 logo 而不是地球:这一格代表的是"那台机器上的 DSH"
3186
+ iconNode: h(DshMark, { size: 14 }),
3187
+ label: `访问 ${name} 的 DSH Web(${webUrl})`,
3188
+ disabled: !online,
3189
+ onClick: (event) => {
3190
+ event.stopPropagation();
3191
+ onWeb(peer);
3192
+ },
3193
+ })
3194
+ : null,
3195
+ // SSH 终端:与「访问 DSH Web」同一位置,连的是对端 22 端口
3196
+ !isSelf && onSsh
3197
+ ? h(IconButton, {
3198
+ icon: "terminal",
3199
+ label: `SSH 连接到 ${name}`,
3200
+ disabled: !online,
3201
+ onClick: (event) => {
3202
+ event.stopPropagation();
3203
+ onSsh(peer);
3204
+ },
3205
+ })
3206
+ : null,
3207
+ h(Icon, { name: "chevron", size: 13 }),
3208
+ ),
2865
3209
  );
2866
3210
  }
2867
3211
 
2868
- function DeviceList({ selfPeer, peers, selectedId, onSelect, now, lastOk, onScan, scanning }) {
3212
+ function DeviceList({ selfPeer, peers, selectedId, onSelect, onWeb, onSsh, now, lastOk, onScan, scanning }) {
2869
3213
  return h(
2870
3214
  "aside",
2871
3215
  { className: "mesh-list-pane" },
@@ -2886,12 +3230,12 @@ window.__ModuleLoader__.load({
2886
3230
  react.Fragment,
2887
3231
  null,
2888
3232
  h("div", { className: "mesh-list-heading" }, "本机"),
2889
- h(DeviceRow, { peer: selfPeer, isSelf: true, active: selectedId === "self", onSelect, now, index: 0 }),
3233
+ h(DeviceRow, { peer: selfPeer, isSelf: true, active: selectedId === "self", onSelect, onWeb, onSsh, now, index: 0 }),
2890
3234
  )
2891
3235
  : null,
2892
3236
  h("div", { className: "mesh-list-heading" }, "其他设备"),
2893
3237
  peers.length
2894
- ? peers.map((p, i) => h(DeviceRow, { key: p.id, peer: p, active: selectedId === p.id, onSelect, now, index: i + 1 }))
3238
+ ? peers.map((p, i) => h(DeviceRow, { key: p.id, peer: p, active: selectedId === p.id, onSelect, onWeb, onSsh, now, index: i + 1 }))
2895
3239
  : h("div", { className: "mesh-list-empty" }, "还没有发现其他设备。点下面探测一次本网段。"),
2896
3240
  h(
2897
3241
  "div",
@@ -3069,7 +3413,7 @@ window.__ModuleLoader__.load({
3069
3413
  }
3070
3414
 
3071
3415
  function DeviceView(props) {
3072
- const { selfPeer, peers, selectedPeer, selectedId, onSelect, mobilePane, onBack, onCompose, onProbe, probe, hostDown, now, lastOk, onScan, scanning, firstRun, onRename, recentTasks, onOpenTask, onAllTasks } = props;
3416
+ const { selfPeer, peers, selectedPeer, selectedId, onSelect, onWeb, onSsh, mobilePane, onBack, onCompose, onProbe, probe, hostDown, now, lastOk, onScan, scanning, firstRun, onRename, recentTasks, onOpenTask, onAllTasks } = props;
3073
3417
  return h(
3074
3418
  react.Fragment,
3075
3419
  null,
@@ -3077,7 +3421,7 @@ window.__ModuleLoader__.load({
3077
3421
  h(
3078
3422
  "div",
3079
3423
  { className: "mesh-split", "data-pane": mobilePane },
3080
- h(DeviceList, { selfPeer, peers, selectedId, onSelect, now, lastOk, onScan, scanning }),
3424
+ h(DeviceList, { selfPeer, peers, selectedId, onSelect, onWeb, onSsh, now, lastOk, onScan, scanning }),
3081
3425
  h(DeviceDetail, { peer: selectedPeer, isSelf: selectedId === "self", onCompose, onProbe, probe, hostDown, now, onBack, onRename, onScan, recentTasks, onOpenTask, onAllTasks }),
3082
3426
  ),
3083
3427
  );
@@ -3560,6 +3904,302 @@ window.__ModuleLoader__.load({
3560
3904
  );
3561
3905
  }
3562
3906
 
3907
+ /**
3908
+ * 对端 DSH Web 的应用内面板。
3909
+ *
3910
+ * 承载方式是同源 iframe —— 指向**本机**的一个回环反代端口(宿主的
3911
+ * /mesh/api/web-panel 起出来的),对端认证在服务端完成。所以这里不需要
3912
+ * token、不依赖壳的浏览器 WebView,也不受对端 cookie SameSite 限制。
3913
+ */
3914
+ function WebPanel({ panel, onClose, onReload }) {
3915
+ if (!panel) return null;
3916
+ const ready = panel.state === "ready";
3917
+ const name = panel.name || "对端";
3918
+ return h(
3919
+ "div",
3920
+ {
3921
+ className: "mesh-web-layer",
3922
+ role: "dialog",
3923
+ "aria-modal": "true",
3924
+ "aria-label": `${name} 的 DSH Web`,
3925
+ "data-mesh-view": "web",
3926
+ },
3927
+ h(
3928
+ "div",
3929
+ { className: "mesh-web-bar" },
3930
+ h(
3931
+ "button",
3932
+ { type: "button", className: "mesh-panel-back", onClick: onClose, "aria-label": "关闭面板" },
3933
+ h(Icon, { name: "back", size: 14 }),
3934
+ h("span", null, "返回"),
3935
+ ),
3936
+ h("span", { className: "mesh-web-mark", "aria-hidden": "true" }, h(DshMark, { size: 16 })),
3937
+ h(
3938
+ "span",
3939
+ { className: "mesh-web-title", title: panel.remote || "" },
3940
+ name,
3941
+ h("span", { className: "mesh-web-sub" }, " · DSH Web"),
3942
+ ),
3943
+ h(IconButton, { icon: "refresh", label: "重新加载面板", onClick: onReload }),
3944
+ ),
3945
+ !ready
3946
+ ? h(
3947
+ "div",
3948
+ { className: "mesh-web-status" },
3949
+ h("span", { className: "mesh-spinner" }),
3950
+ h("span", null, "正在起回环代理…"),
3951
+ )
3952
+ : null,
3953
+ ready && panel.hasSession === false
3954
+ ? h(
3955
+ "div",
3956
+ { className: "mesh-web-status is-warn" },
3957
+ h(Icon, { name: "alert", size: 14 }),
3958
+ h("span", null, panel.note || "对端没给出可用 token,面板可能停在登录页。"),
3959
+ )
3960
+ : null,
3961
+ ready
3962
+ ? h("iframe", {
3963
+ key: panel.reloadKey || 0,
3964
+ className: "mesh-web-frame",
3965
+ src: panel.url,
3966
+ title: `${name} 的 DSH Web`,
3967
+ // 对端界面里要用剪贴板(复制命令/日志),别让它被静默拒绝。
3968
+ allow: "clipboard-read; clipboard-write; fullscreen",
3969
+ referrerPolicy: "no-referrer",
3970
+ })
3971
+ : null,
3972
+ );
3973
+ }
3974
+
3975
+
3976
+ /** 去掉终端控制序列:没有 xterm 时,把 ANSI 转义剥掉才不会满屏乱码。 */
3977
+ function stripAnsi(text) {
3978
+ return String(text)
3979
+ .replace(/\u001b\][^\u0007]*\u0007/g, "")
3980
+ .replace(/\u001b\[[0-9;?]*[ -/]*[@-~]/g, "")
3981
+ .replace(/\r(?!\n)/g, "");
3982
+ }
3983
+
3984
+ /**
3985
+ * 应用内 SSH 终端。
3986
+ *
3987
+ * 传输走同源 WebSocket(/mesh/api/ssh/ws),SSH 本身由本机宿主发起;
3988
+ * 这里只是个"哑终端":输出按行渲染、输入整行发送,另给 Ctrl+C / Tab 两个键。
3989
+ * 没做完整 VT100(没有 xterm 依赖),够用来跑命令、看日志。
3990
+ */
3991
+ function SshPanel({ peer, onClose }) {
3992
+ const machine = (peer && peer.machine) || "";
3993
+ const [phase, setPhase] = react.useState("form");
3994
+ const [username, setUsername] = react.useState("");
3995
+ const [password, setPassword] = react.useState("");
3996
+ const [hasKey, setHasKey] = react.useState(false);
3997
+ // 密钥属于哪个用户名:换了用户名就不能再拿它去认证(否则只会得到认证失败)
3998
+ const [keyUser, setKeyUser] = react.useState("");
3999
+ // 密钥失效时不至于卡死:允许手动切回密码登录
4000
+ const [forcePassword, setForcePassword] = react.useState(false);
4001
+ const [output, setOutput] = react.useState("");
4002
+ const [line, setLine] = react.useState("");
4003
+ const [error, setError] = react.useState("");
4004
+ const wsRef = react.useRef(null);
4005
+ const idRef = react.useRef("");
4006
+ const outRef = react.useRef(null);
4007
+
4008
+ react.useEffect(() => {
4009
+ let alive = true;
4010
+ api("/ssh/known", { machine })
4011
+ .then((r) => {
4012
+ if (!alive || !r || !r.ok) return;
4013
+ if (r.username) {
4014
+ setUsername(r.username);
4015
+ setKeyUser(r.username);
4016
+ }
4017
+ if (r.hasKey) setHasKey(true);
4018
+ })
4019
+ .catch(() => {});
4020
+ return () => {
4021
+ alive = false;
4022
+ };
4023
+ }, [machine]);
4024
+
4025
+ react.useEffect(() => {
4026
+ const el = outRef.current;
4027
+ if (el) el.scrollTop = el.scrollHeight;
4028
+ }, [output]);
4029
+
4030
+ const closeSocket = () => {
4031
+ try {
4032
+ wsRef.current?.close();
4033
+ } catch {
4034
+ /* 已关 */
4035
+ }
4036
+ wsRef.current = null;
4037
+ idRef.current = "";
4038
+ };
4039
+
4040
+ react.useEffect(() => () => closeSocket(), []);
4041
+
4042
+ const connect = () => {
4043
+ setError("");
4044
+ setOutput("");
4045
+ setPhase("connecting");
4046
+ const scheme = location.protocol === "https:" ? "wss" : "ws";
4047
+ let ws;
4048
+ try {
4049
+ ws = new WebSocket(`${scheme}://${location.host}/mesh/api/ssh/ws`);
4050
+ } catch (e) {
4051
+ setError(String(e && e.message ? e.message : e));
4052
+ setPhase("error");
4053
+ return;
4054
+ }
4055
+ wsRef.current = ws;
4056
+ ws.onopen = () => {
4057
+ ws.send(
4058
+ JSON.stringify({
4059
+ type: "open",
4060
+ machine,
4061
+ host: peer.host || "",
4062
+ port: 22,
4063
+ username: username.trim(),
4064
+ password: keyApplies && !forcePassword ? "" : password,
4065
+ cols: 100,
4066
+ rows: 30,
4067
+ }),
4068
+ );
4069
+ };
4070
+ ws.onmessage = (event) => {
4071
+ let msg;
4072
+ try {
4073
+ msg = JSON.parse(event.data);
4074
+ } catch {
4075
+ return;
4076
+ }
4077
+ if (msg.type === "ready") {
4078
+ idRef.current = msg.id;
4079
+ setPhase("open");
4080
+ if (msg.buffer) setOutput(stripAnsi(msg.buffer));
4081
+ return;
4082
+ }
4083
+ if (msg.type === "data") {
4084
+ setOutput((prev) => (prev + stripAnsi(msg.data)).slice(-200000));
4085
+ return;
4086
+ }
4087
+ if (msg.type === "exit") {
4088
+ setPhase("closed");
4089
+ return;
4090
+ }
4091
+ if (msg.type === "error") {
4092
+ setError(String(msg.message || "未知错误"));
4093
+ setPhase("error");
4094
+ }
4095
+ };
4096
+ ws.onerror = () => {
4097
+ setError("连接通道错误(WebSocket)");
4098
+ setPhase("error");
4099
+ };
4100
+ ws.onclose = () => {
4101
+ setPhase((prev) => (prev === "error" ? prev : "closed"));
4102
+ };
4103
+ };
4104
+
4105
+ const sendInput = (data) => {
4106
+ const ws = wsRef.current;
4107
+ if (!ws || ws.readyState !== 1 || !idRef.current) return;
4108
+ ws.send(JSON.stringify({ type: "input", id: idRef.current, data }));
4109
+ };
4110
+
4111
+ const submit = (event) => {
4112
+ event.preventDefault();
4113
+ if (!line.trim()) return;
4114
+ sendInput(line + "\r");
4115
+ setLine("");
4116
+ };
4117
+
4118
+ const disconnect = () => {
4119
+ const id = idRef.current;
4120
+ if (id) sendInput.call(null, ""); // 占位,避免 eslint 抱怨
4121
+ try {
4122
+ if (id) wsRef.current?.send(JSON.stringify({ type: "close", id }));
4123
+ } catch {
4124
+ /* 忽略 */
4125
+ }
4126
+ closeSocket();
4127
+ onClose();
4128
+ };
4129
+
4130
+ const keyApplies = hasKey && keyUser !== "" && username.trim() === keyUser;
4131
+ const name = machine || "对端";
4132
+ return h(
4133
+ "div",
4134
+ { className: "mesh-web-layer", role: "dialog", "aria-modal": "true", "aria-label": `${name} 的 SSH 终端` },
4135
+ h(
4136
+ "div",
4137
+ { className: "mesh-web-bar" },
4138
+ h("button", { type: "button", className: "mesh-panel-back", onClick: disconnect }, h(Icon, { name: "back", size: 14 }), h("span", null, "返回")),
4139
+ h("span", { className: "mesh-web-title" }, name, h("span", { className: "mesh-web-sub" }, " · SSH")),
4140
+ phase === "open"
4141
+ ? h(IconButton, { icon: "close", label: "断开连接", onClick: disconnect })
4142
+ : null,
4143
+ ),
4144
+ phase === "form" || phase === "connecting" || phase === "error"
4145
+ ? h(
4146
+ "div",
4147
+ { className: "mesh-ssh-form" },
4148
+ h(
4149
+ "div",
4150
+ { className: "mesh-ssh-note" },
4151
+ keyApplies
4152
+ ? "已部署本机公钥,直接连接即可(免密)。"
4153
+ : hasKey
4154
+ ? `公钥属于 ${keyUser};当前用户名不同,请输入密码。`
4155
+ : "首次连接需要用户名和密码;成功后会自动把本机公钥写到对端,之后免密。",
4156
+ ),
4157
+ h("label", { className: "mesh-ssh-field" }, h("span", null, "用户名"), h("input", { value: username, onChange: (e) => setUsername(e.target.value), autoCapitalize: "none", spellCheck: false })),
4158
+ keyApplies && !forcePassword
4159
+ ? null
4160
+ : h("label", { className: "mesh-ssh-field" }, h("span", null, "密码"), h("input", { type: "password", value: password, onChange: (e) => setPassword(e.target.value) })),
4161
+ keyApplies && !forcePassword && (phase === "error" || phase === "form")
4162
+ ? h(
4163
+ "button",
4164
+ {
4165
+ type: "button",
4166
+ className: "mesh-ssh-key",
4167
+ onClick: () => {
4168
+ setForcePassword(true);
4169
+ setError("");
4170
+ setPhase("form");
4171
+ },
4172
+ },
4173
+ "改用密码连接",
4174
+ )
4175
+ : null,
4176
+ error ? h("div", { className: "mesh-ssh-error" }, error) : null,
4177
+ h(
4178
+ Button,
4179
+ { variant: "primary", onClick: connect, disabled: !username.trim() || phase === "connecting" },
4180
+ phase === "connecting" ? "连接中…" : "连接",
4181
+ ),
4182
+ )
4183
+ : null,
4184
+ phase === "open" || phase === "closed"
4185
+ ? h(
4186
+ react.Fragment,
4187
+ null,
4188
+ h("pre", { className: "mesh-ssh-out", ref: outRef }, output || "已连接,等输出…"),
4189
+ phase === "closed" ? h("div", { className: "mesh-ssh-note" }, "会话已结束") : null,
4190
+ h(
4191
+ "form",
4192
+ { className: "mesh-ssh-inputrow", onSubmit: submit },
4193
+ h("input", { value: line, onChange: (e) => setLine(e.target.value), placeholder: "输入命令,回车执行", autoCapitalize: "none", spellCheck: false }),
4194
+ h("button", { type: "button", className: "mesh-ssh-key", onClick: () => sendInput("\u0003") }, "Ctrl-C"),
4195
+ h("button", { type: "button", className: "mesh-ssh-key", onClick: () => sendInput("\t") }, "Tab"),
4196
+ h("button", { type: "submit", className: "mesh-ssh-send" }, "发送"),
4197
+ ),
4198
+ )
4199
+ : null,
4200
+ );
4201
+ }
4202
+
3563
4203
  function TransferLog({ items, onClose, onRetry, onLocate, onCopy }) {
3564
4204
  return h(
3565
4205
  "div",
@@ -3966,6 +4606,158 @@ window.__ModuleLoader__.load({
3966
4606
 
3967
4607
  // ─────────────────────── 连接 / 设置 ───────────────────────
3968
4608
 
4609
+ /**
4610
+ * 一键关闭(kill switch)。
4611
+ *
4612
+ * 三个范围与宿主 lib/switch.js 一致:all / lan / internet。
4613
+ * 刻意**不做二次确认**:这个功能最需要的时刻是"我怀疑有人能连上我",
4614
+ * 那一刻要的是快;误点的代价只是再点一次打开(配置、会话都不丢)。
4615
+ * 牙口留给别处:按钮文案写清楚会发生什么,关闭后顶部横幅常驻提示。
4616
+ */
4617
+ const MESH_SWITCH_ROWS = [
4618
+ {
4619
+ scope: "all",
4620
+ title: "全部 Mesh",
4621
+ icon: "power",
4622
+ desc: "局域网 + 互联网一起关。关掉后这台机器不再被任何设备发现,也不再接受任务。",
4623
+ },
4624
+ {
4625
+ scope: "lan",
4626
+ title: "局域网 Mesh",
4627
+ icon: "wifi",
4628
+ desc: "停发组播、停止扫描与 ping,对端端口从局域网收回(只绑本机回环)。",
4629
+ },
4630
+ {
4631
+ scope: "internet",
4632
+ title: "互联网 Mesh",
4633
+ icon: "tailscale",
4634
+ desc: "停掉全部 tailnet sidecar。通道与授权码保留,打开即恢复,不用重新登录。",
4635
+ },
4636
+ ];
4637
+
4638
+ function SwitchRow({ row, off, badge, meta, note, busy, onToggle }) {
4639
+ return h(
4640
+ "div",
4641
+ { className: cls("mesh-switch-row", off && "is-off"), "data-mesh-switch": row.scope },
4642
+ h("span", { className: "mesh-switch-row-icon" }, h(Icon, { name: row.icon, size: 15 })),
4643
+ h(
4644
+ "div",
4645
+ { className: "mesh-switch-row-main" },
4646
+ h(
4647
+ "div",
4648
+ { className: "mesh-switch-row-top" },
4649
+ h("span", { className: "mesh-switch-row-title" }, row.title),
4650
+ h(Badge, { kind: off ? "warn" : "ok" }, badge),
4651
+ ),
4652
+ h("div", { className: "mesh-switch-row-desc" }, row.desc),
4653
+ meta ? h("div", { className: "mesh-switch-row-meta" }, meta) : null,
4654
+ note ? h("div", { className: "mesh-note is-warn", style: { marginTop: 8 } }, h(Icon, { name: "alert", size: 13 }), h("span", null, note)) : null,
4655
+ ),
4656
+ h(
4657
+ "div",
4658
+ { className: "mesh-switch-row-action" },
4659
+ h(
4660
+ Button,
4661
+ {
4662
+ variant: off ? "secondary" : "danger",
4663
+ size: "sm",
4664
+ icon: off ? "check" : "power",
4665
+ loading: busy,
4666
+ onClick: () => onToggle(row.scope, !off),
4667
+ },
4668
+ off ? "打开" : `一键关闭${row.scope === "all" ? " Mesh" : ""}`,
4669
+ ),
4670
+ ),
4671
+ );
4672
+ }
4673
+
4674
+ function SwitchBody({ sw, push, reload }) {
4675
+ const st = sw || {};
4676
+ const lan = st.lan || {};
4677
+ const net = st.internet || {};
4678
+ const [busy, setBusy] = react.useState("");
4679
+ const [error, setError] = react.useState("");
4680
+
4681
+ const apply = async (scope, off) => {
4682
+ setBusy(scope);
4683
+ setError("");
4684
+ try {
4685
+ const r = await api("/switch", { scope, off });
4686
+ if (r && r.ok) {
4687
+ const label = scope === "all" ? "Mesh" : scope === "lan" ? "局域网 Mesh" : "互联网 Mesh";
4688
+ push(
4689
+ "success",
4690
+ `${label}已${off ? "关闭" : "打开"}${r.changed === false ? "(本来就是这个状态)" : ""}`,
4691
+ // 误点一键关闭时,"撤销"要在一处就能点回来,而不是去翻三个开关
4692
+ { label: "撤销", onClick: () => apply(scope, !off) },
4693
+ );
4694
+ await reload();
4695
+ } else {
4696
+ setError(apiErr(r));
4697
+ }
4698
+ } catch (e) {
4699
+ setError(String((e && e.message) || e));
4700
+ } finally {
4701
+ setBusy("");
4702
+ }
4703
+ };
4704
+
4705
+ const LAN_META = () =>
4706
+ lan.off
4707
+ ? `对端端口${lan.port ? ` ${lan.bind || "回环"}:${lan.port}` : "已停"} · 组播已停`
4708
+ : `监听 ${lan.bind || "—"}:${lan.port || "—"} · 组播 ${lan.multicast ? "开" : "关"}`;
4709
+ const NET_META = () =>
4710
+ `运行中 ${net.running || 0} / 已启用 ${net.configured || 0} 条通道` + (net.off ? " · sidecar 已停" : "");
4711
+
4712
+ // 「全部」这一行不能复用单条的 active:两条都开着才叫全部开启,
4713
+ // 只关了一条要显示「部分关闭」而不是含糊的「开启」。
4714
+ const partial = !st.all && (!!lan.off || !!net.off);
4715
+ const values = {
4716
+ all: {
4717
+ off: !!st.all,
4718
+ badge: st.all ? "已关闭" : partial ? "部分关闭" : "全部开启",
4719
+ meta: `${lan.off ? "局域网已关" : "局域网开着"} · ${net.off ? "互联网已关" : "互联网开着"}`,
4720
+ },
4721
+ lan: { off: !!lan.off, badge: lan.off ? "已关闭" : lan.active ? "运行中" : "开启(未监听)", meta: LAN_META(), note: lan.note || "" },
4722
+ internet: {
4723
+ off: !!net.off,
4724
+ badge: net.off ? "已关闭" : net.active ? "运行中" : net.stalled ? "启动受阻" : "开启(未连接)",
4725
+ meta: NET_META(),
4726
+ note: net.note || "",
4727
+ },
4728
+ };
4729
+
4730
+ return h(
4731
+ "div",
4732
+ null,
4733
+ h(
4734
+ "p",
4735
+ { className: "mesh-p", style: { marginBottom: 4 } },
4736
+ "关闭立即生效,并写入本机状态 —— 重启 DSH 后仍保持关闭,直到在这里打开。面板本身始终可用。",
4737
+ ),
4738
+ error ? h("div", { className: "mesh-note is-err", style: { marginTop: 10 } }, h(Icon, { name: "alert", size: 13 }), h("span", null, error)) : null,
4739
+ h(
4740
+ "div",
4741
+ { className: "mesh-switch-list" },
4742
+ MESH_SWITCH_ROWS.map((row) =>
4743
+ h(SwitchRow, {
4744
+ key: row.scope,
4745
+ row,
4746
+ off: values[row.scope].off,
4747
+ badge: values[row.scope].badge,
4748
+ meta: values[row.scope].meta,
4749
+ note: values[row.scope].note,
4750
+ busy: busy === row.scope,
4751
+ onToggle: apply,
4752
+ }),
4753
+ ),
4754
+ ),
4755
+ st.by
4756
+ ? h("p", { className: "mesh-hint", style: { marginTop: 10 } }, `最近一次操作:${st.at ? new Date(st.at).toLocaleString() : "—"}(${st.by === "tool" ? "agent 调用" : st.by === "ui" ? "界面" : st.by})`)
4757
+ : null,
4758
+ );
4759
+ }
4760
+
3969
4761
  function SettingsSection({ id, icon, title, subtitle, status, open, onToggle, children }) {
3970
4762
  return h(
3971
4763
  "section",
@@ -4222,18 +5014,23 @@ window.__ModuleLoader__.load({
4222
5014
  /** 单条通道的阶段 → 文案/颜色。 */
4223
5015
  function channelPhase(ch) {
4224
5016
  const p = ch && ch.node && ch.node.phase ? ch.node.phase : ch && ch.enabled ? "idle" : "off";
5017
+ // 卡在控制面上时 phase 仍然会是 starting —— 光看 phase 会一直显示「正在启动」。
5018
+ // node.stalled 是宿主按时间+证据给的结论,优先级更高(真机反馈 2026-10-29)。
5019
+ const stalled = !!(ch && ch.node && ch.node.stalled);
4225
5020
  const map = {
4226
5021
  off: ["未启用", "idle"],
4227
5022
  idle: ["未连接", "idle"],
4228
5023
  starting: ["正在启动", "warn"],
4229
5024
  downloading: ["正在下载组件", "warn"],
4230
5025
  "needs-login": ["需要授权", "warn"],
5026
+ stalled: ["启动受阻", "err"],
4231
5027
  running: ["已连接", "ok"],
4232
5028
  exited: ["已停止", "idle"],
4233
5029
  error: ["出错", "err"],
4234
5030
  };
4235
- const m = map[p] || [p, "idle"];
4236
- return { phase: p, label: m[0], kind: m[1] };
5031
+ const key = stalled && p !== "running" ? "stalled" : p;
5032
+ const m = map[key] || [p, "idle"];
5033
+ return { phase: key, label: m[0], kind: m[1] };
4237
5034
  }
4238
5035
 
4239
5036
  /**
@@ -4264,6 +5061,7 @@ window.__ModuleLoader__.load({
4264
5061
  if (running > 0) phase = "running";
4265
5062
  else if (phases.includes("needs-login")) phase = "needs-login";
4266
5063
  else if (phases.includes("downloading")) phase = "downloading";
5064
+ else if (phases.includes("stalled")) phase = "stalled";
4267
5065
  else if (phases.includes("starting")) phase = "starting";
4268
5066
  else if (phases.includes("error")) phase = "error";
4269
5067
  else if (phases.includes("exited")) phase = "exited";
@@ -4275,6 +5073,7 @@ window.__ModuleLoader__.load({
4275
5073
  starting: ["正在启动", "warn"],
4276
5074
  downloading: ["正在下载组件", "warn"],
4277
5075
  "needs-login": ["需要授权", "warn"],
5076
+ stalled: ["启动受阻", "err"],
4278
5077
  running: ["已连接", "ok"],
4279
5078
  exited: ["已停止", "idle"],
4280
5079
  error: ["出错", "err"],
@@ -4488,7 +5287,7 @@ window.__ModuleLoader__.load({
4488
5287
  disabled: isBusy && busy !== `/tsnet/start:${ch.id}`,
4489
5288
  onClick: () => run("/tsnet/start", { id: ch.id }, `通道「${ch.label || ch.id}」已启动`),
4490
5289
  },
4491
- "连接",
5290
+ cp.phase === "stalled" ? "重试连接" : "连接",
4492
5291
  ),
4493
5292
  ),
4494
5293
  node && node.authUrl
@@ -4502,6 +5301,19 @@ window.__ModuleLoader__.load({
4502
5301
  ),
4503
5302
  )
4504
5303
  : null,
5304
+ node && node.stalled
5305
+ ? h(
5306
+ "div",
5307
+ { className: "mesh-note is-err" },
5308
+ h(Icon, { name: "alert", size: 13 }),
5309
+ h(
5310
+ "span",
5311
+ null,
5312
+ `启动受阻:${node.stalledReason || "控制面一直没有回应"}`,
5313
+ node.stalledHint ? h("div", { className: "mesh-hint", style: { marginTop: 4 } }, node.stalledHint) : null,
5314
+ ),
5315
+ )
5316
+ : null,
4505
5317
  node && node.error
4506
5318
  ? h(
4507
5319
  "div",
@@ -4680,8 +5492,20 @@ window.__ModuleLoader__.load({
4680
5492
  const self = (state && state.self) || {};
4681
5493
  const cfg = (state && state.config) || {};
4682
5494
  const tsnet = state && state.tsnet;
5495
+ const sw = state && state.switch;
4683
5496
  const phase = tsnetPhase(tsnet);
4684
5497
  const toggle = (id) => onOpen(open === id ? null : id);
5498
+ // 关闭状态的摘要要能一眼看出"哪一条被关了",而不是只说"有东西关了"
5499
+ const swOff = Boolean(sw && (sw.lan.off || sw.internet.off));
5500
+ const swSubtitle = !sw
5501
+ ? "本机 mesh 开关"
5502
+ : sw.all
5503
+ ? "全部已关闭 · 不广播、不监听、不接受任务"
5504
+ : sw.lan.off
5505
+ ? "局域网已关闭 · 互联网仍可用"
5506
+ : sw.internet.off
5507
+ ? "互联网已关闭 · 局域网仍可用"
5508
+ : "全部开启 · 局域网 + 互联网";
4685
5509
 
4686
5510
  return h(
4687
5511
  "div",
@@ -4695,6 +5519,21 @@ window.__ModuleLoader__.load({
4695
5519
  // tab 已经叫「连接」了,标题再写一遍是重复;这里只留一句说明。
4696
5520
  h("p", null, "本机身份、配对码与跨网络互联。改动立即生效,不需要重启。"),
4697
5521
  ),
5522
+ sw
5523
+ ? h(
5524
+ SettingsSection,
5525
+ {
5526
+ id: "switch",
5527
+ icon: "power",
5528
+ title: "一键关闭",
5529
+ subtitle: swSubtitle,
5530
+ status: h(Badge, { kind: swOff ? "warn" : "ok" }, sw.all ? "全部关闭" : swOff ? "部分关闭" : "全部开启"),
5531
+ open: open === "switch",
5532
+ onToggle: () => toggle("switch"),
5533
+ },
5534
+ h(SwitchBody, { sw, push, reload }),
5535
+ )
5536
+ : null,
4698
5537
  h(
4699
5538
  SettingsSection,
4700
5539
  {
@@ -4773,6 +5612,69 @@ window.__ModuleLoader__.load({
4773
5612
  );
4774
5613
  }
4775
5614
 
5615
+ /**
5616
+ * 概览卡上的「一键关闭」快捷条。
5617
+ *
5618
+ * 为什么放主页概览:用户想关 mesh 的时候通常就在主页,不在设置页 ——
5619
+ * 要的是"一眼看见状态、一下点掉",而不是先找到连接页再展开折叠。
5620
+ * 设置页里那份保留:那里有端口/组播/受阻原因等细节。
5621
+ *
5622
+ * 三个胶囊都**没有二次确认**:这是紧急动作,误点的成本只是再点一次。
5623
+ */
5624
+ function HomeSwitchBar({ sw, push, reload }) {
5625
+ const [busy, setBusy] = react.useState("");
5626
+ if (!sw) return null; // 老宿主没有这个能力:不占位、也不显示一个点了没用的按钮
5627
+ const lan = sw.lan || {};
5628
+ const net = sw.internet || {};
5629
+ const rows = [
5630
+ { scope: "all", label: "全部", off: !!sw.all },
5631
+ { scope: "lan", label: "局域网", off: !!lan.off },
5632
+ { scope: "internet", label: "互联网", off: !!net.off, stalled: !net.off && !!net.stalled },
5633
+ ];
5634
+ const toggle = async (scope, off) => {
5635
+ setBusy(scope);
5636
+ try {
5637
+ const r = await api("/switch", { scope, off });
5638
+ if (r && r.ok) {
5639
+ const name = scope === "all" ? "Mesh" : scope === "lan" ? "局域网 Mesh" : "互联网 Mesh";
5640
+ push("success", `${name}已${off ? "关闭" : "打开"}`, {
5641
+ label: "撤销",
5642
+ onClick: () => toggle(scope, !off),
5643
+ });
5644
+ await reload();
5645
+ } else {
5646
+ push("error", apiErr(r));
5647
+ }
5648
+ } catch (e) {
5649
+ push("error", String((e && e.message) || e));
5650
+ } finally {
5651
+ setBusy("");
5652
+ }
5653
+ };
5654
+ return h(
5655
+ "div",
5656
+ { className: "mesh-home-switch", "data-mesh-home-switch": "1" },
5657
+ h("span", { className: "mesh-home-switch-label" }, "一键关闭"),
5658
+ rows.map((r) => {
5659
+ const stateText = r.off ? "已关" : r.stalled ? "受阻" : "开";
5660
+ return h(
5661
+ "button",
5662
+ {
5663
+ key: r.scope,
5664
+ type: "button",
5665
+ className: cls("mesh-home-switch-pill", r.off && "is-off", r.stalled && "is-stalled", busy === r.scope && "is-busy"),
5666
+ disabled: !!busy,
5667
+ title: `${r.off ? "打开" : "关闭"}${r.scope === "all" ? " Mesh(局域网 + 互联网)" : r.scope === "lan" ? "局域网 Mesh" : "互联网 Mesh"}`,
5668
+ onClick: () => toggle(r.scope, !r.off),
5669
+ },
5670
+ h(Dot, { kind: r.off ? "idle" : r.stalled ? "warn" : "ok" }),
5671
+ h("span", { className: "mesh-home-switch-name" }, r.label),
5672
+ h("span", { className: "mesh-home-switch-state" }, busy === r.scope ? "…" : stateText),
5673
+ );
5674
+ }),
5675
+ );
5676
+ }
5677
+
4776
5678
  function HomeCard({ card, subtitle, status, editing, index, count, onMove, onHide, children, footer }) {
4777
5679
  return h(
4778
5680
  "article",
@@ -4824,6 +5726,8 @@ window.__ModuleLoader__.load({
4824
5726
  onDevices,
4825
5727
  onTasks,
4826
5728
  onConnect,
5729
+ onWeb,
5730
+ onSsh,
4827
5731
  onScan,
4828
5732
  scanning,
4829
5733
  firstRun,
@@ -5574,11 +6478,15 @@ window.__ModuleLoader__.load({
5574
6478
  onDevices,
5575
6479
  onTasks,
5576
6480
  onConnect,
6481
+ onWeb,
6482
+ onSsh,
5577
6483
  onScan,
5578
6484
  scanning,
5579
6485
  firstRun,
5580
6486
  hostDown,
5581
6487
  onDispatched,
6488
+ push,
6489
+ reload,
5582
6490
  }) {
5583
6491
  const [editing, setEditing] = react.useState(false);
5584
6492
  const [drag, setDrag] = react.useState({ draggingId: null, dropId: null, resizingId: null });
@@ -5740,6 +6648,39 @@ window.__ModuleLoader__.load({
5740
6648
  h(Dot, { kind: p.online ? "ok" : "idle" }),
5741
6649
  h("span", { className: "mesh-mini-name" }, p.machine || "未命名设备"),
5742
6650
  h("span", { className: "mesh-mini-meta" }, p.online ? `在线 · ${osLabel(p.os)}` : `${ago(p.lastSeen, now)}`),
6651
+ // 与「设备」页同一组入口:访问 DSH Web / SSH 终端
6652
+ h(
6653
+ "span",
6654
+ { className: "mesh-mini-actions" },
6655
+ onWeb
6656
+ ? h(
6657
+ "button",
6658
+ {
6659
+ type: "button",
6660
+ className: "mesh-mini-act",
6661
+ title: `访问 ${p.machine || "对端"} 的 DSH Web`,
6662
+ "aria-label": `访问 ${p.machine || "对端"} 的 DSH Web`,
6663
+ disabled: !p.online,
6664
+ onClick: () => onWeb(p),
6665
+ },
6666
+ h(DshMark, { size: 14 }),
6667
+ )
6668
+ : null,
6669
+ onSsh
6670
+ ? h(
6671
+ "button",
6672
+ {
6673
+ type: "button",
6674
+ className: "mesh-mini-act",
6675
+ title: `SSH 连接到 ${p.machine || "对端"}`,
6676
+ "aria-label": `SSH 连接到 ${p.machine || "对端"}`,
6677
+ disabled: !p.online,
6678
+ onClick: () => onSsh(p),
6679
+ },
6680
+ h(Icon, { name: "terminal", size: 14 }),
6681
+ )
6682
+ : null,
6683
+ ),
5743
6684
  ),
5744
6685
  )
5745
6686
  : h("p", { className: "mesh-card-text" }, "还没有发现其他设备。扫描本网段,或让对方也打开 Mesh。");
@@ -5852,6 +6793,7 @@ window.__ModuleLoader__.load({
5852
6793
  h(HomeStat, { label: "跨网络", value: tsnet ? phase.label : "未启用" }),
5853
6794
  h(HomeStat, { label: "更新", value: ago(lastOk, now) }),
5854
6795
  ),
6796
+ h(HomeSwitchBar, { sw: state && state.switch, push, reload }),
5855
6797
  ),
5856
6798
  footer: h(
5857
6799
  react.Fragment,
@@ -6105,7 +7047,7 @@ window.__ModuleLoader__.load({
6105
7047
 
6106
7048
  // ─────────────────────── 工作台外壳 ───────────────────────
6107
7049
 
6108
- function TopBar({ view, onView, online, total, taskCount, error, lastOk, now, refreshing, onRefresh, scanning, onScan, disabled, busy, focus, onToggleFocus, onTransfer, transferActive, onLog, transferCount }) {
7050
+ function TopBar({ view, onView, online, total, taskCount, error, lastOk, now, refreshing, onRefresh, scanning, onScan, disabled, busy, focus, onToggleFocus, onTransfer, transferActive, onLog, transferCount, onExit }) {
6109
7051
  const tabs = [
6110
7052
  { value: "home", label: "主页", icon: "home" },
6111
7053
  { value: "devices", label: "设备", icon: "device", count: total },
@@ -6117,6 +7059,23 @@ window.__ModuleLoader__.load({
6117
7059
  return h(
6118
7060
  "header",
6119
7061
  { className: "mesh-topbar", "aria-busy": !!busy },
7062
+ // 主面板是"点进去出不来"的:宿主只在插件管理页注入返回键,Mesh 这个
7063
+ // 主面板没有,窄屏上连侧边栏都被抽屉挡住。这里自带一个,直接回到会话。
7064
+ onExit
7065
+ ? h(
7066
+ "button",
7067
+ {
7068
+ type: "button",
7069
+ className: "mesh-panel-back",
7070
+ onClick: onExit,
7071
+ title: "返回会话(退出 Mesh 面板)",
7072
+ "aria-label": "返回会话",
7073
+ "data-mesh-view": "back",
7074
+ },
7075
+ h(Icon, { name: "back", size: 14 }),
7076
+ h("span", { className: "mesh-panel-back-text" }, "返回"),
7077
+ )
7078
+ : null,
6120
7079
  h(
6121
7080
  "div",
6122
7081
  { className: "mesh-brand" },
@@ -6243,6 +7202,10 @@ window.__ModuleLoader__.load({
6243
7202
  const [taskFilter, setTaskFilter] = react.useState("all");
6244
7203
  const [composer, setComposer] = react.useState(null);
6245
7204
  const [probe, setProbe] = react.useState(null);
7205
+ // 对端 DSH Web 的应用内面板:{ peer, name, state: loading|ready, url, note, hasSession, reloadKey }
7206
+ const [webPanel, setWebPanel] = react.useState(null);
7207
+ // SSH 终端面板:null 或某个 peer
7208
+ const [sshPeer, setSshPeer] = react.useState(null);
6246
7209
  const [scanning, setScanning] = react.useState(false);
6247
7210
  const [nameBusy, setNameBusy] = react.useState(false);
6248
7211
  const [nameDismissed, setNameDismissed] = react.useState(false);
@@ -6256,6 +7219,7 @@ window.__ModuleLoader__.load({
6256
7219
  const self = state && state.self ? state.self : null;
6257
7220
  const peers = state && Array.isArray(state.peers) ? state.peers : [];
6258
7221
  const online = peers.filter((p) => p && p.online).length;
7222
+ const sw = state && state.switch ? state.switch : null;
6259
7223
  const tasks = react.useMemo(() => taskList(state), [state]);
6260
7224
  const sortedPeers = react.useMemo(
6261
7225
  () =>
@@ -6434,7 +7398,110 @@ window.__ModuleLoader__.load({
6434
7398
  };
6435
7399
 
6436
7400
  /**
6437
- * 派发成功的统一收尾:toast + 让轮询立刻刷新。
7401
+ * 打开对端的 DSH Web。
7402
+ *
7403
+ * 主路是**应用内面板**:宿主起一个回环反代(认证在服务端做),这里只
7404
+ * 把它的地址塞进同源 iframe —— 不依赖壳的浏览器 WebView(本机没有),
7405
+ * 也不受对端 cookie 的 SameSite=Strict 影响。
7406
+ * 反代起不来时才退回老的"浏览器页签 / 外部浏览器"那条链。
7407
+ */
7408
+ const openWeb = async (peer) => {
7409
+ const name = (peer && peer.machine) || "对端";
7410
+ setWebPanel({ peer, name, state: "loading", reloadKey: 0 });
7411
+ try {
7412
+ const r = await api("/web-panel", { peer: (peer && (peer.machine || peer.id)) || "" });
7413
+ if (r && r.ok === true && typeof r.url === "string") {
7414
+ setWebPanel((prev) => ({
7415
+ ...(prev || { peer, name }),
7416
+ state: "ready",
7417
+ url: r.url,
7418
+ remote: r.remote || "",
7419
+ hasSession: r.hasSession !== false,
7420
+ note: r.note || "",
7421
+ reloadKey: 0,
7422
+ }));
7423
+ if (r.hasSession === false) {
7424
+ push("warn", `${name} 那边没给出可用 token,面板可能停在登录页。`);
7425
+ }
7426
+ return;
7427
+ }
7428
+ setWebPanel(null);
7429
+ push("warn", `应用内面板起不来(${(r && r.error) || "未知原因"}),改用外部方式打开。`);
7430
+ } catch (error) {
7431
+ setWebPanel(null);
7432
+ push("warn", `应用内面板起不来(${String((error && error.message) || error)}),改用外部方式打开。`);
7433
+ }
7434
+
7435
+ let result;
7436
+ try {
7437
+ result = await openDshWebPage(peer);
7438
+ } catch (error) {
7439
+ push("error", `打不开 ${name} 的 Web:${String((error && error.message) || error)}`);
7440
+ return;
7441
+ }
7442
+ if (!result.ok) {
7443
+ push("error", `打不开 ${name} 的 Web:${result.reason || "未知原因"}`);
7444
+ return;
7445
+ }
7446
+ if (result.lanReachable === false) {
7447
+ push("warn", `${name} 只监听 127.0.0.1,手机连不通;在那边把 webserver.host 改成 0.0.0.0 再重启。`);
7448
+ return;
7449
+ }
7450
+ if (result.browserUnavailable) {
7451
+ push("warn", `这台壳没有可用的浏览器 WebView,已改用外部浏览器打开 ${result.url}`);
7452
+ return;
7453
+ }
7454
+ if (result.how === "browser" && result.viaHost) {
7455
+ push("success", `已打开 ${result.url}`);
7456
+ return;
7457
+ }
7458
+ if (result.how === "browser") {
7459
+ push("info", `已打开 ${result.url}`);
7460
+ return;
7461
+ }
7462
+ push("info", `应用内浏览器不可用,已用外部浏览器打开 ${result.url}`);
7463
+ };
7464
+
7465
+ /**
7466
+ * 回到会话:上游 layout.selectPanel(null)。
7467
+ *
7468
+ * 宿主(Android 壳)只会给**插件管理页**注入返回键,任何其它主面板都得
7469
+ * 自己带出口——否则窄屏上点进 Mesh 就只剩浏览器的返回手势。
7470
+ */
7471
+ const leavePanel = () => {
7472
+ try {
7473
+ const layout = (pluginCtx && pluginCtx.get ? pluginCtx.get("layout") : null) || null;
7474
+ if (layout && typeof layout.selectPanel === "function") {
7475
+ layout.selectPanel(null);
7476
+ return;
7477
+ }
7478
+ } catch (error) {
7479
+ // 落到下面的兜底提示,不要静默失效
7480
+ }
7481
+ push("warn", "当前宿主没有 layout 服务,无法自动回到会话;用侧边栏切回对话即可。");
7482
+ };
7483
+
7484
+ /**
7485
+ * 关掉对端 Web 面板:先卸载前端这一层,再尽力让宿主把反代也停掉
7486
+ * (停不掉只是多一个回环端口,不影响正确性)。
7487
+ */
7488
+ const closeWebPanel = () => {
7489
+ const machine = webPanel && webPanel.peer ? webPanel.peer.machine || webPanel.peer.id || "" : "";
7490
+ setWebPanel(null);
7491
+ if (!machine) return;
7492
+ api("/web-panel/close", { peer: machine }).catch(() => {
7493
+ /* 关闭是尽力而为 */
7494
+ });
7495
+ };
7496
+
7497
+ /** 重新拉起面板(对端重启过、或 iframe 白屏时用)。 */
7498
+ const reloadWebPanel = () => {
7499
+ const peer = webPanel && webPanel.peer;
7500
+ if (!peer) return;
7501
+ void openWeb(peer);
7502
+ };
7503
+
7504
+ /** 派发成功的统一收尾:toast + 让轮询立刻刷新。
6438
7505
  * 设备页弹层和主页的派发面板共用它,免得两处提示文案慢慢走散。
6439
7506
  */
6440
7507
  const notifyDispatched = (name, r) => {
@@ -6607,6 +7674,7 @@ window.__ModuleLoader__.load({
6607
7674
  transferActive: false,
6608
7675
  onLog: () => setTransferLogOpen(true),
6609
7676
  transferCount: transfers.length,
7677
+ onExit: leavePanel,
6610
7678
  }),
6611
7679
  loading ? h(LoadingView) : h(ErrorView, { error, onRetry: reload, onCopy: () => copy(error) }),
6612
7680
  );
@@ -6645,6 +7713,7 @@ window.__ModuleLoader__.load({
6645
7713
  setTransferLogOpen(true);
6646
7714
  },
6647
7715
  transferCount: transfers.filter((item) => item.status === "sent" || item.status === "delivered").length,
7716
+ onExit: leavePanel,
6648
7717
  }),
6649
7718
  error
6650
7719
  ? h(Banner, {
@@ -6654,6 +7723,25 @@ window.__ModuleLoader__.load({
6654
7723
  action: { label: "重试", onClick: reload },
6655
7724
  })
6656
7725
  : null,
7726
+ sw && (sw.lan.off || sw.internet.off)
7727
+ ? h(Banner, {
7728
+ kind: "warn",
7729
+ title: sw.all
7730
+ ? "Mesh 已全部关闭"
7731
+ : sw.lan.off
7732
+ ? "局域网 Mesh 已关闭"
7733
+ : "互联网 Mesh 已关闭",
7734
+ // 关掉之后"没有设备"是正常的,不是故障 —— 这一句把两者区分开
7735
+ detail: `${sw.summary || ""} · 关闭期间不广播、不接受任务;重启后仍保持`.trim(),
7736
+ action: {
7737
+ label: "去打开",
7738
+ onClick: () => {
7739
+ setView("connect");
7740
+ setSettingsOpen("switch");
7741
+ },
7742
+ },
7743
+ })
7744
+ : null,
6657
7745
  state.duplicateNames && state.duplicateNames.length
6658
7746
  ? h(Banner, {
6659
7747
  kind: "warn",
@@ -6693,11 +7781,15 @@ window.__ModuleLoader__.load({
6693
7781
  onDevices: goDevices,
6694
7782
  onTasks: goTasks,
6695
7783
  onConnect: openConnect,
7784
+ onWeb: openWeb,
7785
+ onSsh: (peer) => setSshPeer(peer),
6696
7786
  onScan: doScan,
6697
7787
  scanning,
6698
7788
  firstRun: firstRunNode,
6699
7789
  hostDown,
6700
7790
  onDispatched: (peer, r) => notifyDispatched((peer && peer.machine) || "", r),
7791
+ push,
7792
+ reload,
6701
7793
  })
6702
7794
  : view === "devices"
6703
7795
  ? h(DeviceView, {
@@ -6706,6 +7798,8 @@ window.__ModuleLoader__.load({
6706
7798
  selectedPeer,
6707
7799
  selectedId,
6708
7800
  onSelect: selectPeer,
7801
+ onWeb: openWeb,
7802
+ onSsh: (peer) => setSshPeer(peer),
6709
7803
  mobilePane,
6710
7804
  onBack: () => setMobilePane("list"),
6711
7805
  onCompose: openComposer,
@@ -6782,6 +7876,8 @@ window.__ModuleLoader__.load({
6782
7876
  onCopy: copyTransfer,
6783
7877
  })
6784
7878
  : null,
7879
+ h(WebPanel, { panel: webPanel, onClose: closeWebPanel, onReload: reloadWebPanel }),
7880
+ sshPeer ? h(SshPanel, { peer: sshPeer, onClose: () => setSshPeer(null) }) : null,
6785
7881
  h(Toasts, { items: toasts, onClose: close }),
6786
7882
  );
6787
7883
  }
@@ -6835,6 +7931,10 @@ window.__ModuleLoader__.load({
6835
7931
  TasksView,
6836
7932
  DeviceDetail,
6837
7933
  DeviceRow,
7934
+ dshWebUrl,
7935
+ resolveWebUrl,
7936
+ openDshWebPage,
7937
+ WebPanel,
6838
7938
  CapabilityChips,
6839
7939
  TaskRow,
6840
7940
  TaskDetail,
@@ -6857,7 +7957,12 @@ window.__ModuleLoader__.load({
6857
7957
  sendToAgent,
6858
7958
  PairingBody,
6859
7959
  TsnetBody,
7960
+ SwitchBody,
7961
+ SwitchRow,
7962
+ HomeSwitchBar,
6860
7963
  };
6861
7964
  return module.exports;
6862
7965
  },
6863
7966
  });
7967
+ ;
7968
+ //# sourceMappingURL=??dsh-plugin-mesh/client.js.map&rev=81fe4f4a3488