dsh-plugin-mesh 0.5.5 → 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;
@@ -1373,6 +1574,14 @@ window.__ModuleLoader__.load({
1373
1574
  .mesh-mini-row:first-child { border-top: 0; padding-top: 0; }
1374
1575
  .mesh-mini-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
1375
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; }
1376
1585
  .mesh-home-hidden {
1377
1586
  margin-top: 18px; padding-top: 14px;
1378
1587
  border-top: 1px solid var(--mesh-line);
@@ -1767,6 +1976,7 @@ window.__ModuleLoader__.load({
1767
1976
  gap: 8px;
1768
1977
  }
1769
1978
  .mesh-brand { order: 1; }
1979
+ .mesh-panel-back { order: 0; height: 28px; padding: 0 8px 0 6px; font-size: 11.5px; }
1770
1980
  .mesh-topright { order: 2; }
1771
1981
  .mesh-tabs { order: 3; flex: 0 0 100%; width: 100%; }
1772
1982
  .mesh-tab { flex: 1 1 0; justify-content: center; padding: 7px 6px; }
@@ -1838,6 +2048,7 @@ window.__ModuleLoader__.load({
1838
2048
  .mesh-task-row {
1839
2049
  touch-action: manipulation;
1840
2050
  }
2051
+ .mesh-panel-back { touch-action: manipulation; }
1841
2052
  .mesh-tab { min-height: 44px; }
1842
2053
  .mesh-btn,
1843
2054
  .mesh-btn--sm,
@@ -2289,6 +2500,8 @@ window.__ModuleLoader__.load({
2289
2500
  ];
2290
2501
  case "chevron":
2291
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" })];
2292
2505
  case "close":
2293
2506
  return [
2294
2507
  h("path", { key: "a", d: "M6 6l12 12" }),
@@ -2369,6 +2582,25 @@ window.__ModuleLoader__.load({
2369
2582
  }
2370
2583
  }
2371
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
+
2372
2604
  function Icon({ name, size, stroke, className }) {
2373
2605
  return h(
2374
2606
  "svg",
@@ -2407,7 +2639,7 @@ window.__ModuleLoader__.load({
2407
2639
  );
2408
2640
  }
2409
2641
 
2410
- function IconButton({ icon, label, onClick, disabled, loading, active, badge }) {
2642
+ function IconButton({ icon, iconNode, label, onClick, disabled, loading, active, badge }) {
2411
2643
  return h(
2412
2644
  "button",
2413
2645
  {
@@ -2419,7 +2651,7 @@ window.__ModuleLoader__.load({
2419
2651
  "aria-label": label,
2420
2652
  "aria-pressed": active === undefined ? undefined : !!active,
2421
2653
  },
2422
- 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 }),
2423
2655
  badge ? h("span", { className: "mesh-icon-badge" }, badge > 9 ? "9+" : String(badge)) : null,
2424
2656
  );
2425
2657
  }
@@ -2897,16 +3129,28 @@ window.__ModuleLoader__.load({
2897
3129
  );
2898
3130
  }
2899
3131
 
2900
- function DeviceRow({ peer, isSelf, active, onSelect, now, index }) {
3132
+ function DeviceRow({ peer, isSelf, active, onSelect, onWeb, onSsh, now, index }) {
2901
3133
  const online = !!peer.online || !!isSelf;
2902
3134
  const name = peer.machine || "未命名设备";
3135
+ const webUrl = isSelf ? "" : dshWebUrl(peer);
3136
+ const select = () => onSelect(peer.id);
2903
3137
  return h(
2904
- "button",
3138
+ "div",
2905
3139
  {
2906
- type: "button",
3140
+ role: "button",
3141
+ tabIndex: 0,
2907
3142
  className: cls("mesh-row", active && "is-active", !online && "is-offline"),
2908
- 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
+ },
2909
3152
  "aria-label": `${name},${online ? "在线" : "离线"}`,
3153
+ "aria-pressed": !!active,
2910
3154
  "data-mesh-view": "devices",
2911
3155
  "data-mesh-peer": peer.machine || "",
2912
3156
  "data-mesh-instance": peer.instanceId || peer.id || "",
@@ -2932,11 +3176,40 @@ window.__ModuleLoader__.load({
2932
3176
  h("span", null, isSelf ? "现在" : ago(peer.lastSeen, now)),
2933
3177
  ),
2934
3178
  ),
2935
- 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
+ ),
2936
3209
  );
2937
3210
  }
2938
3211
 
2939
- function DeviceList({ selfPeer, peers, selectedId, onSelect, now, lastOk, onScan, scanning }) {
3212
+ function DeviceList({ selfPeer, peers, selectedId, onSelect, onWeb, onSsh, now, lastOk, onScan, scanning }) {
2940
3213
  return h(
2941
3214
  "aside",
2942
3215
  { className: "mesh-list-pane" },
@@ -2957,12 +3230,12 @@ window.__ModuleLoader__.load({
2957
3230
  react.Fragment,
2958
3231
  null,
2959
3232
  h("div", { className: "mesh-list-heading" }, "本机"),
2960
- 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 }),
2961
3234
  )
2962
3235
  : null,
2963
3236
  h("div", { className: "mesh-list-heading" }, "其他设备"),
2964
3237
  peers.length
2965
- ? 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 }))
2966
3239
  : h("div", { className: "mesh-list-empty" }, "还没有发现其他设备。点下面探测一次本网段。"),
2967
3240
  h(
2968
3241
  "div",
@@ -3140,7 +3413,7 @@ window.__ModuleLoader__.load({
3140
3413
  }
3141
3414
 
3142
3415
  function DeviceView(props) {
3143
- 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;
3144
3417
  return h(
3145
3418
  react.Fragment,
3146
3419
  null,
@@ -3148,7 +3421,7 @@ window.__ModuleLoader__.load({
3148
3421
  h(
3149
3422
  "div",
3150
3423
  { className: "mesh-split", "data-pane": mobilePane },
3151
- h(DeviceList, { selfPeer, peers, selectedId, onSelect, now, lastOk, onScan, scanning }),
3424
+ h(DeviceList, { selfPeer, peers, selectedId, onSelect, onWeb, onSsh, now, lastOk, onScan, scanning }),
3152
3425
  h(DeviceDetail, { peer: selectedPeer, isSelf: selectedId === "self", onCompose, onProbe, probe, hostDown, now, onBack, onRename, onScan, recentTasks, onOpenTask, onAllTasks }),
3153
3426
  ),
3154
3427
  );
@@ -3631,6 +3904,302 @@ window.__ModuleLoader__.load({
3631
3904
  );
3632
3905
  }
3633
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
+
3634
4203
  function TransferLog({ items, onClose, onRetry, onLocate, onCopy }) {
3635
4204
  return h(
3636
4205
  "div",
@@ -5157,6 +5726,8 @@ window.__ModuleLoader__.load({
5157
5726
  onDevices,
5158
5727
  onTasks,
5159
5728
  onConnect,
5729
+ onWeb,
5730
+ onSsh,
5160
5731
  onScan,
5161
5732
  scanning,
5162
5733
  firstRun,
@@ -5907,6 +6478,8 @@ window.__ModuleLoader__.load({
5907
6478
  onDevices,
5908
6479
  onTasks,
5909
6480
  onConnect,
6481
+ onWeb,
6482
+ onSsh,
5910
6483
  onScan,
5911
6484
  scanning,
5912
6485
  firstRun,
@@ -6075,6 +6648,39 @@ window.__ModuleLoader__.load({
6075
6648
  h(Dot, { kind: p.online ? "ok" : "idle" }),
6076
6649
  h("span", { className: "mesh-mini-name" }, p.machine || "未命名设备"),
6077
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
+ ),
6078
6684
  ),
6079
6685
  )
6080
6686
  : h("p", { className: "mesh-card-text" }, "还没有发现其他设备。扫描本网段,或让对方也打开 Mesh。");
@@ -6441,7 +7047,7 @@ window.__ModuleLoader__.load({
6441
7047
 
6442
7048
  // ─────────────────────── 工作台外壳 ───────────────────────
6443
7049
 
6444
- 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 }) {
6445
7051
  const tabs = [
6446
7052
  { value: "home", label: "主页", icon: "home" },
6447
7053
  { value: "devices", label: "设备", icon: "device", count: total },
@@ -6453,6 +7059,23 @@ window.__ModuleLoader__.load({
6453
7059
  return h(
6454
7060
  "header",
6455
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,
6456
7079
  h(
6457
7080
  "div",
6458
7081
  { className: "mesh-brand" },
@@ -6579,6 +7202,10 @@ window.__ModuleLoader__.load({
6579
7202
  const [taskFilter, setTaskFilter] = react.useState("all");
6580
7203
  const [composer, setComposer] = react.useState(null);
6581
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);
6582
7209
  const [scanning, setScanning] = react.useState(false);
6583
7210
  const [nameBusy, setNameBusy] = react.useState(false);
6584
7211
  const [nameDismissed, setNameDismissed] = react.useState(false);
@@ -6771,7 +7398,110 @@ window.__ModuleLoader__.load({
6771
7398
  };
6772
7399
 
6773
7400
  /**
6774
- * 派发成功的统一收尾: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 + 让轮询立刻刷新。
6775
7505
  * 设备页弹层和主页的派发面板共用它,免得两处提示文案慢慢走散。
6776
7506
  */
6777
7507
  const notifyDispatched = (name, r) => {
@@ -6944,6 +7674,7 @@ window.__ModuleLoader__.load({
6944
7674
  transferActive: false,
6945
7675
  onLog: () => setTransferLogOpen(true),
6946
7676
  transferCount: transfers.length,
7677
+ onExit: leavePanel,
6947
7678
  }),
6948
7679
  loading ? h(LoadingView) : h(ErrorView, { error, onRetry: reload, onCopy: () => copy(error) }),
6949
7680
  );
@@ -6982,6 +7713,7 @@ window.__ModuleLoader__.load({
6982
7713
  setTransferLogOpen(true);
6983
7714
  },
6984
7715
  transferCount: transfers.filter((item) => item.status === "sent" || item.status === "delivered").length,
7716
+ onExit: leavePanel,
6985
7717
  }),
6986
7718
  error
6987
7719
  ? h(Banner, {
@@ -7049,6 +7781,8 @@ window.__ModuleLoader__.load({
7049
7781
  onDevices: goDevices,
7050
7782
  onTasks: goTasks,
7051
7783
  onConnect: openConnect,
7784
+ onWeb: openWeb,
7785
+ onSsh: (peer) => setSshPeer(peer),
7052
7786
  onScan: doScan,
7053
7787
  scanning,
7054
7788
  firstRun: firstRunNode,
@@ -7064,6 +7798,8 @@ window.__ModuleLoader__.load({
7064
7798
  selectedPeer,
7065
7799
  selectedId,
7066
7800
  onSelect: selectPeer,
7801
+ onWeb: openWeb,
7802
+ onSsh: (peer) => setSshPeer(peer),
7067
7803
  mobilePane,
7068
7804
  onBack: () => setMobilePane("list"),
7069
7805
  onCompose: openComposer,
@@ -7140,6 +7876,8 @@ window.__ModuleLoader__.load({
7140
7876
  onCopy: copyTransfer,
7141
7877
  })
7142
7878
  : null,
7879
+ h(WebPanel, { panel: webPanel, onClose: closeWebPanel, onReload: reloadWebPanel }),
7880
+ sshPeer ? h(SshPanel, { peer: sshPeer, onClose: () => setSshPeer(null) }) : null,
7143
7881
  h(Toasts, { items: toasts, onClose: close }),
7144
7882
  );
7145
7883
  }
@@ -7193,6 +7931,10 @@ window.__ModuleLoader__.load({
7193
7931
  TasksView,
7194
7932
  DeviceDetail,
7195
7933
  DeviceRow,
7934
+ dshWebUrl,
7935
+ resolveWebUrl,
7936
+ openDshWebPage,
7937
+ WebPanel,
7196
7938
  CapabilityChips,
7197
7939
  TaskRow,
7198
7940
  TaskDetail,
@@ -7222,3 +7964,5 @@ window.__ModuleLoader__.load({
7222
7964
  return module.exports;
7223
7965
  },
7224
7966
  });
7967
+ ;
7968
+ //# sourceMappingURL=??dsh-plugin-mesh/client.js.map&rev=81fe4f4a3488