dsh-plugin-mesh 0.5.5 → 0.5.7

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,10 +29,19 @@ 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";
35
39
  const TRANSFER_LIMIT = 50;
40
+ // 更新与反馈都指向同一个 GitHub 仓库;邮件是 GitHub 不通时的退路
41
+ //(作者机器上 git-over-https 到 github.com 常被重置,见 AGENTS.md)。
42
+ const RELEASE_REPO = "peng456/dsh-plugin-mesh";
43
+ const NEW_ISSUE_URL = `https://github.com/${RELEASE_REPO}/issues/new`;
44
+ const FEEDBACK_MAIL = "geekstartup@163.com";
36
45
  let pluginCtx = null;
37
46
 
38
47
  const HOME_PREF_KEY = "mesh.home.v1";
@@ -185,16 +194,128 @@ window.__ModuleLoader__.load({
185
194
  return ep ? shortAddress(ep.host, ep.port) : "地址未知";
186
195
  }
187
196
 
197
+ /** 对端的局域网主机名/IP(不带 mesh 端口):优先 peer.host,其次第一个 endpoint。 */
198
+ function peerHost(peer) {
199
+ if (!peer) return "";
200
+ if (peer.host) return String(peer.host);
201
+ const eps = Array.isArray(peer.endpoints) ? peer.endpoints : [];
202
+ const ep = eps.find((x) => x && x.host);
203
+ return ep ? String(ep.host) : "";
204
+ }
205
+
206
+ /** 对端 DSH Web 的地址;没有地址时返回空串(不编一个出来)。 */
207
+ function dshWebUrl(peer) {
208
+ const host = peerHost(peer);
209
+ if (!host) return "";
210
+ let port = DSH_WEB_PORT;
211
+ try {
212
+ const custom = Number(localStorage.getItem(WEB_PORT_KEY));
213
+ if (Number.isFinite(custom) && custom > 0 && custom < 65536) port = Math.floor(custom);
214
+ } catch {
215
+ /* 存储不可用就用默认端口 */
216
+ }
217
+ return `http://${host}:${port}/`;
218
+ }
219
+
220
+ /**
221
+ * 要一条能直接打开的地址。
222
+ *
223
+ * 优先问本机宿主(/mesh/api/web-url):它去对端的配对通道里取一条带启动
224
+ * token 的地址,端口和 bind 都是对端自报的真值。对端是老版本插件、或者
225
+ * 取不到时,退回按约定拼出来的 http://<host>:3080/——那种情况浏览器会
226
+ * 停在 401 页,提示用户去对端取一次 token 地址。
227
+ * @returns {{ url: string, source: string, lanReachable?: boolean, reason?: string }}
228
+ */
229
+ async function resolveWebUrl(peer) {
230
+ const fallback = dshWebUrl(peer);
231
+ try {
232
+ const r = await api("/web-url", { peer: (peer && (peer.machine || peer.id)) || "" });
233
+ if (r && r.ok === true && typeof r.url === "string" && r.url)
234
+ return { url: r.url, source: "host", lanReachable: r.lanReachable === true };
235
+ return { url: fallback, source: "computed", reason: (r && r.error) || "" };
236
+ } catch (error) {
237
+ return { url: fallback, source: "computed", reason: String((error && error.message) || error) };
238
+ }
239
+ }
240
+
241
+ /**
242
+ * 壳里的原生浏览器是否可用(只读探测)。
243
+ *
244
+ * 这台 Android 壳会明确报 browserWebViewAvailable=false(工位 WebView 未就绪),
245
+ * 此时开 browser 页签只会落到一个"浏览器不可用"的空页面 —— 那比直接退回
246
+ * 外部浏览器更糟。所以先问一句:**壳明确说不可用才降级**,问不出来照常试。
247
+ */
248
+ function nativeBrowserUsable(sessionId) {
249
+ try {
250
+ const bridge = window.androidBridge;
251
+ if (!bridge || typeof bridge.browserHostCommand !== "function") return false;
252
+ if (!sessionId) return true; // 没有会话就无从判断,按可用处理
253
+ const raw = bridge.browserHostCommand(
254
+ JSON.stringify({ action: "status", session: sessionId, uiTabId: "mesh-probe" }),
255
+ );
256
+ if (typeof raw !== "string" || raw === "") return true; // 没答上来:不据此降级
257
+ const value = JSON.parse(raw);
258
+ return !(value && value.available === false);
259
+ } catch {
260
+ return true;
261
+ }
262
+ }
263
+
264
+ /**
265
+ * 在对端的 DSH Web 上开一个页面。
266
+ * 先走应用内浏览器(sidebar.right 的 browser 页签)——它就是壳里的那个
267
+ * WebView,不跳出 DSH;浏览器页不可用时退回外部浏览器。
268
+ * @returns {Promise<{ ok: boolean, how: string, url: string, lanReachable?: boolean, reason?: string }>}
269
+ */
270
+ async function openDshWebPage(peer) {
271
+ const resolved = await resolveWebUrl(peer);
272
+ const url = resolved.url;
273
+ if (!url) return { ok: false, how: "none", url: "", reason: resolved.reason || "这台设备没有上报地址" };
274
+ const extra = {
275
+ lanReachable: resolved.lanReachable,
276
+ viaHost: resolved.source === "host",
277
+ };
278
+ const sidebar = pluginCtx && pluginCtx.get ? pluginCtx.get("sidebarRight") : null;
279
+ const sessionId = currentSessionId();
280
+ const browserUsable = nativeBrowserUsable(sessionId);
281
+ // 先试强校验的 openTab(没有在屏会话会抛),再退化到按 session 的 openTabIn。
282
+ try {
283
+ if (browserUsable && sidebar && typeof sidebar.openTab === "function") {
284
+ sidebar.openTab("browser", { params: { url }, revealIfOpened: false });
285
+ return { ok: true, how: "browser", url, ...extra };
286
+ }
287
+ } catch {
288
+ /* 落到 openTabIn */
289
+ }
290
+ try {
291
+ if (browserUsable && sidebar && typeof sidebar.openTabIn === "function" && sessionId) {
292
+ sidebar.openTabIn(sessionId, "browser", { params: { url }, revealIfOpened: false });
293
+ return { ok: true, how: "browser", url, ...extra };
294
+ }
295
+ } catch {
296
+ /* 落到外部浏览器 */
297
+ }
298
+ const bridge = window.androidBridge;
299
+ if (bridge && typeof bridge.openExternalLink === "function") {
300
+ try {
301
+ bridge.openExternalLink(url);
302
+ return { ok: true, how: "external", url, ...extra, browserUnavailable: !browserUsable };
303
+ } catch {
304
+ return { ok: false, how: "none", url, reason: "外部浏览器也打不开" };
305
+ }
306
+ }
307
+ if (typeof window.open === "function") {
308
+ window.open(url, "_blank");
309
+ return { ok: true, how: "window", url, ...extra };
310
+ }
311
+ return { ok: false, how: "none", url, reason: "没有可用的打开方式" };
312
+ }
313
+
188
314
  function apiErr(r) {
189
315
  return (r && (r.error || r.message)) || "未知错误";
190
316
  }
191
317
 
192
- async function api(path, body) {
193
- const r = await fetch(API + path, {
194
- method: "POST",
195
- headers: { "content-type": "application/json" },
196
- body: JSON.stringify(body || {}),
197
- });
318
+ async function parseApiResponse(r) {
198
319
  let j = {};
199
320
  try {
200
321
  j = await r.json();
@@ -205,6 +326,24 @@ window.__ModuleLoader__.load({
205
326
  return j;
206
327
  }
207
328
 
329
+ async function api(path, body) {
330
+ const r = await fetch(API + path, {
331
+ method: "POST",
332
+ headers: { "content-type": "application/json" },
333
+ body: JSON.stringify(body || {}),
334
+ });
335
+ return parseApiResponse(r);
336
+ }
337
+
338
+ /** 只读接口走 GET(/mesh/api/update 就是这一类:查一次版本,不改任何状态)。 */
339
+ async function apiGet(path) {
340
+ const r = await fetch(API + path, {
341
+ headers: { accept: "application/json" },
342
+ cache: "no-store",
343
+ });
344
+ return parseApiResponse(r);
345
+ }
346
+
208
347
  async function copyText(text) {
209
348
  try {
210
349
  if (navigator.clipboard && navigator.clipboard.writeText) {
@@ -650,6 +789,86 @@ window.__ModuleLoader__.load({
650
789
  background: var(--mesh-bg);
651
790
  }
652
791
  .mesh-brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
792
+ /* 主面板的"出口":宿主只给插件管理页注入返回键,Mesh 面板得自己带一个。 */
793
+ .mesh-panel-back {
794
+ flex: 0 0 auto;
795
+ display: inline-flex; align-items: center; gap: 4px;
796
+ height: 30px; padding: 0 10px 0 7px;
797
+ border: 1px solid var(--mesh-line); border-radius: 8px;
798
+ background: var(--mesh-surface); color: var(--mesh-muted);
799
+ font-size: 12px; line-height: 1; cursor: pointer;
800
+ transition: background var(--mesh-dur-fast) var(--mesh-ease-out),
801
+ color var(--mesh-dur-fast) var(--mesh-ease-out),
802
+ transform var(--mesh-dur-press) var(--mesh-ease-out);
803
+ }
804
+ .mesh-panel-back:hover { background: var(--mesh-surface-2); color: var(--mesh-fg); }
805
+ .mesh-panel-back:active { transform: scale(0.97); }
806
+ .mesh-panel-back:focus-visible { outline: 2px solid var(--mesh-accent); outline-offset: 2px; }
807
+ /* ── 对端 DSH Web 的应用内面板 ── */
808
+ .mesh-web-layer {
809
+ position: absolute; inset: 0; z-index: 60;
810
+ display: flex; flex-direction: column;
811
+ background: var(--mesh-bg);
812
+ }
813
+ .mesh-web-bar {
814
+ flex: 0 0 auto;
815
+ display: flex; align-items: center; gap: 8px;
816
+ padding: 6px 10px;
817
+ border-bottom: 1px solid var(--mesh-line);
818
+ background: var(--mesh-bg);
819
+ }
820
+ .mesh-web-title {
821
+ flex: 1 1 auto; min-width: 0;
822
+ font-size: 12.5px; font-weight: 600;
823
+ white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
824
+ }
825
+ .mesh-web-sub { color: var(--mesh-muted); font-weight: 400; }
826
+ .mesh-web-mark { flex: 0 0 auto; display: inline-flex; align-items: center; color: var(--mesh-fg); }
827
+ .mesh-web-frame { flex: 1 1 auto; width: 100%; min-height: 0; border: 0; background: var(--mesh-bg); }
828
+ .mesh-web-status {
829
+ flex: 0 0 auto;
830
+ display: flex; align-items: center; gap: 6px;
831
+ padding: 8px 12px;
832
+ font-size: 11.5px; line-height: 1.5;
833
+ color: var(--mesh-muted);
834
+ }
835
+ .mesh-web-status.is-warn { color: var(--mesh-warn); }
836
+
837
+ /* ── SSH 终端面板 ── */
838
+ .mesh-ssh-form { display: flex; flex-direction: column; gap: 10px; padding: 16px; max-width: 520px; }
839
+ .mesh-ssh-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--mesh-muted); }
840
+ .mesh-ssh-field input {
841
+ height: 36px; padding: 0 10px;
842
+ border: 1px solid var(--mesh-line-2); border-radius: 8px;
843
+ background: var(--mesh-surface); color: var(--mesh-fg); font-size: 14px;
844
+ }
845
+ .mesh-ssh-note { font-size: 11.5px; color: var(--mesh-muted); line-height: 1.5; }
846
+ .mesh-ssh-error { font-size: 12px; color: var(--mesh-err); }
847
+ .mesh-ssh-out {
848
+ flex: 1 1 auto; min-height: 0; margin: 0; padding: 10px 12px;
849
+ overflow: auto; white-space: pre-wrap; word-break: break-all;
850
+ background: #111418; color: #d7dde5;
851
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
852
+ font-size: 11.5px; line-height: 1.5;
853
+ }
854
+ .mesh-ssh-inputrow {
855
+ flex: 0 0 auto; display: flex; align-items: center; gap: 6px;
856
+ padding: 8px 10px; border-top: 1px solid var(--mesh-line);
857
+ background: var(--mesh-bg);
858
+ }
859
+ .mesh-ssh-inputrow input {
860
+ flex: 1 1 auto; min-width: 0; height: 36px; padding: 0 10px;
861
+ border: 1px solid var(--mesh-line-2); border-radius: 8px;
862
+ background: var(--mesh-surface); color: var(--mesh-fg);
863
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
864
+ }
865
+ .mesh-ssh-key, .mesh-ssh-send {
866
+ flex: 0 0 auto; height: 36px; padding: 0 10px;
867
+ border: 1px solid var(--mesh-line-2); border-radius: 8px;
868
+ background: var(--mesh-surface); color: var(--mesh-fg); font-size: 12px; cursor: pointer;
869
+ }
870
+ .mesh-ssh-send { background: var(--mesh-fg); color: var(--mesh-bg); border-color: transparent; }
871
+
653
872
  .mesh-logo {
654
873
  width: 26px; height: 26px; border-radius: 8px;
655
874
  display: grid; place-items: center;
@@ -1373,6 +1592,14 @@ window.__ModuleLoader__.load({
1373
1592
  .mesh-mini-row:first-child { border-top: 0; padding-top: 0; }
1374
1593
  .mesh-mini-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
1375
1594
  .mesh-mini-meta { flex: 0 0 auto; font-size: 10.5px; color: var(--mesh-muted); }
1595
+ .mesh-mini-actions { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; }
1596
+ .mesh-mini-act {
1597
+ width: 28px; height: 28px; display: grid; place-items: center;
1598
+ border: 1px solid var(--mesh-line); border-radius: 7px;
1599
+ background: var(--mesh-surface); color: var(--mesh-muted); cursor: pointer;
1600
+ }
1601
+ .mesh-mini-act:active:not(:disabled) { transform: scale(0.95); }
1602
+ .mesh-mini-act:disabled { opacity: .4; cursor: not-allowed; }
1376
1603
  .mesh-home-hidden {
1377
1604
  margin-top: 18px; padding-top: 14px;
1378
1605
  border-top: 1px solid var(--mesh-line);
@@ -1483,6 +1710,21 @@ window.__ModuleLoader__.load({
1483
1710
  .mesh-editor-error { margin: 8px 0; font-size: 11.5px; color: var(--mesh-err); }
1484
1711
  .mesh-editor-foot { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
1485
1712
  .mesh-card-text.is-pre { white-space: pre-wrap; }
1713
+ /* 主页页头的轻入口:只有文字,没有边框/底色,和「专注」「自定义」同一行 */
1714
+ .mesh-home-meta { display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; }
1715
+ .mesh-meta-link {
1716
+ appearance: none; -webkit-appearance: none;
1717
+ border: 0; background: none; padding: 2px 0; margin: 0;
1718
+ font: inherit; font-size: 11px; line-height: 1.5;
1719
+ color: var(--mesh-muted); cursor: pointer;
1720
+ text-decoration: none; white-space: nowrap;
1721
+ transition: color var(--mesh-dur-fast) ease;
1722
+ }
1723
+ .mesh-meta-link:hover { color: var(--mesh-accent); text-decoration: underline; text-underline-offset: 2px; }
1724
+ .mesh-meta-link:focus-visible { outline: 2px solid var(--mesh-accent); outline-offset: 2px; border-radius: 4px; }
1725
+ .mesh-meta-link:disabled { cursor: default; opacity: .6; }
1726
+ .mesh-meta-link.is-update { color: var(--mesh-accent); font-weight: 600; }
1727
+ .mesh-meta-link.is-warn { color: var(--mesh-warn); }
1486
1728
  .mesh-card-link { color: var(--mesh-accent); text-decoration: none; }
1487
1729
  .mesh-card-link:hover { text-decoration: underline; }
1488
1730
  .mesh-focus .mesh-dot.is-ok::after,
@@ -1767,6 +2009,7 @@ window.__ModuleLoader__.load({
1767
2009
  gap: 8px;
1768
2010
  }
1769
2011
  .mesh-brand { order: 1; }
2012
+ .mesh-panel-back { order: 0; height: 28px; padding: 0 8px 0 6px; font-size: 11.5px; }
1770
2013
  .mesh-topright { order: 2; }
1771
2014
  .mesh-tabs { order: 3; flex: 0 0 100%; width: 100%; }
1772
2015
  .mesh-tab { flex: 1 1 0; justify-content: center; padding: 7px 6px; }
@@ -1838,6 +2081,7 @@ window.__ModuleLoader__.load({
1838
2081
  .mesh-task-row {
1839
2082
  touch-action: manipulation;
1840
2083
  }
2084
+ .mesh-panel-back { touch-action: manipulation; }
1841
2085
  .mesh-tab { min-height: 44px; }
1842
2086
  .mesh-btn,
1843
2087
  .mesh-btn--sm,
@@ -2289,6 +2533,8 @@ window.__ModuleLoader__.load({
2289
2533
  ];
2290
2534
  case "chevron":
2291
2535
  return [h("path", { key: "a", d: "M9 6l6 6-6 6" })];
2536
+ case "back":
2537
+ return [h("path", { key: "a", d: "M15 6l-6 6 6 6" })];
2292
2538
  case "close":
2293
2539
  return [
2294
2540
  h("path", { key: "a", d: "M6 6l12 12" }),
@@ -2369,6 +2615,25 @@ window.__ModuleLoader__.load({
2369
2615
  }
2370
2616
  }
2371
2617
 
2618
+ const DSHPATH =
2619
+ "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";
2620
+
2621
+ /** DSH 官方图标(来自 dist/favicon.svg 的单条 path),颜色跟随 currentColor。 */
2622
+ function DshMark({ size }) {
2623
+ return h(
2624
+ "svg",
2625
+ {
2626
+ width: size || 16,
2627
+ height: size || 16,
2628
+ viewBox: "0 0 50 50",
2629
+ fill: "none",
2630
+ "aria-hidden": "true",
2631
+ focusable: "false",
2632
+ },
2633
+ h("path", { d: DSHPATH, fill: "currentColor" }),
2634
+ );
2635
+ }
2636
+
2372
2637
  function Icon({ name, size, stroke, className }) {
2373
2638
  return h(
2374
2639
  "svg",
@@ -2407,7 +2672,7 @@ window.__ModuleLoader__.load({
2407
2672
  );
2408
2673
  }
2409
2674
 
2410
- function IconButton({ icon, label, onClick, disabled, loading, active, badge }) {
2675
+ function IconButton({ icon, iconNode, label, onClick, disabled, loading, active, badge }) {
2411
2676
  return h(
2412
2677
  "button",
2413
2678
  {
@@ -2419,7 +2684,7 @@ window.__ModuleLoader__.load({
2419
2684
  "aria-label": label,
2420
2685
  "aria-pressed": active === undefined ? undefined : !!active,
2421
2686
  },
2422
- loading ? h("span", { className: "mesh-spinner" }) : h(Icon, { name: icon, size: 15 }),
2687
+ loading ? h("span", { className: "mesh-spinner" }) : iconNode || h(Icon, { name: icon, size: 15 }),
2423
2688
  badge ? h("span", { className: "mesh-icon-badge" }, badge > 9 ? "9+" : String(badge)) : null,
2424
2689
  );
2425
2690
  }
@@ -2897,16 +3162,28 @@ window.__ModuleLoader__.load({
2897
3162
  );
2898
3163
  }
2899
3164
 
2900
- function DeviceRow({ peer, isSelf, active, onSelect, now, index }) {
3165
+ function DeviceRow({ peer, isSelf, active, onSelect, onWeb, onSsh, now, index }) {
2901
3166
  const online = !!peer.online || !!isSelf;
2902
3167
  const name = peer.machine || "未命名设备";
3168
+ const webUrl = isSelf ? "" : dshWebUrl(peer);
3169
+ const select = () => onSelect(peer.id);
2903
3170
  return h(
2904
- "button",
3171
+ "div",
2905
3172
  {
2906
- type: "button",
3173
+ role: "button",
3174
+ tabIndex: 0,
2907
3175
  className: cls("mesh-row", active && "is-active", !online && "is-offline"),
2908
- onClick: () => onSelect(peer.id),
3176
+ onClick: select,
3177
+ onKeyDown: (event) => {
3178
+ // 只处理落在行本身上的回车/空格;行内按钮自己处理自己的键盘事件。
3179
+ if (event.target !== event.currentTarget) return;
3180
+ if (event.key === "Enter" || event.key === " " || event.key === "Spacebar") {
3181
+ event.preventDefault();
3182
+ select();
3183
+ }
3184
+ },
2909
3185
  "aria-label": `${name},${online ? "在线" : "离线"}`,
3186
+ "aria-pressed": !!active,
2910
3187
  "data-mesh-view": "devices",
2911
3188
  "data-mesh-peer": peer.machine || "",
2912
3189
  "data-mesh-instance": peer.instanceId || peer.id || "",
@@ -2932,11 +3209,40 @@ window.__ModuleLoader__.load({
2932
3209
  h("span", null, isSelf ? "现在" : ago(peer.lastSeen, now)),
2933
3210
  ),
2934
3211
  ),
2935
- h("span", { className: "mesh-row-side" }, h(Icon, { name: "chevron", size: 13 })),
3212
+ h(
3213
+ "span",
3214
+ { className: "mesh-row-side" },
3215
+ // 「访问 DSH Web」:不选中设备,直接在对端的 DSH Web 上开一个页面。
3216
+ webUrl && onWeb
3217
+ ? h(IconButton, {
3218
+ // 用 DSH 官方 logo 而不是地球:这一格代表的是"那台机器上的 DSH"
3219
+ iconNode: h(DshMark, { size: 14 }),
3220
+ label: `访问 ${name} 的 DSH Web(${webUrl})`,
3221
+ disabled: !online,
3222
+ onClick: (event) => {
3223
+ event.stopPropagation();
3224
+ onWeb(peer);
3225
+ },
3226
+ })
3227
+ : null,
3228
+ // SSH 终端:与「访问 DSH Web」同一位置,连的是对端 22 端口
3229
+ !isSelf && onSsh
3230
+ ? h(IconButton, {
3231
+ icon: "terminal",
3232
+ label: `SSH 连接到 ${name}`,
3233
+ disabled: !online,
3234
+ onClick: (event) => {
3235
+ event.stopPropagation();
3236
+ onSsh(peer);
3237
+ },
3238
+ })
3239
+ : null,
3240
+ h(Icon, { name: "chevron", size: 13 }),
3241
+ ),
2936
3242
  );
2937
3243
  }
2938
3244
 
2939
- function DeviceList({ selfPeer, peers, selectedId, onSelect, now, lastOk, onScan, scanning }) {
3245
+ function DeviceList({ selfPeer, peers, selectedId, onSelect, onWeb, onSsh, now, lastOk, onScan, scanning }) {
2940
3246
  return h(
2941
3247
  "aside",
2942
3248
  { className: "mesh-list-pane" },
@@ -2957,12 +3263,12 @@ window.__ModuleLoader__.load({
2957
3263
  react.Fragment,
2958
3264
  null,
2959
3265
  h("div", { className: "mesh-list-heading" }, "本机"),
2960
- h(DeviceRow, { peer: selfPeer, isSelf: true, active: selectedId === "self", onSelect, now, index: 0 }),
3266
+ h(DeviceRow, { peer: selfPeer, isSelf: true, active: selectedId === "self", onSelect, onWeb, onSsh, now, index: 0 }),
2961
3267
  )
2962
3268
  : null,
2963
3269
  h("div", { className: "mesh-list-heading" }, "其他设备"),
2964
3270
  peers.length
2965
- ? peers.map((p, i) => h(DeviceRow, { key: p.id, peer: p, active: selectedId === p.id, onSelect, now, index: i + 1 }))
3271
+ ? peers.map((p, i) => h(DeviceRow, { key: p.id, peer: p, active: selectedId === p.id, onSelect, onWeb, onSsh, now, index: i + 1 }))
2966
3272
  : h("div", { className: "mesh-list-empty" }, "还没有发现其他设备。点下面探测一次本网段。"),
2967
3273
  h(
2968
3274
  "div",
@@ -3140,7 +3446,7 @@ window.__ModuleLoader__.load({
3140
3446
  }
3141
3447
 
3142
3448
  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;
3449
+ 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
3450
  return h(
3145
3451
  react.Fragment,
3146
3452
  null,
@@ -3148,7 +3454,7 @@ window.__ModuleLoader__.load({
3148
3454
  h(
3149
3455
  "div",
3150
3456
  { className: "mesh-split", "data-pane": mobilePane },
3151
- h(DeviceList, { selfPeer, peers, selectedId, onSelect, now, lastOk, onScan, scanning }),
3457
+ h(DeviceList, { selfPeer, peers, selectedId, onSelect, onWeb, onSsh, now, lastOk, onScan, scanning }),
3152
3458
  h(DeviceDetail, { peer: selectedPeer, isSelf: selectedId === "self", onCompose, onProbe, probe, hostDown, now, onBack, onRename, onScan, recentTasks, onOpenTask, onAllTasks }),
3153
3459
  ),
3154
3460
  );
@@ -3631,6 +3937,302 @@ window.__ModuleLoader__.load({
3631
3937
  );
3632
3938
  }
3633
3939
 
3940
+ /**
3941
+ * 对端 DSH Web 的应用内面板。
3942
+ *
3943
+ * 承载方式是同源 iframe —— 指向**本机**的一个回环反代端口(宿主的
3944
+ * /mesh/api/web-panel 起出来的),对端认证在服务端完成。所以这里不需要
3945
+ * token、不依赖壳的浏览器 WebView,也不受对端 cookie SameSite 限制。
3946
+ */
3947
+ function WebPanel({ panel, onClose, onReload }) {
3948
+ if (!panel) return null;
3949
+ const ready = panel.state === "ready";
3950
+ const name = panel.name || "对端";
3951
+ return h(
3952
+ "div",
3953
+ {
3954
+ className: "mesh-web-layer",
3955
+ role: "dialog",
3956
+ "aria-modal": "true",
3957
+ "aria-label": `${name} 的 DSH Web`,
3958
+ "data-mesh-view": "web",
3959
+ },
3960
+ h(
3961
+ "div",
3962
+ { className: "mesh-web-bar" },
3963
+ h(
3964
+ "button",
3965
+ { type: "button", className: "mesh-panel-back", onClick: onClose, "aria-label": "关闭面板" },
3966
+ h(Icon, { name: "back", size: 14 }),
3967
+ h("span", null, "返回"),
3968
+ ),
3969
+ h("span", { className: "mesh-web-mark", "aria-hidden": "true" }, h(DshMark, { size: 16 })),
3970
+ h(
3971
+ "span",
3972
+ { className: "mesh-web-title", title: panel.remote || "" },
3973
+ name,
3974
+ h("span", { className: "mesh-web-sub" }, " · DSH Web"),
3975
+ ),
3976
+ h(IconButton, { icon: "refresh", label: "重新加载面板", onClick: onReload }),
3977
+ ),
3978
+ !ready
3979
+ ? h(
3980
+ "div",
3981
+ { className: "mesh-web-status" },
3982
+ h("span", { className: "mesh-spinner" }),
3983
+ h("span", null, "正在起回环代理…"),
3984
+ )
3985
+ : null,
3986
+ ready && panel.hasSession === false
3987
+ ? h(
3988
+ "div",
3989
+ { className: "mesh-web-status is-warn" },
3990
+ h(Icon, { name: "alert", size: 14 }),
3991
+ h("span", null, panel.note || "对端没给出可用 token,面板可能停在登录页。"),
3992
+ )
3993
+ : null,
3994
+ ready
3995
+ ? h("iframe", {
3996
+ key: panel.reloadKey || 0,
3997
+ className: "mesh-web-frame",
3998
+ src: panel.url,
3999
+ title: `${name} 的 DSH Web`,
4000
+ // 对端界面里要用剪贴板(复制命令/日志),别让它被静默拒绝。
4001
+ allow: "clipboard-read; clipboard-write; fullscreen",
4002
+ referrerPolicy: "no-referrer",
4003
+ })
4004
+ : null,
4005
+ );
4006
+ }
4007
+
4008
+
4009
+ /** 去掉终端控制序列:没有 xterm 时,把 ANSI 转义剥掉才不会满屏乱码。 */
4010
+ function stripAnsi(text) {
4011
+ return String(text)
4012
+ .replace(/\u001b\][^\u0007]*\u0007/g, "")
4013
+ .replace(/\u001b\[[0-9;?]*[ -/]*[@-~]/g, "")
4014
+ .replace(/\r(?!\n)/g, "");
4015
+ }
4016
+
4017
+ /**
4018
+ * 应用内 SSH 终端。
4019
+ *
4020
+ * 传输走同源 WebSocket(/mesh/api/ssh/ws),SSH 本身由本机宿主发起;
4021
+ * 这里只是个"哑终端":输出按行渲染、输入整行发送,另给 Ctrl+C / Tab 两个键。
4022
+ * 没做完整 VT100(没有 xterm 依赖),够用来跑命令、看日志。
4023
+ */
4024
+ function SshPanel({ peer, onClose }) {
4025
+ const machine = (peer && peer.machine) || "";
4026
+ const [phase, setPhase] = react.useState("form");
4027
+ const [username, setUsername] = react.useState("");
4028
+ const [password, setPassword] = react.useState("");
4029
+ const [hasKey, setHasKey] = react.useState(false);
4030
+ // 密钥属于哪个用户名:换了用户名就不能再拿它去认证(否则只会得到认证失败)
4031
+ const [keyUser, setKeyUser] = react.useState("");
4032
+ // 密钥失效时不至于卡死:允许手动切回密码登录
4033
+ const [forcePassword, setForcePassword] = react.useState(false);
4034
+ const [output, setOutput] = react.useState("");
4035
+ const [line, setLine] = react.useState("");
4036
+ const [error, setError] = react.useState("");
4037
+ const wsRef = react.useRef(null);
4038
+ const idRef = react.useRef("");
4039
+ const outRef = react.useRef(null);
4040
+
4041
+ react.useEffect(() => {
4042
+ let alive = true;
4043
+ api("/ssh/known", { machine })
4044
+ .then((r) => {
4045
+ if (!alive || !r || !r.ok) return;
4046
+ if (r.username) {
4047
+ setUsername(r.username);
4048
+ setKeyUser(r.username);
4049
+ }
4050
+ if (r.hasKey) setHasKey(true);
4051
+ })
4052
+ .catch(() => {});
4053
+ return () => {
4054
+ alive = false;
4055
+ };
4056
+ }, [machine]);
4057
+
4058
+ react.useEffect(() => {
4059
+ const el = outRef.current;
4060
+ if (el) el.scrollTop = el.scrollHeight;
4061
+ }, [output]);
4062
+
4063
+ const closeSocket = () => {
4064
+ try {
4065
+ wsRef.current?.close();
4066
+ } catch {
4067
+ /* 已关 */
4068
+ }
4069
+ wsRef.current = null;
4070
+ idRef.current = "";
4071
+ };
4072
+
4073
+ react.useEffect(() => () => closeSocket(), []);
4074
+
4075
+ const connect = () => {
4076
+ setError("");
4077
+ setOutput("");
4078
+ setPhase("connecting");
4079
+ const scheme = location.protocol === "https:" ? "wss" : "ws";
4080
+ let ws;
4081
+ try {
4082
+ ws = new WebSocket(`${scheme}://${location.host}/mesh/api/ssh/ws`);
4083
+ } catch (e) {
4084
+ setError(String(e && e.message ? e.message : e));
4085
+ setPhase("error");
4086
+ return;
4087
+ }
4088
+ wsRef.current = ws;
4089
+ ws.onopen = () => {
4090
+ ws.send(
4091
+ JSON.stringify({
4092
+ type: "open",
4093
+ machine,
4094
+ host: peer.host || "",
4095
+ port: 22,
4096
+ username: username.trim(),
4097
+ password: keyApplies && !forcePassword ? "" : password,
4098
+ cols: 100,
4099
+ rows: 30,
4100
+ }),
4101
+ );
4102
+ };
4103
+ ws.onmessage = (event) => {
4104
+ let msg;
4105
+ try {
4106
+ msg = JSON.parse(event.data);
4107
+ } catch {
4108
+ return;
4109
+ }
4110
+ if (msg.type === "ready") {
4111
+ idRef.current = msg.id;
4112
+ setPhase("open");
4113
+ if (msg.buffer) setOutput(stripAnsi(msg.buffer));
4114
+ return;
4115
+ }
4116
+ if (msg.type === "data") {
4117
+ setOutput((prev) => (prev + stripAnsi(msg.data)).slice(-200000));
4118
+ return;
4119
+ }
4120
+ if (msg.type === "exit") {
4121
+ setPhase("closed");
4122
+ return;
4123
+ }
4124
+ if (msg.type === "error") {
4125
+ setError(String(msg.message || "未知错误"));
4126
+ setPhase("error");
4127
+ }
4128
+ };
4129
+ ws.onerror = () => {
4130
+ setError("连接通道错误(WebSocket)");
4131
+ setPhase("error");
4132
+ };
4133
+ ws.onclose = () => {
4134
+ setPhase((prev) => (prev === "error" ? prev : "closed"));
4135
+ };
4136
+ };
4137
+
4138
+ const sendInput = (data) => {
4139
+ const ws = wsRef.current;
4140
+ if (!ws || ws.readyState !== 1 || !idRef.current) return;
4141
+ ws.send(JSON.stringify({ type: "input", id: idRef.current, data }));
4142
+ };
4143
+
4144
+ const submit = (event) => {
4145
+ event.preventDefault();
4146
+ if (!line.trim()) return;
4147
+ sendInput(line + "\r");
4148
+ setLine("");
4149
+ };
4150
+
4151
+ const disconnect = () => {
4152
+ const id = idRef.current;
4153
+ if (id) sendInput.call(null, ""); // 占位,避免 eslint 抱怨
4154
+ try {
4155
+ if (id) wsRef.current?.send(JSON.stringify({ type: "close", id }));
4156
+ } catch {
4157
+ /* 忽略 */
4158
+ }
4159
+ closeSocket();
4160
+ onClose();
4161
+ };
4162
+
4163
+ const keyApplies = hasKey && keyUser !== "" && username.trim() === keyUser;
4164
+ const name = machine || "对端";
4165
+ return h(
4166
+ "div",
4167
+ { className: "mesh-web-layer", role: "dialog", "aria-modal": "true", "aria-label": `${name} 的 SSH 终端` },
4168
+ h(
4169
+ "div",
4170
+ { className: "mesh-web-bar" },
4171
+ h("button", { type: "button", className: "mesh-panel-back", onClick: disconnect }, h(Icon, { name: "back", size: 14 }), h("span", null, "返回")),
4172
+ h("span", { className: "mesh-web-title" }, name, h("span", { className: "mesh-web-sub" }, " · SSH")),
4173
+ phase === "open"
4174
+ ? h(IconButton, { icon: "close", label: "断开连接", onClick: disconnect })
4175
+ : null,
4176
+ ),
4177
+ phase === "form" || phase === "connecting" || phase === "error"
4178
+ ? h(
4179
+ "div",
4180
+ { className: "mesh-ssh-form" },
4181
+ h(
4182
+ "div",
4183
+ { className: "mesh-ssh-note" },
4184
+ keyApplies
4185
+ ? "已部署本机公钥,直接连接即可(免密)。"
4186
+ : hasKey
4187
+ ? `公钥属于 ${keyUser};当前用户名不同,请输入密码。`
4188
+ : "首次连接需要用户名和密码;成功后会自动把本机公钥写到对端,之后免密。",
4189
+ ),
4190
+ h("label", { className: "mesh-ssh-field" }, h("span", null, "用户名"), h("input", { value: username, onChange: (e) => setUsername(e.target.value), autoCapitalize: "none", spellCheck: false })),
4191
+ keyApplies && !forcePassword
4192
+ ? null
4193
+ : h("label", { className: "mesh-ssh-field" }, h("span", null, "密码"), h("input", { type: "password", value: password, onChange: (e) => setPassword(e.target.value) })),
4194
+ keyApplies && !forcePassword && (phase === "error" || phase === "form")
4195
+ ? h(
4196
+ "button",
4197
+ {
4198
+ type: "button",
4199
+ className: "mesh-ssh-key",
4200
+ onClick: () => {
4201
+ setForcePassword(true);
4202
+ setError("");
4203
+ setPhase("form");
4204
+ },
4205
+ },
4206
+ "改用密码连接",
4207
+ )
4208
+ : null,
4209
+ error ? h("div", { className: "mesh-ssh-error" }, error) : null,
4210
+ h(
4211
+ Button,
4212
+ { variant: "primary", onClick: connect, disabled: !username.trim() || phase === "connecting" },
4213
+ phase === "connecting" ? "连接中…" : "连接",
4214
+ ),
4215
+ )
4216
+ : null,
4217
+ phase === "open" || phase === "closed"
4218
+ ? h(
4219
+ react.Fragment,
4220
+ null,
4221
+ h("pre", { className: "mesh-ssh-out", ref: outRef }, output || "已连接,等输出…"),
4222
+ phase === "closed" ? h("div", { className: "mesh-ssh-note" }, "会话已结束") : null,
4223
+ h(
4224
+ "form",
4225
+ { className: "mesh-ssh-inputrow", onSubmit: submit },
4226
+ h("input", { value: line, onChange: (e) => setLine(e.target.value), placeholder: "输入命令,回车执行", autoCapitalize: "none", spellCheck: false }),
4227
+ h("button", { type: "button", className: "mesh-ssh-key", onClick: () => sendInput("\u0003") }, "Ctrl-C"),
4228
+ h("button", { type: "button", className: "mesh-ssh-key", onClick: () => sendInput("\t") }, "Tab"),
4229
+ h("button", { type: "submit", className: "mesh-ssh-send" }, "发送"),
4230
+ ),
4231
+ )
4232
+ : null,
4233
+ );
4234
+ }
4235
+
3634
4236
  function TransferLog({ items, onClose, onRetry, onLocate, onCopy }) {
3635
4237
  return h(
3636
4238
  "div",
@@ -5157,6 +5759,8 @@ window.__ModuleLoader__.load({
5157
5759
  onDevices,
5158
5760
  onTasks,
5159
5761
  onConnect,
5762
+ onWeb,
5763
+ onSsh,
5160
5764
  onScan,
5161
5765
  scanning,
5162
5766
  firstRun,
@@ -5727,6 +6331,185 @@ window.__ModuleLoader__.load({
5727
6331
  );
5728
6332
  }
5729
6333
 
6334
+ // ─────────────────────── 主页 · 问题反馈 / 检查更新(轻入口) ───────────────────────
6335
+
6336
+ /**
6337
+ * 主页页头的两个轻入口:只占一行文字,不占卡片。
6338
+ *
6339
+ * 它们最初是两张卡片,真机上看太占首屏 —— 主页要回答的是"谁在线、能不能
6340
+ * 派活",更新和反馈是偶尔用一次的事。于是收成和「专注」「自定义」同一行的
6341
+ * 两个小字,功能一个不少:
6342
+ * · 问题反馈 → GitHub 新建 Issue(标题/正文预填,带诊断、不含 secret);
6343
+ * · 检查更新 → 查一次 registry;有更新时旁边多出「新版本 vX」,点它复制
6344
+ * 升级命令;失败时多出「检查失败」,点它重试。
6345
+ * 失败**不会**显示成"已是最新":徽标、tooltip、toast 说的都是"没查到"。
6346
+ */
6347
+
6348
+ /** 反馈正文:与「诊断」同一份数据,Issue 链接里预填。 */
6349
+ function feedbackBody(state) {
6350
+ return [
6351
+ "### 发生了什么",
6352
+ "",
6353
+ "<!-- 一句话描述:做了什么、期望什么、实际发生了什么 -->",
6354
+ "",
6355
+ "### 复现步骤",
6356
+ "",
6357
+ "1. ",
6358
+ "",
6359
+ "### 诊断信息(可删掉不想公开的行)",
6360
+ "",
6361
+ "```",
6362
+ buildDiagnostics(state),
6363
+ "```",
6364
+ ].join("\n");
6365
+ }
6366
+
6367
+ function feedbackIssueUrl(state) {
6368
+ const self = (state && state.self) || {};
6369
+ const title = `[反馈] Mesh ${self.version || ""}${self.machine ? ` · ${self.machine}` : ""}`.trim();
6370
+ const params = new URLSearchParams({ title, body: feedbackBody(state) });
6371
+ return `${NEW_ISSUE_URL}?${params.toString()}`;
6372
+ }
6373
+
6374
+ /** 问题反馈:一个链接,直接打开预填好的新建 Issue 页。 */
6375
+ function FeedbackLink({ state }) {
6376
+ return h(
6377
+ "a",
6378
+ {
6379
+ className: "mesh-meta-link",
6380
+ href: feedbackIssueUrl(state),
6381
+ target: "_blank",
6382
+ rel: "noreferrer",
6383
+ title: `在 GitHub 提 Issue(打不开可以邮件 ${FEEDBACK_MAIL})`,
6384
+ },
6385
+ "问题反馈",
6386
+ );
6387
+ }
6388
+
6389
+ /** 检查更新的展示层(纯 props):自测可以直接给三种现场,不用联网。 */
6390
+ function UpdateLinkView({ phase, report, onCheck, onCopy }) {
6391
+ const checking = phase === "checking";
6392
+ const failed = !!report && report.ok !== true;
6393
+ const hasUpdate = !!report && report.ok === true && report.hasUpdate === true;
6394
+ const incomparable = !!report && report.ok === true && report.comparable === false;
6395
+ const label = checking ? "检查中…" : "检查更新";
6396
+ const title = failed
6397
+ ? `上次检查失败:${String(report.error || "未知原因")}(点一下重试)`
6398
+ : incomparable
6399
+ ? `当前 v${report.current} 与 registry 返回的 v${report.latest} 无法比较,点一下重新检查`
6400
+ : hasUpdate
6401
+ ? `当前 v${report.current} → 最新 v${report.latest};点一下重新检查`
6402
+ : "查一下有没有新版本";
6403
+ return h(
6404
+ react.Fragment,
6405
+ null,
6406
+ h(
6407
+ "button",
6408
+ {
6409
+ type: "button",
6410
+ className: cls("mesh-meta-link", checking && "is-busy"),
6411
+ onClick: onCheck,
6412
+ disabled: checking,
6413
+ title,
6414
+ "aria-label": "检查更新",
6415
+ "aria-busy": checking || undefined,
6416
+ },
6417
+ label,
6418
+ ),
6419
+ hasUpdate
6420
+ ? h(
6421
+ "button",
6422
+ {
6423
+ type: "button",
6424
+ className: "mesh-meta-link is-update",
6425
+ onClick: () => onCopy(report.upgradeCommand),
6426
+ title: `复制升级命令(v${report.current} → v${report.latest},装好后重启 DSH)`,
6427
+ "aria-label": `复制升级命令到 v${report.latest}`,
6428
+ },
6429
+ `新版本 v${report.latest}`,
6430
+ )
6431
+ : null,
6432
+ failed
6433
+ ? h(
6434
+ "button",
6435
+ { type: "button", className: "mesh-meta-link is-warn", onClick: onCheck, title: report.error },
6436
+ "检查失败",
6437
+ )
6438
+ : null,
6439
+ incomparable
6440
+ ? h(
6441
+ "button",
6442
+ { type: "button", className: "mesh-meta-link is-warn", onClick: onCheck, title },
6443
+ "无法比较",
6444
+ )
6445
+ : null,
6446
+ );
6447
+ }
6448
+
6449
+ /**
6450
+ * 检查更新的容器:进主页**静默**查一次(宿主机缓存 30 分钟),点一下强查。
6451
+ * 静默失败也会在页头留下「检查失败」—— 不点也看得见"没问到",而不是假装无事。
6452
+ */
6453
+ function UpdateLink({ push }) {
6454
+ const [phase, setPhase] = react.useState("idle");
6455
+ const [report, setReport] = react.useState(null);
6456
+ const alive = react.useRef(true);
6457
+ const copyCommand = react.useCallback(
6458
+ async (text) => {
6459
+ if (!text) {
6460
+ push("error", "这次结果里没有升级命令,请先重新检查");
6461
+ return;
6462
+ }
6463
+ const ok = await copyText(text);
6464
+ push(ok ? "success" : "error", ok ? "升级命令已复制:装好后重启 DSH 生效" : "复制失败,请手动选择");
6465
+ },
6466
+ [push],
6467
+ );
6468
+ const run = react.useCallback(
6469
+ async (force, announce) => {
6470
+ setPhase("checking");
6471
+ try {
6472
+ const r = await apiGet(`/update${force ? "?force=1" : ""}`);
6473
+ if (!alive.current) return;
6474
+ const next = r && typeof r === "object" ? r : { ok: false, error: "主机没有返回结果" };
6475
+ setReport(next);
6476
+ setPhase("done");
6477
+ if (!announce) return;
6478
+ if (next.ok !== true) {
6479
+ push("error", `没查到最新版本:${String(next.error || "未知原因")}`);
6480
+ } else if (next.comparable === false) {
6481
+ push("error", `版本号无法比较:v${next.current} vs v${next.latest},请到 Release 页面确认`);
6482
+ } else if (next.hasUpdate) {
6483
+ push("success", `有新版本 v${next.latest}(当前 v${next.current})`, {
6484
+ label: "复制升级命令",
6485
+ onClick: () => copyCommand(next.upgradeCommand),
6486
+ });
6487
+ } else {
6488
+ push("success", `已是最新(v${next.current})`);
6489
+ }
6490
+ } catch (e) {
6491
+ if (!alive.current) return;
6492
+ setReport({ ok: false, error: String((e && e.message) || e) });
6493
+ setPhase("done");
6494
+ if (announce) push("error", `没查到最新版本:${String((e && e.message) || e)}`);
6495
+ }
6496
+ },
6497
+ [push, copyCommand],
6498
+ );
6499
+ react.useEffect(() => {
6500
+ alive.current = true;
6501
+ run(false, false);
6502
+ return () => {
6503
+ alive.current = false;
6504
+ };
6505
+ }, [run]);
6506
+ return h(UpdateLinkView, { phase, report, onCheck: () => run(true, true), onCopy: copyCommand });
6507
+ }
6508
+
6509
+ function HomeMetaLinks({ state, push }) {
6510
+ return h("div", { className: "mesh-home-meta" }, h(FeedbackLink, { state }), h(UpdateLink, { push }));
6511
+ }
6512
+
5730
6513
  // ─────────────────────── 主页 · 派发任务 ───────────────────────
5731
6514
 
5732
6515
  /**
@@ -5907,6 +6690,8 @@ window.__ModuleLoader__.load({
5907
6690
  onDevices,
5908
6691
  onTasks,
5909
6692
  onConnect,
6693
+ onWeb,
6694
+ onSsh,
5910
6695
  onScan,
5911
6696
  scanning,
5912
6697
  firstRun,
@@ -6075,6 +6860,39 @@ window.__ModuleLoader__.load({
6075
6860
  h(Dot, { kind: p.online ? "ok" : "idle" }),
6076
6861
  h("span", { className: "mesh-mini-name" }, p.machine || "未命名设备"),
6077
6862
  h("span", { className: "mesh-mini-meta" }, p.online ? `在线 · ${osLabel(p.os)}` : `${ago(p.lastSeen, now)}`),
6863
+ // 与「设备」页同一组入口:访问 DSH Web / SSH 终端
6864
+ h(
6865
+ "span",
6866
+ { className: "mesh-mini-actions" },
6867
+ onWeb
6868
+ ? h(
6869
+ "button",
6870
+ {
6871
+ type: "button",
6872
+ className: "mesh-mini-act",
6873
+ title: `访问 ${p.machine || "对端"} 的 DSH Web`,
6874
+ "aria-label": `访问 ${p.machine || "对端"} 的 DSH Web`,
6875
+ disabled: !p.online,
6876
+ onClick: () => onWeb(p),
6877
+ },
6878
+ h(DshMark, { size: 14 }),
6879
+ )
6880
+ : null,
6881
+ onSsh
6882
+ ? h(
6883
+ "button",
6884
+ {
6885
+ type: "button",
6886
+ className: "mesh-mini-act",
6887
+ title: `SSH 连接到 ${p.machine || "对端"}`,
6888
+ "aria-label": `SSH 连接到 ${p.machine || "对端"}`,
6889
+ disabled: !p.online,
6890
+ onClick: () => onSsh(p),
6891
+ },
6892
+ h(Icon, { name: "terminal", size: 14 }),
6893
+ )
6894
+ : null,
6895
+ ),
6078
6896
  ),
6079
6897
  )
6080
6898
  : h("p", { className: "mesh-card-text" }, "还没有发现其他设备。扫描本网段,或让对方也打开 Mesh。");
@@ -6307,6 +7125,7 @@ window.__ModuleLoader__.load({
6307
7125
  ? h(Button, { variant: "primary", size: "sm", icon: "check", onClick: () => setEditing(false) }, "完成")
6308
7126
  : h(Button, { variant: "secondary", size: "sm", icon: "edit", onClick: () => setEditing(true) }, "自定义"),
6309
7127
  editing ? h(Button, { variant: "ghost", size: "sm", onClick: onReset }, "恢复默认") : null,
7128
+ h(HomeMetaLinks, { state, push }),
6310
7129
  ),
6311
7130
  ),
6312
7131
  h(
@@ -6441,7 +7260,7 @@ window.__ModuleLoader__.load({
6441
7260
 
6442
7261
  // ─────────────────────── 工作台外壳 ───────────────────────
6443
7262
 
6444
- function TopBar({ view, onView, online, total, taskCount, error, lastOk, now, refreshing, onRefresh, scanning, onScan, disabled, busy, focus, onToggleFocus, onTransfer, transferActive, onLog, transferCount }) {
7263
+ function TopBar({ view, onView, online, total, taskCount, error, lastOk, now, refreshing, onRefresh, scanning, onScan, disabled, busy, focus, onToggleFocus, onTransfer, transferActive, onLog, transferCount, onExit }) {
6445
7264
  const tabs = [
6446
7265
  { value: "home", label: "主页", icon: "home" },
6447
7266
  { value: "devices", label: "设备", icon: "device", count: total },
@@ -6453,6 +7272,23 @@ window.__ModuleLoader__.load({
6453
7272
  return h(
6454
7273
  "header",
6455
7274
  { className: "mesh-topbar", "aria-busy": !!busy },
7275
+ // 主面板是"点进去出不来"的:宿主只在插件管理页注入返回键,Mesh 这个
7276
+ // 主面板没有,窄屏上连侧边栏都被抽屉挡住。这里自带一个,直接回到会话。
7277
+ onExit
7278
+ ? h(
7279
+ "button",
7280
+ {
7281
+ type: "button",
7282
+ className: "mesh-panel-back",
7283
+ onClick: onExit,
7284
+ title: "返回会话(退出 Mesh 面板)",
7285
+ "aria-label": "返回会话",
7286
+ "data-mesh-view": "back",
7287
+ },
7288
+ h(Icon, { name: "back", size: 14 }),
7289
+ h("span", { className: "mesh-panel-back-text" }, "返回"),
7290
+ )
7291
+ : null,
6456
7292
  h(
6457
7293
  "div",
6458
7294
  { className: "mesh-brand" },
@@ -6579,6 +7415,10 @@ window.__ModuleLoader__.load({
6579
7415
  const [taskFilter, setTaskFilter] = react.useState("all");
6580
7416
  const [composer, setComposer] = react.useState(null);
6581
7417
  const [probe, setProbe] = react.useState(null);
7418
+ // 对端 DSH Web 的应用内面板:{ peer, name, state: loading|ready, url, note, hasSession, reloadKey }
7419
+ const [webPanel, setWebPanel] = react.useState(null);
7420
+ // SSH 终端面板:null 或某个 peer
7421
+ const [sshPeer, setSshPeer] = react.useState(null);
6582
7422
  const [scanning, setScanning] = react.useState(false);
6583
7423
  const [nameBusy, setNameBusy] = react.useState(false);
6584
7424
  const [nameDismissed, setNameDismissed] = react.useState(false);
@@ -6771,7 +7611,110 @@ window.__ModuleLoader__.load({
6771
7611
  };
6772
7612
 
6773
7613
  /**
6774
- * 派发成功的统一收尾:toast + 让轮询立刻刷新。
7614
+ * 打开对端的 DSH Web。
7615
+ *
7616
+ * 主路是**应用内面板**:宿主起一个回环反代(认证在服务端做),这里只
7617
+ * 把它的地址塞进同源 iframe —— 不依赖壳的浏览器 WebView(本机没有),
7618
+ * 也不受对端 cookie 的 SameSite=Strict 影响。
7619
+ * 反代起不来时才退回老的"浏览器页签 / 外部浏览器"那条链。
7620
+ */
7621
+ const openWeb = async (peer) => {
7622
+ const name = (peer && peer.machine) || "对端";
7623
+ setWebPanel({ peer, name, state: "loading", reloadKey: 0 });
7624
+ try {
7625
+ const r = await api("/web-panel", { peer: (peer && (peer.machine || peer.id)) || "" });
7626
+ if (r && r.ok === true && typeof r.url === "string") {
7627
+ setWebPanel((prev) => ({
7628
+ ...(prev || { peer, name }),
7629
+ state: "ready",
7630
+ url: r.url,
7631
+ remote: r.remote || "",
7632
+ hasSession: r.hasSession !== false,
7633
+ note: r.note || "",
7634
+ reloadKey: 0,
7635
+ }));
7636
+ if (r.hasSession === false) {
7637
+ push("warn", `${name} 那边没给出可用 token,面板可能停在登录页。`);
7638
+ }
7639
+ return;
7640
+ }
7641
+ setWebPanel(null);
7642
+ push("warn", `应用内面板起不来(${(r && r.error) || "未知原因"}),改用外部方式打开。`);
7643
+ } catch (error) {
7644
+ setWebPanel(null);
7645
+ push("warn", `应用内面板起不来(${String((error && error.message) || error)}),改用外部方式打开。`);
7646
+ }
7647
+
7648
+ let result;
7649
+ try {
7650
+ result = await openDshWebPage(peer);
7651
+ } catch (error) {
7652
+ push("error", `打不开 ${name} 的 Web:${String((error && error.message) || error)}`);
7653
+ return;
7654
+ }
7655
+ if (!result.ok) {
7656
+ push("error", `打不开 ${name} 的 Web:${result.reason || "未知原因"}`);
7657
+ return;
7658
+ }
7659
+ if (result.lanReachable === false) {
7660
+ push("warn", `${name} 只监听 127.0.0.1,手机连不通;在那边把 webserver.host 改成 0.0.0.0 再重启。`);
7661
+ return;
7662
+ }
7663
+ if (result.browserUnavailable) {
7664
+ push("warn", `这台壳没有可用的浏览器 WebView,已改用外部浏览器打开 ${result.url}`);
7665
+ return;
7666
+ }
7667
+ if (result.how === "browser" && result.viaHost) {
7668
+ push("success", `已打开 ${result.url}`);
7669
+ return;
7670
+ }
7671
+ if (result.how === "browser") {
7672
+ push("info", `已打开 ${result.url}`);
7673
+ return;
7674
+ }
7675
+ push("info", `应用内浏览器不可用,已用外部浏览器打开 ${result.url}`);
7676
+ };
7677
+
7678
+ /**
7679
+ * 回到会话:上游 layout.selectPanel(null)。
7680
+ *
7681
+ * 宿主(Android 壳)只会给**插件管理页**注入返回键,任何其它主面板都得
7682
+ * 自己带出口——否则窄屏上点进 Mesh 就只剩浏览器的返回手势。
7683
+ */
7684
+ const leavePanel = () => {
7685
+ try {
7686
+ const layout = (pluginCtx && pluginCtx.get ? pluginCtx.get("layout") : null) || null;
7687
+ if (layout && typeof layout.selectPanel === "function") {
7688
+ layout.selectPanel(null);
7689
+ return;
7690
+ }
7691
+ } catch (error) {
7692
+ // 落到下面的兜底提示,不要静默失效
7693
+ }
7694
+ push("warn", "当前宿主没有 layout 服务,无法自动回到会话;用侧边栏切回对话即可。");
7695
+ };
7696
+
7697
+ /**
7698
+ * 关掉对端 Web 面板:先卸载前端这一层,再尽力让宿主把反代也停掉
7699
+ * (停不掉只是多一个回环端口,不影响正确性)。
7700
+ */
7701
+ const closeWebPanel = () => {
7702
+ const machine = webPanel && webPanel.peer ? webPanel.peer.machine || webPanel.peer.id || "" : "";
7703
+ setWebPanel(null);
7704
+ if (!machine) return;
7705
+ api("/web-panel/close", { peer: machine }).catch(() => {
7706
+ /* 关闭是尽力而为 */
7707
+ });
7708
+ };
7709
+
7710
+ /** 重新拉起面板(对端重启过、或 iframe 白屏时用)。 */
7711
+ const reloadWebPanel = () => {
7712
+ const peer = webPanel && webPanel.peer;
7713
+ if (!peer) return;
7714
+ void openWeb(peer);
7715
+ };
7716
+
7717
+ /** 派发成功的统一收尾:toast + 让轮询立刻刷新。
6775
7718
  * 设备页弹层和主页的派发面板共用它,免得两处提示文案慢慢走散。
6776
7719
  */
6777
7720
  const notifyDispatched = (name, r) => {
@@ -6944,6 +7887,7 @@ window.__ModuleLoader__.load({
6944
7887
  transferActive: false,
6945
7888
  onLog: () => setTransferLogOpen(true),
6946
7889
  transferCount: transfers.length,
7890
+ onExit: leavePanel,
6947
7891
  }),
6948
7892
  loading ? h(LoadingView) : h(ErrorView, { error, onRetry: reload, onCopy: () => copy(error) }),
6949
7893
  );
@@ -6982,6 +7926,7 @@ window.__ModuleLoader__.load({
6982
7926
  setTransferLogOpen(true);
6983
7927
  },
6984
7928
  transferCount: transfers.filter((item) => item.status === "sent" || item.status === "delivered").length,
7929
+ onExit: leavePanel,
6985
7930
  }),
6986
7931
  error
6987
7932
  ? h(Banner, {
@@ -7049,6 +7994,8 @@ window.__ModuleLoader__.load({
7049
7994
  onDevices: goDevices,
7050
7995
  onTasks: goTasks,
7051
7996
  onConnect: openConnect,
7997
+ onWeb: openWeb,
7998
+ onSsh: (peer) => setSshPeer(peer),
7052
7999
  onScan: doScan,
7053
8000
  scanning,
7054
8001
  firstRun: firstRunNode,
@@ -7064,6 +8011,8 @@ window.__ModuleLoader__.load({
7064
8011
  selectedPeer,
7065
8012
  selectedId,
7066
8013
  onSelect: selectPeer,
8014
+ onWeb: openWeb,
8015
+ onSsh: (peer) => setSshPeer(peer),
7067
8016
  mobilePane,
7068
8017
  onBack: () => setMobilePane("list"),
7069
8018
  onCompose: openComposer,
@@ -7140,6 +8089,8 @@ window.__ModuleLoader__.load({
7140
8089
  onCopy: copyTransfer,
7141
8090
  })
7142
8091
  : null,
8092
+ h(WebPanel, { panel: webPanel, onClose: closeWebPanel, onReload: reloadWebPanel }),
8093
+ sshPeer ? h(SshPanel, { peer: sshPeer, onClose: () => setSshPeer(null) }) : null,
7143
8094
  h(Toasts, { items: toasts, onClose: close }),
7144
8095
  );
7145
8096
  }
@@ -7193,6 +8144,10 @@ window.__ModuleLoader__.load({
7193
8144
  TasksView,
7194
8145
  DeviceDetail,
7195
8146
  DeviceRow,
8147
+ dshWebUrl,
8148
+ resolveWebUrl,
8149
+ openDshWebPage,
8150
+ WebPanel,
7196
8151
  CapabilityChips,
7197
8152
  TaskRow,
7198
8153
  TaskDetail,
@@ -7218,7 +8173,15 @@ window.__ModuleLoader__.load({
7218
8173
  SwitchBody,
7219
8174
  SwitchRow,
7220
8175
  HomeSwitchBar,
8176
+ HomeMetaLinks,
8177
+ UpdateLink,
8178
+ UpdateLinkView,
8179
+ FeedbackLink,
8180
+ feedbackBody,
8181
+ feedbackIssueUrl,
7221
8182
  };
7222
8183
  return module.exports;
7223
8184
  },
7224
8185
  });
8186
+ ;
8187
+ //# sourceMappingURL=??dsh-plugin-mesh/client.js.map&rev=81fe4f4a3488