dsh-plugin-mesh 0.5.2 → 0.5.4

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
@@ -136,6 +136,42 @@ window.__ModuleLoader__.load({
136
136
  return String(os).split(/\s+/)[0];
137
137
  }
138
138
 
139
+ /** 结构化系统身份:新对端有 osInfo,老对端只有 os 字符串,回退解析。 */
140
+ function osInfoLabel(peer) {
141
+ const info = peer && peer.osInfo;
142
+ if (!info) return osLabel(peer && peer.os);
143
+ const label = [info.name, info.version].filter(Boolean).join(" ");
144
+ return label || osLabel(peer && peer.os);
145
+ }
146
+
147
+ /**
148
+ * 一台机器上的「额外系统」(目前是 WSL 发行版)。
149
+ * 宿主机不在这里返回 —— 它已经由 osInfoLabel 表示了。
150
+ */
151
+ function extraSystems(peer) {
152
+ const list = peer && Array.isArray(peer.systems) ? peer.systems : [];
153
+ return list
154
+ .filter((s) => s && s.kind && s.kind !== "host")
155
+ .map((s, i) => ({
156
+ key: `${s.kind}-${s.name || i}`,
157
+ kind: s.kind,
158
+ text: [s.kind === "wsl" ? "WSL" : s.kind, s.name, s.version].filter(Boolean).join(" "),
159
+ }));
160
+ }
161
+
162
+ /** WSL 发行版里的运行时,压成一行;没有就返回空串。 */
163
+ function wslSummary(caps) {
164
+ const list = caps && Array.isArray(caps.wsl) ? caps.wsl : [];
165
+ return list
166
+ .map((w) => {
167
+ const rts = Object.entries(w.runtimes || {})
168
+ .map(([n, v]) => `${n} ${v}`)
169
+ .join("、");
170
+ return `${w.name}${rts ? `:${rts}` : ""}`;
171
+ })
172
+ .join(" · ");
173
+ }
174
+
139
175
  function shortAddress(host, port) {
140
176
  if (!host) return "地址未知";
141
177
  return port ? `${host}:${port}` : String(host);
@@ -533,6 +569,9 @@ window.__ModuleLoader__.load({
533
569
  const ts = (state && state.tsnet) || {};
534
570
  return [
535
571
  `Mesh ${self.version || ""}`.trim(),
572
+ self.diskVersion && self.diskVersion !== self.version
573
+ ? `disk: ${self.diskVersion} (已升级,进程未重启)`
574
+ : "",
536
575
  `machine: ${self.machine || ""}`,
537
576
  `address: ${shortAddress(self.host, self.port)}`,
538
577
  `hostname: ${self.hostname || ""}`,
@@ -2574,6 +2613,15 @@ window.__ModuleLoader__.load({
2574
2613
  : null,
2575
2614
  !runtimes.length ? h("span", { className: "mesh-chip is-muted" }, "未探到运行时") : null,
2576
2615
  ),
2616
+ // WSL 发行版里的运行时单独一行:Windows 上的 Python 和 WSL 里的 Python
2617
+ // 是两个环境,混进同一排 chip 会让人以为"装过了",从而把任务派到没有它的地方。
2618
+ wslSummary(caps)
2619
+ ? h(
2620
+ "div",
2621
+ { className: "mesh-chips", style: { marginTop: 6 } },
2622
+ h("span", { className: "mesh-chip is-muted" }, `WSL · ${wslSummary(caps)}`),
2623
+ )
2624
+ : null,
2577
2625
  runtimes.length > 6
2578
2626
  ? h(
2579
2627
  "button",
@@ -2675,13 +2723,24 @@ window.__ModuleLoader__.load({
2675
2723
  ? h("p", { className: "mesh-p" }, "对端还没有报告通道信息。等它下一次广播后会出现。")
2676
2724
  : eps.map((ep, i) => {
2677
2725
  const cooling = ep.downUntil && now < ep.downUntil;
2678
- const active = !!(peer.online && peer.transport && ep.transport === peer.transport);
2726
+ // 多 tailnet:通道 key 才是端点身份(lan / tsnet:<id>),
2727
+ // 只比 transport 会把"局域网在用"错标到每条 tailnet 上。
2728
+ const epKey = ep.channel || ep.transport || "";
2729
+ const active = !!(peer.online && (peer.channel || peer.transport) && epKey === (peer.channel || peer.transport));
2679
2730
  const state = active ? "在用" : cooling ? "冷却中" : ep.verified === false ? "未探测" : "备用";
2680
2731
  const kind = active ? "ok" : cooling ? "warn" : "idle";
2681
- const label = ep.transport === "tsnet" ? "互联网" : "局域网";
2732
+ const channelTag =
2733
+ ep.transport === "tsnet"
2734
+ ? epKey.startsWith("tsnet:cand:")
2735
+ ? "候选地址"
2736
+ : epKey.startsWith("tsnet:")
2737
+ ? epKey.slice("tsnet:".length)
2738
+ : ""
2739
+ : "";
2740
+ const label = ep.transport === "tsnet" ? (channelTag ? `互联网 · ${channelTag}` : "互联网") : "局域网";
2682
2741
  return h(
2683
2742
  "div",
2684
- { key: `ep-${ep.transport}-${i}`, className: "mesh-channel" },
2743
+ { key: `ep-${epKey}-${i}`, className: "mesh-channel" },
2685
2744
  h("span", { className: "mesh-channel-icon" }, h(Icon, { name: ep.transport === "tsnet" ? "tailscale" : "wifi", size: 14 })),
2686
2745
  h(
2687
2746
  "span",
@@ -2904,10 +2963,22 @@ window.__ModuleLoader__.load({
2904
2963
  "div",
2905
2964
  { className: "mesh-meta" },
2906
2965
  h(Status, { kind: online ? "ok" : "idle" }, isSelf ? "运行中" : online ? "在线" : "离线"),
2966
+ h("span", null, osInfoLabel(peer)),
2907
2967
  h("span", { className: "mesh-address" }, address),
2908
2968
  isSelf ? null : h("span", null, `最后心跳 ${ago(peer.lastSeen, now)}`),
2909
2969
  peer.capabilitiesStale ? h(Badge, { kind: "warn" }, "能力可能过期") : null,
2910
2970
  ),
2971
+ // 同一台机器上的其它系统(WSL)。分开显示:Windows 上的 Python 和
2972
+ // WSL 里的 Python 是两个环境,混成一行会让 Placement 判断错。
2973
+ extraSystems(peer).length
2974
+ ? h(
2975
+ "div",
2976
+ { className: "mesh-meta" },
2977
+ extraSystems(peer).map((sys) =>
2978
+ h("span", { key: sys.key, className: "mesh-chip" }, h("span", { className: "mesh-chip-label" }, sys.text)),
2979
+ ),
2980
+ )
2981
+ : null,
2911
2982
  ),
2912
2983
  h(
2913
2984
  "div",
@@ -4148,9 +4219,56 @@ window.__ModuleLoader__.load({
4148
4219
  );
4149
4220
  }
4150
4221
 
4222
+ /** 单条通道的阶段 → 文案/颜色。 */
4223
+ function channelPhase(ch) {
4224
+ const p = ch && ch.node && ch.node.phase ? ch.node.phase : ch && ch.enabled ? "idle" : "off";
4225
+ const map = {
4226
+ off: ["未启用", "idle"],
4227
+ idle: ["未连接", "idle"],
4228
+ starting: ["正在启动", "warn"],
4229
+ downloading: ["正在下载组件", "warn"],
4230
+ "needs-login": ["需要授权", "warn"],
4231
+ running: ["已连接", "ok"],
4232
+ exited: ["已停止", "idle"],
4233
+ error: ["出错", "err"],
4234
+ };
4235
+ const m = map[p] || [p, "idle"];
4236
+ return { phase: p, label: m[0], kind: m[1] };
4237
+ }
4238
+
4239
+ /**
4240
+ * 汇总多条 tailnet 通道的状态。
4241
+ *
4242
+ * 多 tailnet 之后"连上没连上"不再是一个布尔值:3 条通道里连上 2 条,
4243
+ * 既要显示"已连接",又要让用户看见还差一条。所以标签带分数。
4244
+ */
4151
4245
  function tsnetPhase(tsnet) {
4152
- const node = tsnet && tsnet.node;
4153
- const phase = node && node.phase ? node.phase : tsnet && tsnet.enabled ? "idle" : "off";
4246
+ if (!tsnet) return { phase: "off", label: "未启用", kind: "idle", channels: [], running: 0 };
4247
+ const channels = Array.isArray(tsnet.channels) ? tsnet.channels.slice() : [];
4248
+ // 旧主机只有单节点字段:合成一个通道视图,界面逻辑不分叉
4249
+ if (channels.length === 0 && tsnet.node) {
4250
+ channels.push({
4251
+ id: "default",
4252
+ label: "Tailscale",
4253
+ enabled: tsnet.enabled === true,
4254
+ authKeySaved: tsnet.authKeySaved === true,
4255
+ controlUrl: tsnet.controlUrl || "",
4256
+ hostname: (tsnet.node && tsnet.node.hostname) || "",
4257
+ node: tsnet.node,
4258
+ recentEvents: tsnet.recentEvents || [],
4259
+ });
4260
+ }
4261
+ const phases = channels.map((c) => channelPhase(c).phase);
4262
+ const running = phases.filter((p) => p === "running").length;
4263
+ let phase = tsnet.enabled ? "idle" : "off";
4264
+ if (running > 0) phase = "running";
4265
+ else if (phases.includes("needs-login")) phase = "needs-login";
4266
+ else if (phases.includes("downloading")) phase = "downloading";
4267
+ else if (phases.includes("starting")) phase = "starting";
4268
+ else if (phases.includes("error")) phase = "error";
4269
+ else if (phases.includes("exited")) phase = "exited";
4270
+ else if (channels.length === 0) phase = tsnet.enabled ? "idle" : "off";
4271
+ const base = channelPhase({ enabled: tsnet.enabled, node: null });
4154
4272
  const map = {
4155
4273
  off: ["未启用", "idle"],
4156
4274
  idle: ["已启用 · 未启动", "idle"],
@@ -4161,72 +4279,120 @@ window.__ModuleLoader__.load({
4161
4279
  exited: ["已停止", "idle"],
4162
4280
  error: ["出错", "err"],
4163
4281
  };
4164
- return { phase, label: (map[phase] || [phase, "idle"])[0], kind: (map[phase] || [phase, "idle"])[1] };
4282
+ const m = map[phase] || base;
4283
+ let label = m[0];
4284
+ if (phase === "running" && channels.length > 1) label = `已连接 ${running}/${channels.length} 条`;
4285
+ return { phase, label, kind: m[1], channels, running };
4286
+ }
4287
+
4288
+ /** 通道列表的公共视图:旧主机没有 channels 时用旧字段兜底。 */
4289
+ function tsnetChannelsOf(tsnet) {
4290
+ const list = tsnet && Array.isArray(tsnet.channels) ? tsnet.channels.slice() : [];
4291
+ if (list.length > 0) return list;
4292
+ if (tsnet && tsnet.node) {
4293
+ return [
4294
+ {
4295
+ id: "default",
4296
+ label: "Tailscale",
4297
+ enabled: tsnet.enabled === true,
4298
+ authKeySaved: tsnet.authKeySaved === true,
4299
+ controlUrl: tsnet.controlUrl || "",
4300
+ hostname: (tsnet.node && tsnet.node.hostname) || "",
4301
+ node: tsnet.node,
4302
+ recentEvents: tsnet.recentEvents || [],
4303
+ },
4304
+ ];
4305
+ }
4306
+ return [];
4307
+ }
4308
+
4309
+ /** 已连接通道的 tailnet 地址(供设置页/卡片显示一行摘要)。 */
4310
+ function tsnetAddressList(tsnet) {
4311
+ return tsnetChannelsOf(tsnet)
4312
+ .filter((c) => c.node && c.node.phase === "running")
4313
+ .map((c) => (c.node && c.node.selfIpv4) || "")
4314
+ .filter(Boolean);
4165
4315
  }
4166
4316
 
4167
4317
  function TsnetBody({ tsnet, push, reload }) {
4168
- const [key, setKey] = react.useState("");
4169
- const [controlUrl, setControlUrl] = react.useState((tsnet && tsnet.controlUrl) || "");
4170
4318
  const [busy, setBusy] = react.useState("");
4171
4319
  const [error, setError] = react.useState("");
4172
-
4173
- react.useEffect(() => {
4174
- setControlUrl((tsnet && tsnet.controlUrl) || "");
4175
- }, [tsnet && tsnet.controlUrl]);
4320
+ const [draftLabel, setDraftLabel] = react.useState("");
4321
+ const [draftKey, setDraftKey] = react.useState("");
4322
+ const [draftControl, setDraftControl] = react.useState("");
4176
4323
 
4177
4324
  if (!tsnet) {
4178
4325
  return h("p", { className: "mesh-p" }, "当前主机版本还没有跨网络组网能力。升级插件后会出现在这里。");
4179
4326
  }
4180
4327
 
4181
- const node = tsnet.node || null;
4328
+ const channels = tsnetChannelsOf(tsnet);
4182
4329
  const phase = tsnetPhase(tsnet);
4183
- const running = phase.phase === "running";
4184
- const events = (tsnet.recentEvents && tsnet.recentEvents.length ? tsnet.recentEvents : node && node.recentEvents ? node.recentEvents : []).slice(-6);
4185
- const canConnect = !!(tsnet.authKeySaved || key.trim());
4330
+ const running = phase.running;
4331
+ const events = (channels.find((c) => c.node && c.node.phase === "running")?.recentEvents || channels[0]?.recentEvents || tsnet.recentEvents || []).slice(-6);
4186
4332
 
4187
- const saveAndConnect = async () => {
4188
- if (!canConnect) {
4189
- setError("先填入授权码。");
4190
- return;
4191
- }
4192
- setBusy("connect");
4333
+ const run = async (path, body, okText) => {
4334
+ const tag = `${path}${body && body.id ? `:${body.id}` : ""}`;
4335
+ setBusy(tag);
4193
4336
  setError("");
4194
4337
  try {
4195
- const saved = await api("/tsnet/config", {
4196
- authKey: key.trim(),
4197
- controlUrl: controlUrl.trim(),
4198
- enabled: true,
4199
- });
4200
- if (!saved || !saved.ok) {
4201
- setError(`保存失败:${apiErr(saved)}`);
4202
- return;
4203
- }
4204
- setKey("");
4205
- const started = await api("/tsnet/start", {});
4206
- if (started && started.ok) {
4207
- push("success", "已开始连接。授权码只保存在本机,之后不用再填。");
4208
- } else {
4209
- push("error", `启动失败:${apiErr(started)}`);
4338
+ const r = await api(path, body || {});
4339
+ if (r && r.ok) {
4340
+ push("success", okText || "完成");
4341
+ await reload();
4342
+ return r;
4210
4343
  }
4211
- await reload();
4344
+ setError(apiErr(r));
4345
+ return r;
4212
4346
  } catch (e) {
4213
4347
  setError(String((e && e.message) || e));
4348
+ return null;
4214
4349
  } finally {
4215
4350
  setBusy("");
4216
4351
  }
4217
4352
  };
4218
4353
 
4219
- const runNode = async (path, okText) => {
4220
- setBusy(path);
4354
+ // 保存通道列表时只回传非敏感字段;授权码留空 = 保留原值(宿主按 id 合并)。
4355
+ const payloadOf = (list) =>
4356
+ list.map((c) => ({
4357
+ id: c.id,
4358
+ label: c.label,
4359
+ controlUrl: c.controlUrl || "",
4360
+ hostname: c.hostname || "",
4361
+ enabled: c.enabled !== false,
4362
+ }));
4363
+
4364
+ const addChannel = async () => {
4365
+ if (!draftKey.trim()) {
4366
+ setError("先填入授权码。");
4367
+ return;
4368
+ }
4369
+ setBusy("add");
4221
4370
  setError("");
4222
4371
  try {
4223
- const r = await api(path, {});
4224
- if (r && r.ok) {
4225
- push("success", okText || "完成");
4226
- await reload();
4227
- } else {
4228
- setError(apiErr(r));
4372
+ const next = [
4373
+ ...payloadOf(channels),
4374
+ {
4375
+ label: draftLabel.trim() || `Tailnet ${channels.length + 1}`,
4376
+ authKey: draftKey.trim(),
4377
+ controlUrl: draftControl.trim(),
4378
+ enabled: true,
4379
+ },
4380
+ ];
4381
+ const saved = await api("/tsnet/config", { channels: next });
4382
+ if (!saved || !saved.ok) {
4383
+ setError(`保存失败:${apiErr(saved)}`);
4384
+ return;
4229
4385
  }
4386
+ const created = (saved.channels || []).find((c) => !channels.some((x) => x.id === c.id));
4387
+ if (created) {
4388
+ const started = await api("/tsnet/start", { id: created.id });
4389
+ if (started && started.ok) push("success", `通道「${created.label}」已开始连接。授权码只保存在本机。`);
4390
+ else push("error", `通道已保存,但启动失败:${apiErr(started)}`);
4391
+ }
4392
+ setDraftLabel("");
4393
+ setDraftKey("");
4394
+ setDraftControl("");
4395
+ await reload();
4230
4396
  } catch (e) {
4231
4397
  setError(String((e && e.message) || e));
4232
4398
  } finally {
@@ -4234,60 +4400,158 @@ window.__ModuleLoader__.load({
4234
4400
  }
4235
4401
  };
4236
4402
 
4403
+ const removeChannel = async (ch) => {
4404
+ const next = payloadOf(channels.filter((c) => c.id !== ch.id));
4405
+ // 最后一条也允许删:宿主会顺带清掉旧版单通道字段并关闭组网,
4406
+ // 否则"删不掉、也关不干净"会变成又一处静默残留。
4407
+ await run(
4408
+ "/tsnet/config",
4409
+ { channels: next },
4410
+ next.length === 0 ? "所有通道已删除,跨网络组网已关闭" : `通道「${ch.label || ch.id}」已删除`,
4411
+ );
4412
+ };
4413
+
4414
+ const updateEnabled = async (ch, enabled) => {
4415
+ const next = payloadOf(channels).map((c) => (c.id === ch.id ? { ...c, enabled } : c));
4416
+ await run("/tsnet/config", { channels: next }, enabled ? "通道已启用" : "通道已停用");
4417
+ };
4418
+
4237
4419
  return h(
4238
4420
  "div",
4239
4421
  null,
4240
4422
  h(
4241
4423
  "p",
4242
4424
  { className: "mesh-p", style: { marginBottom: 12 } },
4243
- "让不在同一网络的电脑也能互相派发任务。使用同一套设备列表,不需要另装 Tailscale 客户端。",
4425
+ "让不在同一网络的电脑也能互相派发任务。使用同一套设备列表,不需要另装 Tailscale 客户端。一台机器可以同时加入多个 tailnet:设备身份仍然只有一个,每条通道只是它的一条路。",
4244
4426
  ),
4245
- node && node.authUrl
4427
+ channels.length === 0
4246
4428
  ? h(
4247
4429
  "div",
4248
- { className: "mesh-note is-warn" },
4249
- h(Icon, { name: "alert", size: 13 }),
4430
+ { className: "mesh-note" },
4431
+ h(Icon, { name: "key", size: 13 }),
4250
4432
  h("span", null,
4251
- "这台机器需要你授权加入 tailnet:",
4252
- h("a", { href: node.authUrl, target: "_blank", rel: "noreferrer", style: { marginLeft: 4, wordBreak: "break-all" } }, "打开授权页"),
4433
+ "还没有配置 tailnet 通道。需要一个 Tailscale 授权码:打开 ",
4434
+ h("a", { href: TS_KEYS_URL, target: "_blank", rel: "noreferrer" }, TS_KEYS_URL),
4435
+ " 登录后点 Generate auth key;生成时勾选 Reusable,如果后台开了设备审批再勾 Pre-approved。",
4253
4436
  ),
4254
4437
  )
4255
4438
  : null,
4256
- node && node.error
4257
- ? h(
4258
- "div",
4259
- { className: "mesh-note is-err" },
4260
- h(Icon, { name: "alert", size: 13 }),
4261
- h("span", null, String(node.error)),
4262
- )
4263
- : null,
4264
- phase.phase === "downloading"
4265
- ? h(
4266
- "div",
4267
- { className: "mesh-note" },
4268
- h("span", { className: "mesh-spinner" }),
4269
- h("span", null, `正在下载组件${node && node.downloadPercent ? ` · ${node.downloadPercent}%` : ""}。第一次使用会稍慢,之后不再下载。`),
4270
- )
4271
- : null,
4272
- h(
4273
- Collapse,
4274
- { open: running },
4275
- h(
4439
+ channels.map((ch) => {
4440
+ const cp = channelPhase(ch);
4441
+ const node = ch.node || null;
4442
+ const isBusy = !!busy;
4443
+ return h(
4276
4444
  "div",
4277
- { className: "mesh-channel" },
4278
- h("span", { className: "mesh-channel-icon" }, h(Icon, { name: "tailscale", size: 14 })),
4445
+ { key: ch.id, className: "mesh-channel-card", style: { marginBottom: 10 } },
4279
4446
  h(
4280
- "span",
4281
- { className: "mesh-channel-main" },
4282
- h("span", { className: "mesh-channel-title" }, "Tailscale", h(Badge, { kind: "ok" }, "已连接")),
4283
- h("span", { className: "mesh-channel-sub" }, [node && node.selfIpv4, node && node.selfDnsName].filter(Boolean).join(" · ") || "已建立连接"),
4447
+ "div",
4448
+ { className: "mesh-channel" },
4449
+ h("span", { className: "mesh-channel-icon" }, h(Icon, { name: "tailscale", size: 14 })),
4450
+ h(
4451
+ "span",
4452
+ { className: "mesh-channel-main" },
4453
+ h(
4454
+ "span",
4455
+ { className: "mesh-channel-title" },
4456
+ ch.label || "Tailscale",
4457
+ h(Badge, { kind: cp.kind }, cp.label),
4458
+ ch.id !== "default" ? h("span", { className: "mesh-channel-sub", style: { marginLeft: 6 } }, ch.id) : null,
4459
+ ),
4460
+ h(
4461
+ "span",
4462
+ { className: "mesh-channel-sub" },
4463
+ node && node.selfIpv4
4464
+ ? [node.selfIpv4, node.selfDnsName].filter(Boolean).join(" · ")
4465
+ : ch.authKeySaved
4466
+ ? `已保存授权码${ch.controlUrl ? ` · ${ch.controlUrl}` : " · 官方 Tailscale"}`
4467
+ : "未设置授权码",
4468
+ ),
4469
+ ),
4470
+ cp.phase === "running"
4471
+ ? h(
4472
+ Button,
4473
+ {
4474
+ variant: "ghost",
4475
+ size: "sm",
4476
+ loading: busy === `/tsnet/stop:${ch.id}`,
4477
+ disabled: isBusy && busy !== `/tsnet/stop:${ch.id}`,
4478
+ onClick: () => run("/tsnet/stop", { id: ch.id }, `通道「${ch.label || ch.id}」已断开`),
4479
+ },
4480
+ "断开",
4481
+ )
4482
+ : h(
4483
+ Button,
4484
+ {
4485
+ variant: "ghost",
4486
+ size: "sm",
4487
+ loading: busy === `/tsnet/start:${ch.id}`,
4488
+ disabled: isBusy && busy !== `/tsnet/start:${ch.id}`,
4489
+ onClick: () => run("/tsnet/start", { id: ch.id }, `通道「${ch.label || ch.id}」已启动`),
4490
+ },
4491
+ "连接",
4492
+ ),
4284
4493
  ),
4285
- h(Button, { variant: "ghost", size: "sm", loading: busy === "/tsnet/stop", onClick: () => runNode("/tsnet/stop", "已断开") }, "断开"),
4286
- ),
4287
- ),
4494
+ node && node.authUrl
4495
+ ? h(
4496
+ "div",
4497
+ { className: "mesh-note is-warn" },
4498
+ h(Icon, { name: "alert", size: 13 }),
4499
+ h("span", null,
4500
+ "这条通道需要你授权加入 tailnet:",
4501
+ h("a", { href: node.authUrl, target: "_blank", rel: "noreferrer", style: { marginLeft: 4, wordBreak: "break-all" } }, "打开授权页"),
4502
+ ),
4503
+ )
4504
+ : null,
4505
+ node && node.error
4506
+ ? h(
4507
+ "div",
4508
+ { className: "mesh-note is-err" },
4509
+ h(Icon, { name: "alert", size: 13 }),
4510
+ h("span", null, String(node.error)),
4511
+ )
4512
+ : null,
4513
+ cp.phase === "downloading"
4514
+ ? h(
4515
+ "div",
4516
+ { className: "mesh-note" },
4517
+ h("span", { className: "mesh-spinner" }),
4518
+ h("span", null, `正在下载组件${node && node.downloadPercent ? ` · ${node.downloadPercent}%` : ""}。第一次使用会稍慢,之后不再下载。`),
4519
+ )
4520
+ : null,
4521
+ h(
4522
+ Fold,
4523
+ { title: "通道设置", right: ch.controlUrl ? "自定义控制服务器" : "官方 Tailscale" },
4524
+ h(
4525
+ "dl",
4526
+ { className: "mesh-kv" },
4527
+ h("dt", null, "通道 id"), h("dd", null, ch.id),
4528
+ h("dt", null, "节点名"), h("dd", null, (node && node.hostname) || ch.hostname || "—"),
4529
+ h("dt", null, "控制服务器"), h("dd", null, ch.controlUrl || "官方"),
4530
+ h("dt", null, "授权码"), h("dd", null, ch.authKeySaved ? "已保存(不会显示内容)" : "未设置"),
4531
+ ),
4532
+ h(
4533
+ "div",
4534
+ { className: "mesh-actions-row" },
4535
+ h(Button, { variant: "ghost", size: "sm", disabled: !!busy || cp.phase !== "running", loading: busy === `/tsnet/scan:${ch.id}`, onClick: () => run("/tsnet/scan", { id: ch.id }, "已扫描该通道") }, "扫描该通道"),
4536
+ h(ConfirmButton, {
4537
+ label: "重新登录",
4538
+ confirmLabel: "确认清除身份?",
4539
+ disabled: !!busy || !ch.authKeySaved,
4540
+ onConfirm: () => run("/tsnet/relogin", { id: ch.id }, "已清除节点身份,等待重新授权"),
4541
+ }),
4542
+ h(ConfirmButton, {
4543
+ label: "删除通道",
4544
+ confirmLabel: "确认删除?",
4545
+ disabled: !!busy,
4546
+ onConfirm: () => removeChannel(ch),
4547
+ }),
4548
+ ),
4549
+ ),
4550
+ );
4551
+ }),
4288
4552
  h(
4289
- Collapse,
4290
- { open: !running },
4553
+ Fold,
4554
+ { title: channels.length ? "添加通道" : "配置第一条通道", right: "多 tailnet", defaultOpen: channels.length === 0 },
4291
4555
  h(
4292
4556
  "div",
4293
4557
  null,
@@ -4296,21 +4560,39 @@ window.__ModuleLoader__.load({
4296
4560
  { className: "mesh-note" },
4297
4561
  h(Icon, { name: "key", size: 13 }),
4298
4562
  h("span", null,
4299
- "需要一个 Tailscale 授权码。打开 ",
4300
- h("a", { href: TS_KEYS_URL, target: "_blank", rel: "noreferrer" }, TS_KEYS_URL),
4301
- " 登录后点 Generate auth key;生成时勾选 Reusable,如果后台开了设备审批再勾 Pre-approved。",
4563
+ "每条通道对应一个 tailnet(一把 tskey 一把钥匙,但可以加多条)。名称只用于本机显示;重命名不影响设备身份。",
4302
4564
  ),
4303
4565
  ),
4304
4566
  h(
4305
4567
  Field,
4306
- { label: "授权码", hint: "只保存在本机;之后留空即可沿用。粘贴新值会替换旧值。" },
4568
+ { label: "名称(可选)", hint: "例如「个人」「公司」;留空自动命名。" },
4569
+ h("input", {
4570
+ className: "mesh-input",
4571
+ value: draftLabel,
4572
+ placeholder: "公司 tailnet",
4573
+ onChange: (e) => setDraftLabel(e.target.value),
4574
+ }),
4575
+ ),
4576
+ h(
4577
+ Field,
4578
+ { label: "授权码", hint: "只保存在本机;粘贴新值会新增一条通道。" },
4307
4579
  h("input", {
4308
4580
  className: "mesh-input",
4309
4581
  type: "password",
4310
4582
  autoComplete: "off",
4311
- value: key,
4312
- placeholder: tsnet.authKeySaved ? "已保存 —— 留空沿用,粘贴新值可替换" : "tskey-auth-…",
4313
- onChange: (e) => setKey(e.target.value),
4583
+ value: draftKey,
4584
+ placeholder: "tskey-auth-…",
4585
+ onChange: (e) => setDraftKey(e.target.value),
4586
+ }),
4587
+ ),
4588
+ h(
4589
+ Field,
4590
+ { label: "控制服务器(可选)", hint: "留空用官方 Tailscale;Headscale 用户填自己的地址。" },
4591
+ h("input", {
4592
+ className: "mesh-input",
4593
+ value: draftControl,
4594
+ placeholder: "https://controlplane.tailscale.com",
4595
+ onChange: (e) => setDraftControl(e.target.value),
4314
4596
  }),
4315
4597
  ),
4316
4598
  h(
@@ -4318,44 +4600,24 @@ window.__ModuleLoader__.load({
4318
4600
  { className: "mesh-actions-row" },
4319
4601
  h(
4320
4602
  Button,
4321
- { variant: "primary", icon: "plug", loading: busy === "connect", disabled: !canConnect, onClick: saveAndConnect },
4322
- tsnet.enabled ? "保存并重启" : "保存并连接",
4603
+ { variant: "primary", icon: "plug", loading: busy === "add", disabled: !!busy || !draftKey.trim(), onClick: addChannel },
4604
+ "添加并连接",
4323
4605
  ),
4324
- tsnet.enabled && !running && tsnet.authKeySaved
4325
- ? h(Button, { variant: "ghost", loading: busy === "/tsnet/start", onClick: () => runNode("/tsnet/start", "已启动") }, "只启动")
4326
- : null,
4327
4606
  ),
4328
4607
  ),
4329
4608
  ),
4330
4609
  h(
4331
4610
  Fold,
4332
- { title: "高级", right: running ? "连接参数与维护" : undefined },
4333
- h(
4334
- Field,
4335
- { label: "控制服务器", hint: "留空用官方 Tailscale;Headscale 用户填自己的地址。修改后点“保存并重启”。" },
4336
- h("input", {
4337
- className: "mesh-input",
4338
- value: controlUrl,
4339
- placeholder: "https://controlplane.tailscale.com",
4340
- onChange: (e) => setControlUrl(e.target.value),
4341
- }),
4342
- ),
4611
+ { title: "维护", right: running ? "扫描与组件" : undefined },
4343
4612
  h(
4344
4613
  "div",
4345
4614
  { className: "mesh-actions-row" },
4346
- h(Button, { variant: "ghost", size: "sm", disabled: !tsnet.enabled || !!busy, loading: busy === "/tsnet/scan", onClick: () => runNode("/tsnet/scan", "已扫描 tailnet") }, "扫描 tailnet"),
4347
- h(Button, { variant: "ghost", size: "sm", disabled: !canConnect || !!busy, loading: busy === "connect", onClick: saveAndConnect }, "保存并重启"),
4348
- h(ConfirmButton, {
4349
- label: "重新登录",
4350
- confirmLabel: "确认清除身份?",
4351
- disabled: !tsnet.enabled || !!busy,
4352
- onConfirm: () => runNode("/tsnet/relogin", "已清除节点身份,等待重新授权"),
4353
- }),
4615
+ h(Button, { variant: "ghost", size: "sm", disabled: !!busy || running === 0, loading: busy === "/tsnet/scan", onClick: () => run("/tsnet/scan", {}, "已扫描所有通道") }, "扫描所有通道"),
4354
4616
  h(ConfirmButton, {
4355
4617
  label: "重新下载组件",
4356
4618
  confirmLabel: "确认重新下载?",
4357
- disabled: !tsnet.enabled || !!busy,
4358
- onConfirm: () => runNode("/tsnet/reinstall", "已重新下载组件"),
4619
+ disabled: !!busy,
4620
+ onConfirm: () => run("/tsnet/reinstall", {}, "已重新下载组件"),
4359
4621
  }),
4360
4622
  ),
4361
4623
  events.length
@@ -4392,9 +4654,19 @@ window.__ModuleLoader__.load({
4392
4654
  h("dt", null, "端口"), h("dd", null, String(self.port || "—")),
4393
4655
  h("dt", null, "主机名"), h("dd", null, self.hostname || "—"),
4394
4656
  h("dt", null, "MAC"), h("dd", null, self.mac || "—"),
4395
- h("dt", null, "版本"), h("dd", null, self.version || "—"),
4657
+ h("dt", null, "版本(进程)"), h("dd", null, self.version || "—"),
4658
+ // 进程版本 ≠ 磁盘版本 = 升级了没重启。光看一个版本号永远发现不了,
4659
+ // 于是用户会拿旧行为当新版本的 bug 报上来(真踩过)。
4660
+ h("dt", null, "版本(磁盘)"), h("dd", null, self.diskVersion || "—"),
4396
4661
  h("dt", null, "对端"), h("dd", null, `${peers.length} 台,在线 ${peers.filter((p) => p && p.online).length} 台`),
4397
4662
  ),
4663
+ self.versionDrift
4664
+ ? h(
4665
+ "div",
4666
+ { className: "mesh-notice", role: "status" },
4667
+ `磁盘上是 ${self.diskVersion},当前进程还在跑 ${self.version}:重启 DSH 后新版本才生效。`,
4668
+ )
4669
+ : null,
4398
4670
  h(
4399
4671
  "div",
4400
4672
  { className: "mesh-actions-row" },
@@ -4464,8 +4736,8 @@ window.__ModuleLoader__.load({
4464
4736
  id: "tsnet",
4465
4737
  icon: "tailscale",
4466
4738
  title: "互联网组网",
4467
- subtitle: tsnet.enabled
4468
- ? `${phase.label}${tsnet.node && tsnet.node.selfIpv4 ? ` · ${tsnet.node.selfIpv4}` : ""}`
4739
+ subtitle: tsnet.enabled || tsnetAddressList(tsnet).length
4740
+ ? `${phase.label}${tsnetAddressList(tsnet).length ? ` · ${tsnetAddressList(tsnet)[0]}` : ""}`
4469
4741
  : "未启用 · 跨网络互联(Tailscale)",
4470
4742
  status: h(Badge, { kind: phase.kind }, phase.label),
4471
4743
  open: open === "tsnet",
@@ -4682,8 +4954,8 @@ window.__ModuleLoader__.load({
4682
4954
  children: h(
4683
4955
  "p",
4684
4956
  { className: "mesh-card-text" },
4685
- tsnet && tsnet.node && tsnet.node.selfIpv4
4686
- ? `已连接 · ${tsnet.node.selfIpv4}${tsnet.node.selfDnsName ? ` · ${tsnet.node.selfDnsName}` : ""}`
4957
+ tsnetAddressList(tsnet).length
4958
+ ? `已连接 ${tsnetAddressList(tsnet).length} 条通道 · ${tsnetAddressList(tsnet).join(" · ")}`
4687
4959
  : "让不在同一网络的电脑也能互相派发任务。需要免费的 Tailscale 账号,授权码只保存一次。",
4688
4960
  ),
4689
4961
  footer: h(Button, { variant: "ghost", size: "sm", icon: "tailscale", onClick: () => onConnect("tsnet") }, "设置互联网组网"),
@@ -5633,8 +5905,8 @@ window.__ModuleLoader__.load({
5633
5905
  children: h(
5634
5906
  "p",
5635
5907
  { className: "mesh-card-text" },
5636
- tsnet && tsnet.node && tsnet.node.selfIpv4
5637
- ? `已连接 · ${tsnet.node.selfIpv4}${tsnet.node.selfDnsName ? ` · ${tsnet.node.selfDnsName}` : ""}`
5908
+ tsnetAddressList(tsnet).length
5909
+ ? `已连接 ${tsnetAddressList(tsnet).length} 条通道 · ${tsnetAddressList(tsnet).join(" · ")}`
5638
5910
  : "让不在同一网络的电脑也能互相派发任务。需要免费的 Tailscale 账号,授权码只保存一次。",
5639
5911
  ),
5640
5912
  footer: h(Button, { variant: "ghost", size: "sm", icon: "tailscale", onClick: () => onConnect("tsnet") }, "设置互联网组网"),
@@ -6567,6 +6839,7 @@ window.__ModuleLoader__.load({
6567
6839
  TaskRow,
6568
6840
  TaskDetail,
6569
6841
  SettingsView,
6842
+ Diagnostics,
6570
6843
  Composer,
6571
6844
  TopBar,
6572
6845
  TransferLayer,