dsh-modpack-kit 0.2.1 → 0.2.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/client.js CHANGED
@@ -201,6 +201,72 @@ window.__ModuleLoader__.load({
201
201
  return data
202
202
  }
203
203
 
204
+ // 插件市场的侧栏入口(/dsh-market/sidebar-entry):本条开关就是替市场把 enabled 关掉。
205
+ // 市场那一行是它自己的偏好,存在 profile 的 .dsh-market/state.json 里;我们只写这一个键。
206
+ const MARKET_SIDEBAR_ROUTE = "/dsh-market/sidebar-entry"
207
+ async function readMarketSidebar() {
208
+ try {
209
+ const res = await fetch(MARKET_SIDEBAR_ROUTE, { headers: { Accept: "application/json" }, credentials: "same-origin" })
210
+ if (!res.ok) return null
211
+ const data = await res.json()
212
+ return data && typeof data.enabled === "boolean" ? data : null
213
+ } catch (e) { return null }
214
+ }
215
+ async function writeMarketSidebar(enabled) {
216
+ const res = await fetch(MARKET_SIDEBAR_ROUTE, {
217
+ method: "POST",
218
+ headers: { "Content-Type": "application/json" },
219
+ credentials: "same-origin",
220
+ body: JSON.stringify({ enabled: enabled === true }),
221
+ })
222
+ let data = null
223
+ try { data = await res.json() } catch (e) { data = null }
224
+ if (!res.ok) {
225
+ const error = new Error((data && (data.error || data.message)) || ("插件市场拒绝了这次修改(HTTP " + res.status + ")"))
226
+ error.status = res.status
227
+ throw error
228
+ }
229
+ return data
230
+ }
231
+
232
+ // 开机把市场的侧栏入口关一次:插件加载时拉 /status 顺带执行,不必等用户点开某一栏。
233
+ let marketSidebarForced = false
234
+ async function enforceMarketSidebarOff() {
235
+ if (marketSidebarForced) return
236
+ const current = await readMarketSidebar()
237
+ if (!current) return
238
+ if (current.enabled !== true) { marketSidebarForced = true; return }
239
+ try { await writeMarketSidebar(false); marketSidebarForced = true } catch (e) { marketSidebarForced = true }
240
+ }
241
+
242
+ // 解除卡顿插件(dsh-unlag):装了才有按钮。只读它的 /state;按一次要带它要的头。
243
+ const UNLAG_STATE_ROUTE = "/dsh-unlag/state"
244
+ async function detectUnlag() {
245
+ try {
246
+ const res = await fetch(UNLAG_STATE_ROUTE, { headers: { Accept: "application/json" }, credentials: "same-origin" })
247
+ if (!res.ok) return null
248
+ const data = await res.json()
249
+ return data && typeof data.version === "string" ? data : null
250
+ } catch (e) { return null }
251
+ }
252
+ async function pressUnlag() {
253
+ const requestId = "modpack-" + Date.now().toString(36) + "-" + Math.random().toString(36).slice(2, 8)
254
+ const res = await fetch("/dsh-unlag/reload?requestId=" + encodeURIComponent(requestId), {
255
+ method: "POST",
256
+ headers: { "Content-Type": "application/json", "x-dsh-unlag": "1" },
257
+ credentials: "same-origin",
258
+ body: JSON.stringify({}),
259
+ })
260
+ let data = null
261
+ try { data = await res.json() } catch (e) { data = null }
262
+ if (!res.ok) {
263
+ const error = new Error((data && (data.status || data.message || data.error)) || ("解除卡顿拒绝了这次请求(HTTP " + res.status + ")"))
264
+ error.status = res.status
265
+ throw error
266
+ }
267
+ return data
268
+ }
269
+
204
270
  // 宿主有没有原生的目录选择器:有就能点「浏览文件夹…」,没有就退回手填
205
271
  let pickDirectoryHost = null
206
272
 
@@ -258,7 +324,7 @@ window.__ModuleLoader__.load({
258
324
  }
259
325
 
260
326
  function Switch(props) {
261
- return h("label", { style: { display: "inline-flex", gap: "6px", alignItems: "center", fontSize: "12.5px", cursor: props.disabled ? "not-allowed" : "pointer", opacity: props.disabled ? 0.45 : 1 } },
327
+ return h("label", { title: props.title || undefined, style: { display: "inline-flex", gap: "6px", alignItems: "center", fontSize: "12.5px", cursor: props.disabled ? "not-allowed" : "pointer", opacity: props.disabled ? 0.45 : 1 } },
262
328
  h("input", { type: "checkbox", checked: !!props.checked, disabled: !!props.disabled, onChange: (e) => props.onChange(e.target.checked) }),
263
329
  props.label)
264
330
  }
@@ -411,18 +477,78 @@ window.__ModuleLoader__.load({
411
477
 
412
478
  // 进度窗:可以拖,拖过的位置记在浏览器本地;没有任务时自动收起,只留一枚唤出按钮。
413
479
  const DOCK_POS_KEY = "dsh-modpack-kit:dock-pos"
480
+ // localStorage 里只存相对坐标(fx/fy,0~1),换窗口大小时按比例还原一次;
481
+ // 界面上的位置一律用像素,并且不存任何「算出来的高度 / 要不要向上长」这类状态。
414
482
  function readDockPos() {
415
483
  try {
416
484
  const raw = typeof localStorage !== "undefined" ? localStorage.getItem(DOCK_POS_KEY) : null
417
485
  if (!raw) return null
418
486
  const parsed = JSON.parse(raw)
419
487
  if (!parsed || typeof parsed !== "object") return null
420
- if (!Number.isFinite(Number(parsed.x)) || !Number.isFinite(Number(parsed.y))) return null
421
- return { x: Math.max(0, Math.round(Number(parsed.x))), y: Math.max(0, Math.round(Number(parsed.y))) }
488
+ if (Number.isFinite(Number(parsed.fx)) && Number.isFinite(Number(parsed.fy))) {
489
+ return { fx: Math.max(0, Math.min(1, Number(parsed.fx))), fy: Math.max(0, Math.min(1, Number(parsed.fy))) }
490
+ }
491
+ // 老版本存的是像素:按当前视口折算成相对坐标,迁移一次就够了
492
+ if (Number.isFinite(Number(parsed.x)) && Number.isFinite(Number(parsed.y))) {
493
+ const vp = viewportSize()
494
+ return { fx: Math.max(0, Math.min(1, Number(parsed.x) / vp.width)), fy: Math.max(0, Math.min(1, Number(parsed.y) / vp.height)) }
495
+ }
496
+ return null
422
497
  } catch { return null }
423
498
  }
424
499
  function writeDockPos(pos) {
425
- try { if (typeof localStorage !== "undefined" && pos) localStorage.setItem(DOCK_POS_KEY, JSON.stringify(pos)) } catch { /* 存不了就算了,不影响本场使用 */ }
500
+ try {
501
+ if (typeof localStorage === "undefined" || !pos) return
502
+ const vp = viewportSize()
503
+ localStorage.setItem(DOCK_POS_KEY, JSON.stringify({
504
+ fx: Math.max(0, Math.min(1, Number(pos.x) / vp.width)),
505
+ fy: Math.max(0, Math.min(1, Number(pos.y) / vp.height)),
506
+ }))
507
+ } catch { /* 存不了就算了,不影响本场使用 */ }
508
+ }
509
+ // 召回:把存在浏览器里的位置清掉,回到默认的右下角
510
+ function clearDockPos() {
511
+ try {
512
+ if (typeof localStorage !== 'undefined') localStorage.removeItem(DOCK_POS_KEY)
513
+ } catch { /* 清不掉也没关系,下一次拖动会覆盖 */ }
514
+ }
515
+ // DSH 顶栏 / 标签行大约占这么高:窗口别停在那上面,否则会盖住界面的按钮
516
+ const DOCK_TOP_INSET = 56
517
+ const DOCK_MARGIN = 12 // 离视口边缘至少留这么宽
518
+ const DOCK_MIN_LEFT = 4
519
+ const DOCK_W = 300 // 收起、展开同一个宽度,简单可预期
520
+ const DOCK_OPEN_MAX_H = 420 // 展开时最高这么多,再多就在窗里滚动
521
+ const DOCK_HEAD_H = 44 // 标题行的占位高度:夹边只按它算,展开多高由可用空间决定
522
+ const clampNum = (value, min, max) => Math.max(min, Math.min(value, max))
523
+ // 和布局有关的只有这一件事:把像素位置夹回可见区。
524
+ // 没有「自动判定向上/向下」、也没有自动算高度——拖到哪就是哪,超出才夹回来,默认落右下角。
525
+ function clampDockPos(pos, viewport, size) {
526
+ const vw = Math.max(1, Number(viewport && viewport.width) || 0)
527
+ const vh = Math.max(1, Number(viewport && viewport.height) || 0)
528
+ const w = Math.max(1, Number(size && size.w) || DOCK_W)
529
+ const h = Math.max(1, Number(size && size.h) || 44)
530
+ const x = pos && Number.isFinite(Number(pos.x)) ? Number(pos.x) : vw - w - DOCK_MARGIN
531
+ const y = pos && Number.isFinite(Number(pos.y)) ? Number(pos.y) : vh - h - DOCK_MARGIN
532
+ return {
533
+ x: Math.round(clampNum(x, DOCK_MIN_LEFT, Math.max(DOCK_MIN_LEFT, vw - w - DOCK_MIN_LEFT))),
534
+ y: Math.round(clampNum(y, DOCK_TOP_INSET, Math.max(DOCK_TOP_INSET, vh - h - DOCK_MIN_LEFT))),
535
+ }
536
+ }
537
+ // 存下来的相对坐标 -> 像素(窗口大小变了就按比例落回去)
538
+ function dockFromFractions(saved, viewport) {
539
+ if (!saved) return null
540
+ const vw = Math.max(1, Number(viewport && viewport.width) || 0)
541
+ const vh = Math.max(1, Number(viewport && viewport.height) || 0)
542
+ return { x: clampNum(Number(saved.fx) || 0, 0, 1) * vw, y: clampNum(Number(saved.fy) || 0, 0, 1) * vh }
543
+ }
544
+ // 召回:标签行那个显眼按钮通过它把进度窗叫回默认位置
545
+ const dockReset = { subs: new Set() }
546
+ function requestDockReset() {
547
+ for (const fn of Array.from(dockReset.subs)) { try { fn() } catch { /* 某个订阅坏了不该影响别的 */ } }
548
+ }
549
+ function subscribeDockReset(fn) {
550
+ dockReset.subs.add(fn)
551
+ return () => { dockReset.subs.delete(fn) }
426
552
  }
427
553
  function viewportSize() {
428
554
  const width = typeof window !== "undefined" && Number(window.innerWidth) ? Number(window.innerWidth) : 1280
@@ -438,13 +564,26 @@ window.__ModuleLoader__.load({
438
564
  useEffect(() => {
439
565
  setCleared((prev) => (prev.length === 0 ? prev : prev.filter((id) => given.some((job) => job.id === id))))
440
566
  }, [given])
441
- const [pos, setPos] = useState(readDockPos())
567
+ const [pos, setPos] = useState(() => dockFromFractions(readDockPos(), viewportSize()))
442
568
  const [pinned, setPinned] = useState(false) // 手动唤出:没有任务时也显示
443
569
  const [hidden, setHidden] = useState(false) // 手动收起:连进行中的也先藏起来
444
570
  const [open, setOpen] = useState(false)
445
571
  const [dockMsg, setDockMsg] = useState("")
446
572
  const dragRef = useRef(null)
447
573
  const boxRef = useRef(null)
574
+ const headerRef = useRef(null)
575
+ const pillRef = useRef(null)
576
+ // 窗口大小变了要重算贴边位置,所以留一个 tick 触发重渲染
577
+ const [, setViewportTick] = useState(0)
578
+ // 标签行的「召回」把窗口叫回右下角默认位置
579
+ useEffect(() => subscribeDockReset(() => {
580
+ // 召回是「兜底入口」:任何一步出错都不能把整个面板带崩,所以逐条 try 住
581
+ try { clearDockPos() } catch { /* 清不掉照样能显示 */ }
582
+ setPos(null)
583
+ setOpen(false)
584
+ setHidden(false)
585
+ setPinned(true)
586
+ }), [])
448
587
  const running = jobs.filter((job) => job.status === "running")
449
588
  const visible = !hidden && (pinned || running.length > 0)
450
589
 
@@ -453,12 +592,19 @@ window.__ModuleLoader__.load({
453
592
  if (running.length > 0) { setHidden(false) }
454
593
  }, [running.length])
455
594
 
456
- const startDrag = (event) => {
595
+ useEffect(() => {
596
+ if (typeof window === "undefined" || typeof window.addEventListener !== "function") return undefined
597
+ const onResize = () => setViewportTick((n) => n + 1)
598
+ window.addEventListener("resize", onResize)
599
+ return () => { window.removeEventListener("resize", onResize) }
600
+ }, [])
601
+ // 最小化的胶囊自己也是一个按钮,所以这一路要放行:不然 pointer 事件会被当成「按在按钮上」直接丢掉。
602
+ const startDrag = (event, element, allowOnButton) => {
457
603
  if (!event || typeof event.clientX !== "number") return
458
604
  // 按在按钮上就别当拖动:否则指针捕获会把 click 抢走,按钮点不到,
459
605
  // 而且抬手时还会顺带把窗口展开/收起(就是「判定重叠」那个毛病)
460
- if (event.target && typeof event.target.closest === "function" && event.target.closest("button")) return
461
- const el = boxRef.current
606
+ if (!allowOnButton && event.target && typeof event.target.closest === "function" && event.target.closest("button")) return
607
+ const el = element || boxRef.current
462
608
  const rect = el && el.getBoundingClientRect ? el.getBoundingClientRect() : { left: 0, top: 0, width: 0, height: 0 }
463
609
  dragRef.current = {
464
610
  dx: event.clientX - rect.left,
@@ -477,12 +623,13 @@ window.__ModuleLoader__.load({
477
623
  const moveDrag = (event) => {
478
624
  const drag = dragRef.current
479
625
  if (!drag || !event || typeof event.clientX !== "number") return
480
- const { width, height } = viewportSize()
481
- const left = Math.min(Math.max(4, event.clientX - drag.dx), Math.max(4, width - drag.width - 4))
482
- const top = Math.min(Math.max(4, event.clientY - drag.dy), Math.max(4, height - drag.height - 4))
483
- if (Math.abs(left - drag.startX) > 3 || Math.abs(top - drag.startY) > 3) drag.moved = true
484
- drag.last = { x: Math.round(left), y: Math.round(top) }
485
- setPos(drag.last)
626
+ const vp = viewportSize()
627
+ // 就用指针位移 + 起手时的窗口尺寸,别在拖动过程中再引用任何会被自己改掉的布局值
628
+ const size = { w: drag.width || DOCK_W, h: DOCK_HEAD_H }
629
+ const next = clampDockPos({ x: event.clientX - drag.dx, y: event.clientY - drag.dy }, vp, size)
630
+ if (Math.abs(next.x - drag.startX) > 3 || Math.abs(next.y - drag.startY) > 3) drag.moved = true
631
+ drag.last = next
632
+ setPos(next)
486
633
  }
487
634
  const endDrag = () => {
488
635
  const drag = dragRef.current
@@ -492,12 +639,30 @@ window.__ModuleLoader__.load({
492
639
  if (drag.last) writeDockPos(drag.last)
493
640
  return
494
641
  }
495
- // 没拖动就是点了一下标题:展开 / 收起
496
- setOpen((prev) => !prev)
642
+ // 没拖动就是点了一下标题:展开 / 收起。
643
+ // 不预算任何尺寸与位置:点一下只是开/关,位置永远由 pos + clampDockPos 决定,不会跳。
644
+ setOpen(!open)
645
+ }
646
+ // 胶囊抬手:拖过就记住位置,没拖就是「打开」
647
+ const endPillDrag = () => {
648
+ const drag = dragRef.current
649
+ if (!drag) return
650
+ dragRef.current = null
651
+ if (drag.moved) {
652
+ if (drag.last) writeDockPos(drag.last)
653
+ return
654
+ }
655
+ setPinned(true)
656
+ setHidden(false)
497
657
  }
498
658
 
499
659
  if (!visible) {
500
- const anchor = pos || null
660
+ const vp = viewportSize()
661
+ const pillW = 132
662
+ const pillH = 42
663
+ // 胶囊也用相对坐标现算:换窗口大小它跟着走
664
+ const pillAt = clampDockPos(pos, vp, { w: pillW, h: pillH })
665
+ const pillPos = { left: pillAt.x + "px", top: pillAt.y + "px" }
501
666
  const summonStyle = {
502
667
  position: "fixed",
503
668
  zIndex: 70,
@@ -510,12 +675,22 @@ window.__ModuleLoader__.load({
510
675
  background: "var(--dsw-alias-surface-1, rgba(24,26,31,.97))",
511
676
  color: "var(--dsw-alias-label-primary)",
512
677
  boxShadow: "0 6px 18px rgba(0,0,0,.28)",
513
- cursor: "pointer",
678
+ cursor: pos ? "grab" : "pointer",
514
679
  fontSize: "12px",
515
- ...(anchor ? { left: anchor.x + "px", top: anchor.y + "px" } : { right: "16px", bottom: "16px" }),
680
+ touchAction: "none",
681
+ userSelect: "none",
682
+ ...pillPos,
516
683
  }
517
684
  const badge = running.length || jobs.length
518
- return h("button", { style: summonStyle, title: "打开整合包进度窗", onClick: () => { setPinned(true); setHidden(false) } },
685
+ return h("button", {
686
+ ref: pillRef,
687
+ style: summonStyle,
688
+ title: pos ? "打开整合包进度窗(按住可以拖到别处)" : "打开整合包进度窗(按住可以拖到别处)",
689
+ onPointerDown: (event) => startDrag(event, pillRef.current, true),
690
+ onPointerMove: moveDrag,
691
+ onPointerUp: endPillDrag,
692
+ onPointerCancel: endPillDrag,
693
+ },
519
694
  h("span", { style: { width: "7px", height: "7px", borderRadius: "99px", background: running.length ? "#4C7DF0" : "rgba(127,163,245,.5)" } }),
520
695
  "进度",
521
696
  badge ? h("span", { style: { ...hint, marginLeft: "0", fontVariantNumeric: "tabular-nums" } }, String(badge)) : null)
@@ -564,14 +739,20 @@ window.__ModuleLoader__.load({
564
739
  // 只要有一条不是「在跑」或「停在风险点」,就给清空入口(状态再怪也算收尾)
565
740
  const finished = jobs.filter((job) => job.status !== "running" && job.status !== "paused")
566
741
 
742
+ // 一帧算完全部布局:位置、宽度、高度、向上还是向下,全部来自当前视口 + 量出来的尺寸。
743
+ // 夹边永远只按「标题行 + 固定宽度」算,所以展开不会把窗口顶上去(高度自己缩,位置不动)
744
+ const vp = viewportSize()
745
+ const placed = clampDockPos(pos, vp, { w: DOCK_W, h: DOCK_HEAD_H })
746
+ const dockPos = { left: placed.x + "px", top: placed.y + "px" }
747
+ const openMaxH = Math.max(160, Math.min(DOCK_OPEN_MAX_H, vp.height - placed.y - DOCK_MARGIN))
567
748
  return h("div", {
568
749
  ref: boxRef,
569
750
  style: {
570
751
  position: "fixed",
571
752
  zIndex: 70,
572
- ...(pos ? { left: pos.x + "px", top: pos.y + "px" } : { right: "16px", bottom: "16px" }),
573
- width: open ? "380px" : "288px",
574
- maxHeight: open ? "58vh" : "none",
753
+ ...dockPos,
754
+ width: DOCK_W + "px",
755
+ maxHeight: open ? openMaxH + "px" : "none",
575
756
  overflow: "auto",
576
757
  boxSizing: "border-box",
577
758
  padding: "10px 12px",
@@ -585,6 +766,7 @@ window.__ModuleLoader__.load({
585
766
  },
586
767
  },
587
768
  h("div", {
769
+ ref: headerRef,
588
770
  style: { display: "flex", alignItems: "center", gap: "8px", cursor: "grab", userSelect: "none", touchAction: "none" },
589
771
  title: "按住可以拖动;点一下展开或收起",
590
772
  onPointerDown: startDrag,
@@ -1708,6 +1890,7 @@ window.__ModuleLoader__.load({
1708
1890
  // 记录用本地状态:删一条不用整页重读,删完立刻看到结果
1709
1891
  const [history, setHistory] = useState((((props.status || {}).history) || []).slice())
1710
1892
  const [historyMsg, setHistoryMsg] = useState("")
1893
+ const [marketSidebarMsg, setMarketSidebarMsg] = useState("")
1711
1894
  const dropHistory = async (item, all) => {
1712
1895
  setHistoryMsg("")
1713
1896
  try {
@@ -1736,6 +1919,20 @@ window.__ModuleLoader__.load({
1736
1919
  } finally { setBusy(false) }
1737
1920
  }
1738
1921
  const setField = (key, value) => setCfg((prev) => ({ ...(prev || {}), [key]: value }))
1922
+ // 打开就替市场把侧栏入口关掉;关掉就还回去。市场没装就只提示,不报错。
1923
+ const toggleMarketSidebar = async (on) => {
1924
+ setMarketSidebarMsg("")
1925
+ setField("forceHideMarketSidebar", on)
1926
+ await patch({ forceHideMarketSidebar: on })
1927
+ const current = await readMarketSidebar()
1928
+ if (!current) { setMarketSidebarMsg("没装插件市场(dshmarket),或者在旧版本上没有这个入口。"); return }
1929
+ try {
1930
+ await writeMarketSidebar(!on)
1931
+ setMarketSidebarMsg(on ? "已关掉:市场侧栏那一行现在不显示。" : "已恢复:市场侧栏那一行按它的设置显示。")
1932
+ } catch (e) {
1933
+ setMarketSidebarMsg((e && e.message) || String(e))
1934
+ }
1935
+ }
1739
1936
  // 体积上限按 MB 输:先把输入框里的原始文本存着,点「保存数值」才换算成字节,
1740
1937
  // 这样不会每敲一个数字就四舍五入一次(以前会越打越多,最后存成 25 GB 这种值)。
1741
1938
  const [limitDraft, setLimitDraft] = useState(String(Math.round(((props.status && props.status.config && props.status.config.maxPackBytes) || 256 * 1048576) / 1048576)))
@@ -1876,6 +2073,15 @@ window.__ModuleLoader__.load({
1876
2073
  h(Switch, { checked: cfg.showInSettings !== false, disabled: placementLocked("showInSettings"), label: "在设置里显示(插件设置页内一栏「整合包」)" + (placementLocked("showInSettings") ? "(最后剩这一个,不能关)" : ""), onChange: (v) => savePlacement("showInSettings", v) }),
1877
2074
  h(Switch, { checked: cfg.showInSidebar !== false, disabled: placementLocked("showInSidebar"), label: "在侧边栏显示(左侧栏「整合包」入口)" + (placementLocked("showInSidebar") ? "(最后剩这一个,不能关)" : ""), onChange: (v) => savePlacement("showInSidebar", v) }),
1878
2075
  h(Switch, { checked: cfg.showInPluginsTab === true, disabled: placementLocked("showInPluginsTab"), label: "在插件页内显示(与插件市场同一位置,单开一栏「整合包」)" + (placementLocked("showInPluginsTab") ? "(最后剩这一个,不能关)" : ""), onChange: (v) => savePlacement("showInPluginsTab", v) })),
2076
+ h("div", { style: { ...hint, borderTop: "0.5px solid var(--dsw-alias-border-l2)", paddingTop: "8px", marginTop: "2px" } }, "插件市场自己那一行(与上面整合包的入口无关):"),
2077
+ h(Switch, {
2078
+ checked: cfg.forceHideMarketSidebar === true,
2079
+ label: "强制关闭侧栏里的插件市场显示",
2080
+ title: "每次开机强制显示还关不掉很烦吧",
2081
+ onChange: (v) => toggleMarketSidebar(v),
2082
+ }),
2083
+ h("div", { style: hint }, "只关市场自己的,不动整合包:改的是它存在 .dsh-market/state.json 里的 sidebarEntry,不动它的安装,也不动整合包的入口。"),
2084
+ marketSidebarMsg ? h("div", { style: hint }, marketSidebarMsg) : null,
1879
2085
  saved ? h("span", { style: hint }, saved) : null),
1880
2086
  h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
1881
2087
  h("div", { style: strong }, "插件目录(分类 · 搜索 · 分页)"),
@@ -1905,6 +2111,35 @@ window.__ModuleLoader__.load({
1905
2111
  const embedded = surface === "plugins"
1906
2112
  const [packResult, setPackResult] = useState(() => readPackValue())
1907
2113
  const [focus, setFocus] = useState(0)
2114
+ const [unlag, setUnlag] = useState(null)
2115
+ const [unlagMsg, setUnlagMsg] = useState("")
2116
+ // 解除卡顿是别人家的插件:有就出按钮,没有就什么都不显示。
2117
+ useEffect(() => {
2118
+ let alive = true
2119
+ detectUnlag().then((data) => { if (alive) setUnlag(data) })
2120
+ return () => { alive = false }
2121
+ }, [])
2122
+ const pressUnlagNow = async () => {
2123
+ setUnlagMsg("正在让解除卡顿整理…")
2124
+ try {
2125
+ const data = await pressUnlag()
2126
+ const status = data && (data.status || data.verdict)
2127
+ setUnlagMsg(status ? ("解除卡顿:" + status) : "已请求,稍等一下看结果")
2128
+ } catch (e) {
2129
+ setUnlagMsg((e && e.message) || String(e))
2130
+ }
2131
+ }
2132
+ // 开机把市场的侧栏入口按设置再关一次:市场自己每次启动都会把它打开。
2133
+ const forceHideMarket = !!(status && status.config && status.config.forceHideMarketSidebar === true)
2134
+ useEffect(() => {
2135
+ if (!forceHideMarket) return
2136
+ let alive = true
2137
+ readMarketSidebar().then((data) => {
2138
+ if (!alive || !data || data.enabled !== true) return
2139
+ writeMarketSidebar(false).catch(() => {})
2140
+ })
2141
+ return () => { alive = false }
2142
+ }, [forceHideMarket])
1908
2143
  useEffect(() => subscribePack((value) => { setPackResult(value) }), [])
1909
2144
  const savePackResult = (value) => {
1910
2145
  setPackValue(value)
@@ -1918,6 +2153,42 @@ window.__ModuleLoader__.load({
1918
2153
  setTab("pack")
1919
2154
  setFocus((n) => n + 1)
1920
2155
  }
2156
+ const [refreshing, setRefreshing] = useState(false)
2157
+ const [refreshedAt, setRefreshedAt] = useState(0)
2158
+ const [refreshMsg, setRefreshMsg] = useState("")
2159
+ const [refreshNote, setRefreshNote] = useState("")
2160
+ // 刷新只管整合包自己:重读本插件看到的状态,再把三个面板重挂一次让它们各自重新取数。
2161
+ // 不碰别的插件,也不调「解除卡顿」——那个插件有自己的按钮,各管各的。
2162
+ const doRefresh = async () => {
2163
+ if (refreshing) return
2164
+ setRefreshing(true)
2165
+ setRefreshMsg("")
2166
+ setRefreshNote("")
2167
+ try {
2168
+ if (typeof props.onRefresh === "function") await props.onRefresh()
2169
+ setRefreshNote("已重新读取整合包自己的状态")
2170
+ setRefreshedAt(Date.now())
2171
+ } catch (e) {
2172
+ setRefreshMsg("刷新失败:" + String((e && e.message) || e))
2173
+ } finally {
2174
+ setRefreshing(false)
2175
+ }
2176
+ }
2177
+ const gen = props.gen || 0
2178
+ const refreshBtn = h("button", {
2179
+ type: "button",
2180
+ style: chipBtn,
2181
+ disabled: refreshing,
2182
+ title: "只刷新整合包自己:重新读一遍插件列表、市场目录与进度窗,再把三个面板重挂一次;不调用别的插件",
2183
+ onClick: doRefresh,
2184
+ }, refreshing ? "刷新中…" : (refreshMsg ? "刷新失败" : refreshedAt ? "刷新 ✓" : "刷新"))
2185
+ // 拖到角上挡住界面时用这个:位置清掉、回到右下角默认位,并且强制显示
2186
+ const recallBtn = h("button", {
2187
+ type: "button",
2188
+ style: { ...chipBtn, background: "#4C7DF0", borderColor: "#4C7DF0", color: "#fff", fontWeight: 600 },
2189
+ title: "把进度窗叫回右下角的默认位置(拖到角落挡住了界面就用这个)",
2190
+ onClick: () => { requestDockReset() },
2191
+ }, "召回进度窗")
1921
2192
  const tabs = [
1922
2193
  ["pack", "打包"],
1923
2194
  ["install", "安装 / 导入"],
@@ -1937,11 +2208,26 @@ window.__ModuleLoader__.load({
1937
2208
  }, text)
1938
2209
 
1939
2210
  const panels = [
1940
- tab === "pack" ? h(PackPanel, { status, jobs, result: packResult, setResult: savePackResult, focus }) : null,
1941
- tab === "install" ? h(InstallPanel, { status }) : null,
1942
- tab === "settings" ? h(SettingsPanel, { status }) : null,
2211
+ tab === "pack" ? h(PackPanel, { key: "pack-" + gen, status, jobs, result: packResult, setResult: savePackResult, focus }) : null,
2212
+ tab === "install" ? h(InstallPanel, { key: "install-" + gen, status }) : null,
2213
+ tab === "settings" ? h(SettingsPanel, { key: "settings-" + gen, status }) : null,
1943
2214
  ]
1944
2215
  const footNote = h("div", { style: hint }, "说明:整合包只打包你选择的插件与必要配置。打包与安装安全检测在内存中进行,命中原文不落盘;请遵守插件作者许可证与你所在地区的法律法规。")
2216
+ const unlagNode = unlag
2217
+ ? h("div", { style: row },
2218
+ h("button", {
2219
+ type: "button",
2220
+ style: chipBtn,
2221
+ title: "来自插件市场的 dsh-unlag@" + (unlag.version || "?") + "(不是本插件的功能:装了才有)",
2222
+ onClick: pressUnlagNow,
2223
+ }, "解除卡顿"),
2224
+ unlagMsg ? h("span", { style: hint }, unlagMsg) : null)
2225
+ : null
2226
+ useEffect(() => {
2227
+ if (!refreshedAt) return undefined
2228
+ const timer = setTimeout(() => { setRefreshedAt(0); setRefreshNote("") }, 2400)
2229
+ return () => clearTimeout(timer)
2230
+ }, [refreshedAt])
1945
2231
  const envLine = h("span", { style: { ...hint, marginLeft: "auto" } },
1946
2232
  status ? ("DSH " + (status.dshVersion || "?") + " · 已装 " + ((status.installed || []).length) + " 个 · v" + (status.pluginVersion || "?")) : "读取环境…")
1947
2233
 
@@ -1958,7 +2244,9 @@ window.__ModuleLoader__.load({
1958
2244
  },
1959
2245
  },
1960
2246
  h("div", { style: { maxWidth: "1020px", margin: "0 auto", width: "100%", display: "flex", flexDirection: "column", gap: "10px" } },
1961
- h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)), envLine),
2247
+ h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)), envLine, refreshNote ? h("span", { style: hint }, refreshNote) : null, refreshMsg ? h("span", { style: { ...hint, color: "#ff6b6b" } }, refreshMsg) : null, recallBtn, refreshBtn),
2248
+ unlagNode,
2249
+ unlagNode,
1962
2250
  panels,
1963
2251
  footNote,
1964
2252
  h(RepoFooter, null)),
@@ -1973,7 +2261,7 @@ window.__ModuleLoader__.load({
1973
2261
  h("div", { style: { display: "flex", alignItems: "baseline", gap: "10px", flexWrap: "wrap" } },
1974
2262
  h("h2", { style: { margin: 0, fontSize: "20px", fontWeight: 600 } }, "整合包"),
1975
2263
  h("span", { style: hint }, ((status && status.config && status.config.tagline) || "谁说 dsh 不能整整合包呢?(你说这几个插件整一块不牛逼坏了)"))),
1976
- h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)), envLine),
2264
+ h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)), envLine, refreshNote ? h("span", { style: hint }, refreshNote) : null, refreshMsg ? h("span", { style: { ...hint, color: "#ff6b6b" } }, refreshMsg) : null, recallBtn, refreshBtn),
1977
2265
  panels,
1978
2266
  footNote,
1979
2267
  h(RepoFooter, null)),
@@ -1993,6 +2281,7 @@ window.__ModuleLoader__.load({
1993
2281
  const [status, setStatus] = useState(null)
1994
2282
  const [error, setError] = useState("")
1995
2283
  const [tries, setTries] = useState(0)
2284
+ const [gen, setGen] = useState(0)
1996
2285
  const alive = useRef(true)
1997
2286
  useEffect(() => () => { alive.current = false }, [])
1998
2287
  // 宿主刚起来、会话还在建的时候,第一次可能拿不到状态(401/网络没就绪)。
@@ -2029,7 +2318,18 @@ window.__ModuleLoader__.load({
2029
2318
  return h("div", { style: { padding: "20px 24px", color: "var(--dsw-alias-label-tertiary, #8b909b)", fontSize: "13px" } },
2030
2319
  tries > 0 ? "整合包:还在连 DSH 本体…(自动重试 " + tries + " 次)" : "整合包:读取环境…")
2031
2320
  }
2032
- return h(Home, { status, surface: (props && props.surface) || "sidebar" })
2321
+ // 手动刷新:先重读 status,再把下面几个面板整体重挂一次(gen+1)。
2322
+ // 只重读 status 是不够的:面板里的插件清单、市场信息、目录分页都是挂载时拉一次,
2323
+ // 不重挂就不会重新取,看起来就像「按了没反应」。
2324
+ return h(Home, {
2325
+ status,
2326
+ surface: (props && props.surface) || "sidebar",
2327
+ gen,
2328
+ onRefresh: async () => {
2329
+ await load(3)
2330
+ setGen((n) => n + 1)
2331
+ },
2332
+ })
2033
2333
  }
2034
2334
 
2035
2335
  const inject = ["slots"]
@@ -2088,6 +2388,7 @@ window.__ModuleLoader__.load({
2088
2388
  try {
2089
2389
  const data = await api("/status")
2090
2390
  if (data && data.ok && data.placements) setPlacement(data.placements)
2391
+ if (data && data.config && data.config.forceHideMarketSidebar === true) enforceMarketSidebarOff()
2091
2392
  } catch (e) {
2092
2393
  if (left > 0) setTimeout(() => { refreshPlacement(left - 1) }, 700 * (3 - left))
2093
2394
  }