dsh-drydock 1.0.1 → 1.0.2

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/bin/open-boot.mjs CHANGED
@@ -1522,13 +1522,28 @@ pre{background:#0b0d11;border:1px solid #2a2e38;border-radius:8px;padding:12px;f
1522
1522
  <h1>${drydockLogoMarkSvg(20)} 🚀 DSH 启动器</h1>
1523
1523
  <div class="sub">正在执行 自检 → 修复 → 启动,完成后自动打开主界面…</div>
1524
1524
  <div class="spinner" id="spin"></div>
1525
+ <div class="sub" id="elapsed" aria-live="polite" style="margin:-6px 0 10px;font-size:12.5px"></div>
1525
1526
  <pre id="out"></pre>
1526
1527
  <div class="sub" style="margin:16px 0 0"><a href="/rescue">救援中心</a>(检查 / 修复 / 启动 / 停止 / 状态)· <a href="/plugins">插件管理</a>(启停 mod / 重启引擎 / 停止启动器)</div>
1527
1528
  <script>
1528
1529
  const out = document.getElementById("out");
1530
+ const spin = document.getElementById("spin");
1531
+ const elapsedEl = document.getElementById("elapsed");
1529
1532
  const TOKEN = (document.querySelector('meta[name="dsh-pm-token"]') || {}).content || "";
1533
+ // U1:启动流程是一个长请求(自检→修复→启动),中间没有任何服务端事件 —— 用计时器证明"页面没卡住"
1534
+ let waited = 0;
1535
+ const ticker = setInterval(function(){
1536
+ waited++;
1537
+ elapsedEl.textContent = "已等待 " + waited + " 秒" + (waited >= 15 ? "(首次启动或修复较慢,页面没有卡住,请勿关闭)" : "…");
1538
+ }, 1000);
1539
+ function stopSpin(){
1540
+ clearInterval(ticker);
1541
+ spin.style.display = "none";
1542
+ if (waited > 0) elapsedEl.textContent = "本次等待 " + waited + " 秒";
1543
+ }
1530
1544
  function log(line, cls){ out.innerHTML += (cls?'<span class="'+cls+'">':'') + String(line).replace(/</g,'&lt;') + (cls?'</span>':'') + "\\n"; }
1531
1545
  function goEntry(r){
1546
+ stopSpin();
1532
1547
  if (r && r.entryUrl) { location.href = r.entryUrl; return; }
1533
1548
  // G03:entryUrl=null(引擎本次启动没打印/没写可读的 token 行)→ 降级指引,不渲染假 token 链接。
1534
1549
  log("⚠ 未捕获到本次启动的登录链接(entryUrl=null,引擎可能没有把 token 行写进 web.log)。", "warn");
@@ -1539,7 +1554,7 @@ function goEntry(r){
1539
1554
  link.textContent = "→ 打开 http://127.0.0.1:${enginePort}/";
1540
1555
  out.appendChild(document.createElement("br"));
1541
1556
  out.appendChild(link);
1542
- document.getElementById("spin").style.display = "none";
1557
+ stopSpin();
1543
1558
  }
1544
1559
  (async () => {
1545
1560
  try {
@@ -1549,22 +1564,28 @@ function goEntry(r){
1549
1564
  goEntry(r);
1550
1565
  return;
1551
1566
  }
1552
- if (r.code === 409) { log("⚠ " + (r.error || "已有启动流程在执行中"), "warn"); return; }
1567
+ if (r.code === 409) {
1568
+ // U1:原本这里只写一行日志就 return,转圈图标永远转下去 → 看起来像卡死
1569
+ log("⚠ " + (r.error || "已有启动流程在执行中"), "warn");
1570
+ log("本页不会自动跳转;可等它完成,或打开 " + location.origin + "/rescue 救援中心看状态。", "warn");
1571
+ stopSpin();
1572
+ return;
1573
+ }
1553
1574
  if (r.verifyOk === false) log("自检:⚠ 发现 " + (r.issues||[]).length + " 个问题", "warn");
1554
1575
  else if (r.verifyOk === true) log("自检:✓ 配置正常", "ok");
1555
1576
  if (r.fixed) log("修复:" + (r.fixed.message || "完成"), "ok");
1556
1577
  if (r.window && r.window.ok) log("⧉ " + r.window.message + "(窗口里可看到完整进度,结束时按任意键关闭)", "warn");
1557
- if (r.ok) { log("✓ " + (r.message || "引擎已启动"), "ok"); setTimeout(() => goEntry(r), 600); }
1558
- else if (r.quarantined && r.quarantined.length) { log("⚠ 运行期失败条目已自动隔离:" + r.quarantined.join(", "), "bad"); log("✓ " + (r.message || "重试成功"), "ok"); setTimeout(() => goEntry(r), 600); }
1578
+ if (r.ok) { log("✓ " + (r.message || "引擎已启动"), "ok"); stopSpin(); setTimeout(() => goEntry(r), 600); }
1579
+ else if (r.quarantined && r.quarantined.length) { log("⚠ 运行期失败条目已自动隔离:" + r.quarantined.join(", "), "bad"); log("✓ " + (r.message || "重试成功"), "ok"); stopSpin(); setTimeout(() => goEntry(r), 600); }
1559
1580
  else {
1560
1581
  log("✗ " + (r.message || JSON.stringify(r)), "bad");
1561
1582
  if (r.logPath) log("日志:" + r.logPath, "warn");
1562
1583
  log("可运行 node bin/open-boot.mjs --status 查看启动器/守护/引擎状态,或打开 " + location.origin + "/rescue 救援中心", "warn");
1563
- document.getElementById("spin").style.display = "none";
1584
+ stopSpin();
1564
1585
  }
1565
1586
  } catch (e) {
1566
1587
  log("✗ 请求失败:" + e.message, "bad");
1567
- document.getElementById("spin").style.display = "none";
1588
+ stopSpin();
1568
1589
  }
1569
1590
  })();
1570
1591
  </script>
@@ -2238,6 +2259,9 @@ button.danger:hover{background:var(--bad-bg);color:var(--bad)}
2238
2259
  .toggle input:checked + .knob{background:var(--accent)}
2239
2260
  .toggle input:checked + .knob::after{left:18px}
2240
2261
  .toggle input:disabled + .knob{opacity:.45;cursor:not-allowed}
2262
+ /* U1:禁用的 input 会吞掉鼠标事件(点击落在它身上就什么都不发生)→ 让事件落到 label/knob 上,
2263
+ 这样"点核心组件开关"能弹 toast 解释为什么不能点,而不是一片死寂。 */
2264
+ .toggle input:disabled{pointer-events:none}
2241
2265
  .hint{color:var(--dim);font-size:12px;line-height:1.6}
2242
2266
  .hint a{color:var(--accent)}
2243
2267
  .dim{color:var(--dim)}
@@ -2246,7 +2270,7 @@ pre.log{background:var(--bg);border:1px solid var(--border);border-radius:8px;pa
2246
2270
  .dot{display:inline-block;width:9px;height:9px;border-radius:50%;margin-right:7px;vertical-align:baseline}
2247
2271
  .dot.ok{background:var(--ok)}.dot.suspect{background:var(--warn)}.dot.broken{background:var(--bad)}
2248
2272
  /* toast */
2249
- #toasts{position:fixed;top:16px;left:50%;transform:translateX(-50%);z-index:60;display:flex;flex-direction:column;gap:8px;align-items:center}
2273
+ #toasts{position:fixed;top:16px;left:50%;transform:translateX(-50%);z-index:60;display:flex;flex-direction:column;gap:8px;align-items:center;pointer-events:none}
2250
2274
  .toast{background:var(--card);border:1px solid var(--border);border-left:4px solid var(--accent);border-radius:8px;padding:9px 16px;font-size:13px;box-shadow:0 4px 14px rgba(0,0,0,.14);max-width:520px}
2251
2275
  .toast.ok{border-left-color:var(--ok)}.toast.bad{border-left-color:var(--bad)}.toast.warn{border-left-color:var(--warn)}
2252
2276
  /* 确认框 */
@@ -2258,6 +2282,12 @@ pre.log{background:var(--bg);border:1px solid var(--border);border-radius:8px;pa
2258
2282
  #confirmBox .btns{display:flex;justify-content:flex-end;gap:8px}
2259
2283
  .panel{display:none}
2260
2284
  .panel.open{display:block}
2285
+ /* U1:结果卡片落点 —— 操作完成后滚动到位 + 闪一下,避免"结果在视口外 = 按钮没反应" */
2286
+ @keyframes cardflash{0%{box-shadow:0 0 0 0 rgba(59,110,246,0)}35%{box-shadow:0 0 0 3px var(--accent)}100%{box-shadow:0 0 0 0 rgba(59,110,246,0)}}
2287
+ .card.flash{animation:cardflash 1.6s ease-out}
2288
+ /* U1:按钮 loading 态(发起反馈) */
2289
+ button.busy{cursor:progress;opacity:.65}
2290
+ .rowitem.busy{opacity:.6}
2261
2291
  </style></head><body><div class="wrap">
2262
2292
  <header>
2263
2293
  <div>
@@ -2283,17 +2313,6 @@ pre.log{background:var(--bg);border:1px solid var(--border);border-radius:8px;pa
2283
2313
  <div class="hint" style="margin-top:10px"><span id="engstate" class="dim">引擎状态检测中…</span> · 改动启用状态后需重启引擎生效(写前自动备份 package.json)。</div>
2284
2314
  </div>
2285
2315
 
2286
- <div class="card">
2287
- <p class="sect">核心组件(引擎必需,不允许禁用)</p>
2288
- <div class="rows" id="coreRows"></div>
2289
- </div>
2290
-
2291
- <div class="card">
2292
- <p class="sect">用户插件</p>
2293
- <div class="rows" id="userRows"></div>
2294
- <div class="hint" style="margin-top:8px">配置入口在各插件的行内设置(主界面 → 插件管理 → 行内 ⚙);「市场详情」打开主界面市场页。</div>
2295
- </div>
2296
-
2297
2316
  <div class="card panel" id="updPanel">
2298
2317
  <p class="sect">更新检查结果</p>
2299
2318
  <div class="rows" id="updRows"></div>
@@ -2310,6 +2329,17 @@ pre.log{background:var(--bg);border:1px solid var(--border);border-radius:8px;pa
2310
2329
  <div class="rows" id="stepRows"></div>
2311
2330
  </div>
2312
2331
 
2332
+ <div class="card">
2333
+ <p class="sect">核心组件(引擎必需,不允许禁用)</p>
2334
+ <div class="rows" id="coreRows"></div>
2335
+ </div>
2336
+
2337
+ <div class="card">
2338
+ <p class="sect">用户插件</p>
2339
+ <div class="rows" id="userRows"></div>
2340
+ <div class="hint" style="margin-top:8px">配置入口在各插件的行内设置(主界面 → 插件管理 → 行内 ⚙);「市场详情」打开主界面市场页。</div>
2341
+ </div>
2342
+
2313
2343
  <div class="hint" style="margin-top:16px">管理器不能在自身管理界面(引擎 ${enginePort})中停用自己;如需禁用或卸载,请前往启动器兜底页(本页 ${launcherPort} /plugins)或使用 dsh 命令行——兜底页独立于引擎存活,禁用后仍可恢复。<b>可事务性自卸载</b>(含开机自启清理指引)。卸载/更新前若引擎正占用目标包,会引导你先禁用并重启引擎,而不是硬删。</div>
2314
2344
  </div>
2315
2345
 
@@ -2356,6 +2386,7 @@ themeBtn.addEventListener("click", function(){
2356
2386
  var next = document.documentElement.getAttribute("data-theme") === "dark" ? "light" : "dark";
2357
2387
  try { localStorage.setItem(THEME_KEY, next); } catch (e) { /* 写不进去就只在本会话生效 */ }
2358
2388
  applyTheme();
2389
+ toast("主题已切换为" + (next === "dark" ? "深色" : "浅色") + "(本页记忆;长按主题按钮复位为自动)", "ok");
2359
2390
  });
2360
2391
  themeBtn.addEventListener("pointerdown", function(){
2361
2392
  themeLongPressed = false;
@@ -2379,10 +2410,54 @@ function toast(text, cls){
2379
2410
  var box = document.getElementById("toasts");
2380
2411
  var el = document.createElement("div");
2381
2412
  el.className = "toast " + (cls || "");
2413
+ el.setAttribute("role", "status");
2382
2414
  el.textContent = text;
2383
2415
  box.appendChild(el);
2384
2416
  setTimeout(function(){ el.remove(); }, 5200);
2385
2417
  }
2418
+ // —— U1:发起反馈 / 落点反馈的统一实现 ——
2419
+ /** 按钮 loading 态:禁用 + 改文案,结束后逐字还原(防重复点击 + 用户能看出"点到了")。 */
2420
+ function setBusy(btn, busy, label){
2421
+ if (!btn) return;
2422
+ if (busy) {
2423
+ if (btn.dataset.idleText === undefined) btn.dataset.idleText = btn.textContent;
2424
+ btn.disabled = true;
2425
+ btn.classList.add("busy");
2426
+ btn.setAttribute("aria-busy", "true");
2427
+ if (label) btn.textContent = label;
2428
+ } else {
2429
+ btn.disabled = false;
2430
+ btn.classList.remove("busy");
2431
+ btn.removeAttribute("aria-busy");
2432
+ if (btn.dataset.idleText !== undefined) { btn.textContent = btn.dataset.idleText; delete btn.dataset.idleText; }
2433
+ }
2434
+ }
2435
+ async function withBusy(btn, label, fn){
2436
+ setBusy(btn, true, label);
2437
+ try { return await fn(); } finally { setBusy(btn, false); }
2438
+ }
2439
+ /** 结果卡片落点:打开 → 滚进视口(block:nearest,不把页面顶跳)→ 高亮闪一下;toast 是"感知",这是"眼睛的落点"。 */
2440
+ function revealPanel(id){
2441
+ var panel = document.getElementById(id);
2442
+ if (!panel) return;
2443
+ panel.classList.add("open");
2444
+ panel.classList.remove("flash");
2445
+ try { void panel.offsetWidth; } catch (e) { /* 强制重排以重放动画 */ }
2446
+ panel.classList.add("flash");
2447
+ if (panel._flashTimer) clearTimeout(panel._flashTimer);
2448
+ panel._flashTimer = setTimeout(function(){ panel.classList.remove("flash"); }, 1700);
2449
+ try {
2450
+ // 卡片比视口还高时(体检 20+ 行 / 长列表后的步骤日志)nearest 可能只对齐底边,
2451
+ // 标题被切掉一半 → 这种情况对齐卡片顶部,保证"体检结果"这个标题一定在屏幕里。
2452
+ var tall = panel.getBoundingClientRect().height > window.innerHeight * 0.85;
2453
+ panel.scrollIntoView({ block: tall ? "start" : "nearest", behavior: "smooth" });
2454
+ } catch (e) { try { panel.scrollIntoView(false); } catch (e2) { /* 老浏览器不支持时退化为仅高亮 */ } }
2455
+ }
2456
+ /** 失败 toast 必须带原因:服务端没给原因也要说清"没给原因",不许只说"失败"。 */
2457
+ function failText(prefix, r){
2458
+ return prefix + ":" + ((r && r.error) ? r.error : "服务端未返回原因(可看「操作步骤日志」或重启启动器后重试)");
2459
+ }
2460
+
2386
2461
  function confirmBox(title, text, okLabel){
2387
2462
  return new Promise(function(resolveCF){
2388
2463
  var mask = document.getElementById("mask");
@@ -2434,6 +2509,13 @@ function toggleHtml(b){
2434
2509
  input.dataset.name = b.name;
2435
2510
  var knob = document.createElement("span"); knob.className = "knob";
2436
2511
  label.appendChild(input); label.appendChild(knob);
2512
+ if (b.core) {
2513
+ // 核心组件的开关是 disabled 的:点它原本毫无反应(用户以为坏了)→ 现在明确说明为什么不能点
2514
+ label.addEventListener("click", function(ev){
2515
+ ev.preventDefault();
2516
+ toast(b.name + " 是引擎必需的核心组件,不能在这里禁用;确需停用请走救援中心 /rescue 或手工改 profile。", "warn");
2517
+ });
2518
+ }
2437
2519
  return label;
2438
2520
  }
2439
2521
  function renderRows(){
@@ -2476,7 +2558,13 @@ function renderRows(){
2476
2558
  var mk = el("button", null, "市场详情");
2477
2559
  mk.title = "打开主界面(引擎未运行时置灰)";
2478
2560
  mk.disabled = !engineUp;
2479
- mk.addEventListener("click", function(){ window.open("http://127.0.0.1:" + ENGINE_PORT + "/", "_blank"); });
2561
+ mk.addEventListener("click", function(){
2562
+ var url = "http://127.0.0.1:" + ENGINE_PORT + "/";
2563
+ var w = null;
2564
+ try { w = window.open(url, "_blank"); } catch (e) { w = null; }
2565
+ if (!w) toast("浏览器拦截了新标签页:请允许本站弹窗,或手动打开 " + url, "warn");
2566
+ else toast("已在新标签页打开主界面(" + url + ")", "ok");
2567
+ });
2480
2568
  row.appendChild(mk);
2481
2569
  (b.core ? coreRows : userRows).appendChild(row);
2482
2570
  });
@@ -2522,67 +2610,89 @@ function renderSteps(steps){
2522
2610
  });
2523
2611
  }
2524
2612
  async function doUpdate(name, btn){
2525
- btn.disabled = true;
2613
+ setBusy(btn, true, "更新中…");
2526
2614
  await guard(async function(){
2527
2615
  var okGo = await confirmBox("更新 " + name, "将运行 pnpm update --latest。若引擎正在运行且该插件已启用,会拒绝并引导你先禁用。", "更新");
2528
- if (!okGo) return;
2616
+ if (!okGo) { toast("已取消更新 " + name, "warn"); return; }
2617
+ toast("正在更新 " + name + "(pnpm update --latest,可能 10-60s)…", "warn");
2529
2618
  var r = await api("/plugins/api/update", { name: name });
2530
- if (!r.ok) { toast(r.error || "更新失败", r.blocked === "engine-busy" ? "warn" : "bad"); return; }
2531
- toast(r.message || "已更新", "ok");
2532
- await refreshUpdates(false);
2619
+ if (!r.ok) {
2620
+ toast(failText("更新 " + name + " 失败", r) + (r.blocked === "engine-busy" ? "(引擎正占用该包:先禁用该插件并重启引擎,再更新)" : ""), r.blocked === "engine-busy" ? "warn" : "bad");
2621
+ return;
2622
+ }
2623
+ toast("已更新 " + name + (r.message ? ":" + r.message : "(重启引擎后生效)"), "ok");
2624
+ // 刷新更新面板并 revealPanel("updPanel")(refreshUpdates 内部负责滚到位;失败时不会掀出空卡片)
2625
+ await refreshUpdates({ showPanel: true, announce: false });
2533
2626
  });
2534
- btn.disabled = false;
2627
+ setBusy(btn, false);
2535
2628
  }
2536
2629
  async function doUninstall(b, btn){
2537
- btn.disabled = true;
2630
+ setBusy(btn, true, "卸载中…");
2538
2631
  await guard(async function(){
2539
2632
  var warnText = b.self
2540
2633
  ? "这是管理器自身:卸载后引擎 ${enginePort} 内的插件管理界面消失;启动器 ${launcherPort} 本兜底页存活到启动器进程结束;之后请运行 node bin/open-boot.mjs --uninstall 清理开机自启。确定继续?"
2541
2634
  : "将执行事务性卸载:备份清单与 cordis.patch.yml → pnpm remove → 清理补丁行 → 验证;每一步都会留下回滚记录。确定继续?";
2542
2635
  var okGo = await confirmBox("卸载 " + b.name, warnText, "卸载");
2543
- if (!okGo) return;
2636
+ if (!okGo) { toast("已取消卸载 " + b.name, "warn"); return; }
2637
+ toast("正在卸载 " + b.name + "(事务性:备份 → pnpm remove → 清理补丁 → 验证)…", "warn");
2544
2638
  var r = await api("/plugins/api/uninstall", { name: b.name });
2545
- if (!r.ok) { toast(r.error || "卸载失败", r.blocked === "engine-busy" ? "warn" : "bad"); return; }
2546
- toast(r.message || "已卸载", "ok");
2547
- if (Array.isArray(r.steps)) renderSteps(r.steps);
2639
+ if (!r.ok) {
2640
+ toast(failText("卸载 " + b.name + " 失败", r) + (r.blocked === "engine-busy" ? "(引擎正占用该包:先禁用该插件并重启引擎,再卸载)" : ""), r.blocked === "engine-busy" ? "warn" : "bad");
2641
+ return;
2642
+ }
2643
+ toast("已卸载 " + b.name + (r.message ? ":" + r.message : "(重启引擎后生效)"), "ok");
2644
+ if (Array.isArray(r.steps)) { renderSteps(r.steps); revealPanel("stepPanel"); }
2548
2645
  await loadBundles();
2549
2646
  });
2550
- btn.disabled = false;
2647
+ setBusy(btn, false);
2551
2648
  }
2552
- async function loadBundles(){
2649
+ async function loadBundles(announce){
2553
2650
  return guard(async function(){
2554
2651
  var r = await api("/plugins/api/bundles");
2555
- if (!r.ok) { toast(r.error || "读取 bundle 失败", "bad"); return; }
2652
+ if (!r.ok) { toast(failText("读取插件列表失败", r), "bad"); return; }
2556
2653
  bundles = (r.bundles || []).map(function(b){ return { name: b.name, enabled: b.enabled, core: b.core, self: b.name === "dsh-drydock" }; });
2557
2654
  renderRows();
2655
+ if (announce) {
2656
+ var users = bundles.filter(function(b){ return !b.core; }).length;
2657
+ var on = bundles.filter(function(b){ return b.enabled; }).length;
2658
+ toast("已刷新:共 " + bundles.length + " 个组件(用户插件 " + users + " 个,已启用 " + on + " 个)", "ok");
2659
+ }
2558
2660
  });
2559
2661
  }
2560
- async function refreshUpdates(showPanel){
2662
+ async function refreshUpdates(opts){
2663
+ opts = opts || {};
2664
+ var showPanel = opts.showPanel !== false;
2665
+ var announce = opts.announce !== false;
2561
2666
  return guard(async function(){
2562
- var btn = document.getElementById("checkUpdBtn");
2563
- btn.disabled = true;
2667
+ if (announce) toast("正在检查更新:逐个比对用户插件的最新版本…", "warn");
2564
2668
  var r = await api("/plugins/api/updates");
2565
- btn.disabled = false;
2566
- if (!r.ok) { toast(r.error || "检查更新失败", "bad"); return; }
2669
+ if (!r.ok) { toast(failText("检查更新失败", r), "bad"); return; }
2567
2670
  updates = r.updates || [];
2568
- var n = updates.filter(function(u){ return u.needsUpdate; }).length;
2569
- toast(n ? "发现 " + n + " 个可更新插件" : "全部用户插件已是最新", n ? "warn" : "ok");
2671
+ var pending = updates.filter(function(u){ return u.needsUpdate; });
2672
+ var n = pending.length;
2673
+ if (announce) {
2674
+ var names = pending.slice(0, 3).map(function(u){ return u.name; }).join("、");
2675
+ toast(n
2676
+ ? "发现 " + n + " 个可更新插件:" + names + (n > 3 ? " 等" : "") + "(结果在「更新检查结果」卡片)"
2677
+ : "全部 " + updates.length + " 个用户插件已是最新", n ? "warn" : "ok");
2678
+ }
2570
2679
  renderRows();
2571
- if (showPanel !== false) renderUpdateRows();
2680
+ if (showPanel) renderUpdateRows();
2681
+ if (showPanel) revealPanel("updPanel");
2572
2682
  });
2573
2683
  }
2574
2684
  async function runHealth(){
2575
2685
  return guard(async function(){
2576
- var btn = document.getElementById("healthBtn");
2577
- btn.disabled = true;
2686
+ toast("正在做 mod 体检(只读:preflight 校验 + 引擎日志末尾 256KB)…", "warn");
2578
2687
  var r = await api("/plugins/api/health");
2579
- btn.disabled = false;
2580
- if (!r.ok) { toast(r.error || "体检失败", "bad"); return; }
2688
+ if (!r.ok) { toast(failText("mod 体检失败", r), "bad"); return; }
2689
+ var reportRows = r.rows || [];
2690
+ var gi = r.globalIssues || [];
2691
+ var broken = reportRows.filter(function(x){ return x.verdict === "broken"; });
2692
+ var suspect = reportRows.filter(function(x){ return x.verdict === "suspect"; });
2581
2693
  var rows = document.getElementById("healthRows");
2582
- var panel = document.getElementById("healthPanel");
2583
2694
  rows.textContent = "";
2584
- panel.classList.add("open");
2585
- (r.rows || []).forEach(function(row){
2695
+ reportRows.forEach(function(row){
2586
2696
  var item = el("div", "rowitem");
2587
2697
  var meta = el("div", "meta");
2588
2698
  var line = el("div", "name", null);
@@ -2596,7 +2706,6 @@ async function runHealth(){
2596
2706
  rows.appendChild(item);
2597
2707
  });
2598
2708
  // rc.2 P2-4:非 bundle 归属的 preflight 问题与未识别日志错误 → 单独区块
2599
- var gi = r.globalIssues || [];
2600
2709
  if (gi.length) {
2601
2710
  var ghead = el("div", "rowitem");
2602
2711
  ghead.appendChild(el("b", "warn", "⚠ 全局问题(不属于任何已装 bundle,勿按插件处理)"));
@@ -2611,46 +2720,71 @@ async function runHealth(){
2611
2720
  });
2612
2721
  }
2613
2722
  document.getElementById("healthHint").textContent = "日志:" + (r.logPath || "") + ";体检只读(preflight 校验 + 日志末尾 256KB 聚合,30s 缓存),不改任何文件。";
2723
+ var healthy = reportRows.length - broken.length - suspect.length;
2724
+ var head = "体检完成:" + reportRows.length + " 个组件(正常 " + healthy + " / 可疑 " + suspect.length + " / 异常 " + broken.length + ")" + (gi.length ? ",另有 " + gi.length + " 条全局问题" : "");
2725
+ if (!reportRows.length) toast("体检完成:profile 里没有已装组件(「用户插件」列表为空就是原因)", "warn");
2726
+ else if (broken.length) toast(head + ";异常:" + broken.slice(0, 3).map(function(x){ return x.name; }).join("、") + (broken.length > 3 ? " 等" : ""), "bad");
2727
+ else if (suspect.length || gi.length) toast(head, "warn");
2728
+ else toast(head + ",全部正常", "ok");
2729
+ revealPanel("healthPanel");
2614
2730
  });
2615
2731
  }
2616
2732
  document.getElementById("q").addEventListener("input", renderRows);
2617
- document.getElementById("refreshBtn").addEventListener("click", loadBundles);
2618
- document.getElementById("checkUpdBtn").addEventListener("click", function(){ refreshUpdates(true); });
2619
- document.getElementById("healthBtn").addEventListener("click", runHealth);
2733
+ document.getElementById("refreshBtn").addEventListener("click", function(){
2734
+ return withBusy(this, "刷新中…", function(){ return loadBundles(true); });
2735
+ });
2736
+ document.getElementById("checkUpdBtn").addEventListener("click", function(){
2737
+ return withBusy(this, "检查中…", function(){ return refreshUpdates({ showPanel: true, announce: true }); });
2738
+ });
2739
+ document.getElementById("healthBtn").addEventListener("click", function(){
2740
+ return withBusy(this, "体检中…", function(){ return runHealth(); });
2741
+ });
2620
2742
  document.getElementById("restartBtn").addEventListener("click", async function(){
2621
- this.disabled = true;
2622
- await guard(async function(){
2623
- var okGo = await confirmBox("重启引擎", "停旧引擎 → 拉起新引擎(失败条目自动隔离一次)→ 等握手。期间引擎 ${enginePort} 会短暂不可用。", "重启");
2624
- if (!okGo) { document.getElementById("restartBtn").disabled = false; return; }
2625
- toast("重启引擎中…", "warn");
2626
- var r = await api("/plugins/api/engine/restart", {});
2627
- toast(r.message || (r.ok ? "引擎已重启。" : "重启失败。"), r.ok ? "ok" : "bad");
2628
- setEngineState(r.ok);
2629
- // G03:entryUrl=null 时的降级指引(不渲染假 token 链接)
2630
- if (r.ok && r.entryUrl) toast("登录链接已就绪(含 token),可直接打开主界面。", "ok");
2631
- else if (r.ok) toast("未捕获到本次启动的登录链接:① 已登录过的浏览器直接打开 http://127.0.0.1:" + ENGINE_PORT + "/(cookie 仍有效);② 新浏览器请看引擎控制台输出的 dsh web: …?token=…,或到 ~/.dsh/logs/web.log 末尾查找最后一次启动追加的链接。", "warn");
2632
- });
2633
- document.getElementById("restartBtn").disabled = false;
2743
+ setBusy(this, true, "重启中…");
2744
+ try {
2745
+ await guard(async function(){
2746
+ var okGo = await confirmBox("重启引擎", "停旧引擎 → 拉起新引擎(失败条目自动隔离一次)→ 等握手。期间引擎 ${enginePort} 会短暂不可用。", "重启");
2747
+ if (!okGo) { toast("已取消重启引擎", "warn"); return; }
2748
+ toast("正在重启引擎(停旧 → 拉起 → 握手,最长约 30s)…", "warn");
2749
+ var r = await api("/plugins/api/engine/restart", {});
2750
+ if (r.ok) toast("引擎已重启,http://127.0.0.1:" + ENGINE_PORT + "/ 可访问" + (r.entryUrl ? ";登录链接已就绪,可直接打开主界面。" : "。"), "ok");
2751
+ else toast(failText("重启引擎失败", r), "bad");
2752
+ setEngineState(r.ok);
2753
+ // G03:entryUrl=null 时的降级指引(不渲染假 token 链接)
2754
+ if (r.ok && !r.entryUrl) toast("未捕获到本次启动的登录链接:① 已登录过的浏览器直接打开 http://127.0.0.1:" + ENGINE_PORT + "/(cookie 仍有效);② 新浏览器请看引擎控制台输出的 dsh web: …?token=…,或到 ~/.dsh/logs/web.log 末尾查找最后一次启动追加的链接。", "warn");
2755
+ });
2756
+ } finally {
2757
+ setBusy(document.getElementById("restartBtn"), false);
2758
+ }
2634
2759
  });
2635
2760
  document.getElementById("stopBtn").addEventListener("click", async function(){
2636
- this.disabled = true;
2637
- await guard(async function(){
2638
- var okGo = await confirmBox("停止本启动器", "启动器进程将优雅退出并清理 pid 文件;引擎与本页面不受影响,重新打开 ${launcherPort} 会重新拉起启动器。", "停止");
2639
- if (!okGo) { document.getElementById("stopBtn").disabled = false; return; }
2640
- var r = await api("/api/launcher/stop", {});
2641
- toast(r.message || "启动器即将退出。", "warn");
2642
- setTimeout(function(){ location.reload(); }, 1200);
2643
- });
2644
- document.getElementById("stopBtn").disabled = false;
2761
+ setBusy(this, true, "停止中…");
2762
+ try {
2763
+ await guard(async function(){
2764
+ var okGo = await confirmBox("停止本启动器", "启动器进程将优雅退出并清理 pid 文件;引擎与本页面不受影响,重新打开 ${launcherPort} 会重新拉起启动器。", "停止");
2765
+ if (!okGo) { toast("已取消停止启动器", "warn"); return; }
2766
+ toast("正在停止本启动器(引擎与本页面不受影响)…", "warn");
2767
+ var r = await api("/api/launcher/stop", {});
2768
+ toast(r.message || "启动器即将退出;重新打开本页地址会重新拉起启动器。", r.ok === false ? "bad" : "warn");
2769
+ setTimeout(function(){ location.reload(); }, 1200);
2770
+ });
2771
+ } finally {
2772
+ setBusy(document.getElementById("stopBtn"), false);
2773
+ }
2645
2774
  });
2646
2775
  document.getElementById("userRows").addEventListener("change", async function(ev){
2647
2776
  var input = ev.target;
2648
2777
  if (!input || input.dataset.name === undefined) return;
2778
+ var name = input.dataset.name;
2779
+ var want = Boolean(input.checked);
2780
+ var row = input.closest ? input.closest(".rowitem") : null;
2649
2781
  input.disabled = true;
2782
+ if (row) row.classList.add("busy");
2783
+ toast((want ? "正在启用 " : "正在禁用 ") + name + "…", "warn");
2650
2784
  await guard(async function(){
2651
- var r = await api("/plugins/api/bundles", { name: input.dataset.name, action: input.checked ? "enable" : "disable" });
2652
- if (!r.ok) { toast(r.error || "操作失败", "bad"); }
2653
- else toast(r.message || "已更新(重启引擎后生效)", r.changed === false ? "warn" : "ok");
2785
+ var r = await api("/plugins/api/bundles", { name: name, action: want ? "enable" : "disable" });
2786
+ if (!r.ok) toast(failText((want ? "启用 " : "禁用 ") + name + " 失败", r), "bad");
2787
+ else toast((want ? "已启用 " : "已禁用 ") + name + (r.changed === false ? "(本来就是这个状态,未改动)" : ",重启引擎后生效"), r.changed === false ? "warn" : "ok");
2654
2788
  });
2655
2789
  await loadBundles();
2656
2790
  });
@@ -2669,7 +2803,12 @@ async function loadEngine(){
2669
2803
  });
2670
2804
  }
2671
2805
  loadBundles(); loadEngine();
2806
+ // U1:结果区(#updPanel / #healthPanel / #stepPanel)已前移到用户插件列表之上,
2807
+ // 因此 #health 直达既能看见结果,也不会被长列表顶出视口;再靠 revealPanel 的滚动+高亮给落点。
2672
2808
  if (location.hash === "#health") runHealth(); // 3080 RescuePanel 的「mod 体检」入口直达(/plugins#health)
2809
+ window.addEventListener("hashchange", function(){
2810
+ if (location.hash === "#health") runHealth();
2811
+ });
2673
2812
  </script>
2674
2813
  </div></body></html>`;
2675
2814
  }
@@ -2998,5 +3137,7 @@ export {
2998
3137
  main, parseArgs, reportStatus, startServer, uninstallAutostart, writeShim,
2999
3138
  // rc.2 测试面:单测直接驱动这些函数(不经过 HTTP)
3000
3139
  CORE_BUNDLES, MANAGER_SELF_NAME, PKG_NAME_RE, runPnpm, writeFileAtomic, engineBusyGate,
3001
- uninstallPackageTransactional, updatePackage, checkUpdates, healthReport, restartEngine, ensureLauncherCmd
3140
+ uninstallPackageTransactional, updatePackage, checkUpdates, healthReport, restartEngine, ensureLauncherCmd,
3141
+ // U1 测试面:兜底页 HTML 静态断言(test-ux.mjs)直接检查页面结构,不用起浏览器
3142
+ pluginsPageHtml
3002
3143
  };