dsh-modpack-kit 0.1.1 → 0.1.3

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
@@ -60,6 +60,32 @@ window.__ModuleLoader__.load({
60
60
  return () => placement.subs.delete(fn)
61
61
  }
62
62
 
63
+ // 打包结果(含下载按钮)放在模块里:切页签、关掉面板都不丢,留到退出程序为止。
64
+ const packStore = { value: null, subs: new Set() }
65
+ function readPackValue() {
66
+ return packStore.value
67
+ }
68
+ function setPackValue(value) {
69
+ const same = (packStore.value || null) === (value || null)
70
+ packStore.value = value || null
71
+ if (same) return
72
+ for (const fn of [...packStore.subs]) { try { fn(packStore.value) } catch (e) { /* 一个订阅出错不该拖垮别的 */ } }
73
+ }
74
+ function subscribePack(fn) {
75
+ packStore.subs.add(fn)
76
+ return () => packStore.subs.delete(fn)
77
+ }
78
+
79
+ // 点了「清空进程」:打包页上的旧报错、旧的失败结果也一起收掉,别留着当幽灵
80
+ const clearSignal = { subs: new Set() }
81
+ function fireClear() {
82
+ for (const fn of [...clearSignal.subs]) { try { fn() } catch (e) { /* 一个订阅出错不该拖垮别的 */ } }
83
+ }
84
+ function subscribeClear(fn) {
85
+ clearSignal.subs.add(fn)
86
+ return () => clearSignal.subs.delete(fn)
87
+ }
88
+
63
89
  async function api(pathname, body) {
64
90
  const init = body === undefined ? { headers: { Accept: "application/json" } } : {
65
91
  method: "POST",
@@ -141,22 +167,51 @@ window.__ModuleLoader__.load({
141
167
  return h("div", { style: { ...box, borderColor: props.tone === "warn" ? "#ffb020" : props.tone === "bad" ? "#ff6b6b" : "var(--dsw-alias-border-l2)", background: "var(--dsw-alias-bg-l2, transparent)", fontSize: "12px", lineHeight: "18px" } }, props.children)
142
168
  }
143
169
 
170
+ const ORIGIN_LABEL = { local: "本机", market: "市场", config: "配置", data: "数据", pack: "整合包" }
171
+
144
172
  function ScanReport(props) {
145
173
  const scan = props.scan
174
+ const counts = (scan && scan.counts) || { high: 0, medium: 0, low: 0 }
175
+ const findings = scan && Array.isArray(scan.findings) ? scan.findings : []
176
+ const [open, setOpen] = useState(counts.high > 0)
177
+ const [openGroup, setOpenGroup] = useState({})
146
178
  if (!scan) return null
147
- const findings = Array.isArray(scan.findings) ? scan.findings : []
148
- const counts = scan.counts || { high: 0, medium: 0, low: 0 }
179
+ const groups = Array.isArray(props.groups) && props.groups.length
180
+ ? props.groups
181
+ : (findings.length ? [{ key: "all", label: "全部命中", origin: "", counts, findings }] : [])
182
+ const toggleGroup = (key) => setOpenGroup((prev) => ({ ...prev, [key]: !prev[key] }))
183
+ const toggleOpen = () => setOpen((prev) => !prev)
149
184
  return h("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } },
150
185
  h("div", { style: row },
151
186
  h("div", { style: strong }, "安全检测"),
152
187
  h(Tag, { color: counts.high ? "#ff6b6b" : counts.medium ? "#ffb020" : "#2bb673" },
153
188
  "高 " + counts.high + " · 中 " + counts.medium + " · 低 " + counts.low),
154
- h("span", { style: hint }, "扫描 " + (scan.scannedFiles || 0) + " 个文件 / " + bytes(scan.scannedBytes || 0) + (scan.note ? " · " + scan.note : ""))),
155
- findings.length
156
- ? h("div", { style: { display: "flex", flexDirection: "column", gap: "4px", maxHeight: "190px", overflow: "auto" } },
157
- findings.slice(0, 120).map((f, i) => h("div", { key: i, style: { ...mono, color: LEVEL_COLOR[f.severity] || "inherit" } },
158
- "[" + String(f.severity || "").toUpperCase() + "] " + (f.label || f.rule) + " · " + f.file + (f.line ? ":" + f.line : "") + " · " + (f.masked || ""))))
159
- : h("div", { style: hint }, "没有命中敏感信息或可疑代码规则。"),
189
+ h("span", { style: hint }, "扫描 " + (scan.scannedFiles || 0) + " 个文件 / " + bytes(scan.scannedBytes || 0) + (scan.note ? " · " + scan.note : "")),
190
+ findings.length
191
+ ? h("button", { style: { ...chipBtn, marginLeft: "auto" }, onClick: toggleOpen },
192
+ open ? "收起风险列表(" + findings.length + " 条)" : "展开风险列表(" + findings.length + " 条)")
193
+ : null),
194
+ findings.length === 0 ? h("div", { style: hint }, "没有命中敏感信息或可疑代码规则。") : null,
195
+ open && findings.length
196
+ ? h("div", { style: { display: "flex", flexDirection: "column", gap: "6px" } },
197
+ groups.map((group) => {
198
+ const expanded = openGroup[group.key] === true
199
+ return h("div", { key: group.key, style: { border: "0.5px solid var(--dsw-alias-border-l2)", borderRadius: "6px", overflow: "hidden" } },
200
+ h("div", {
201
+ style: { display: "flex", alignItems: "center", gap: "8px", padding: "6px 9px", cursor: "pointer", background: "var(--dsw-alias-bg-l2, transparent)" },
202
+ onClick: () => toggleGroup(group.key),
203
+ },
204
+ h("span", { style: { ...label, fontSize: "12.5px" } }, group.label),
205
+ group.origin ? h(Tag, null, ORIGIN_LABEL[group.origin] || group.origin) : null,
206
+ h("span", { style: hint }, "高 " + group.counts.high + " · 中 " + group.counts.medium + " · 低 " + group.counts.low),
207
+ h("span", { style: { ...hint, marginLeft: "auto" } }, expanded ? "收起" : "展开")),
208
+ expanded
209
+ ? h("div", { style: { display: "flex", flexDirection: "column", gap: "3px", padding: "0 9px 8px", maxHeight: "220px", overflow: "auto" } },
210
+ group.findings.map((f, i) => h("div", { key: i, style: { ...mono, color: LEVEL_COLOR[f.severity] || "inherit" } },
211
+ "[" + String(f.severity || "").toUpperCase() + "] " + (f.label || f.rule) + " · " + f.file + (f.line ? ":" + f.line : "") + " · " + (f.masked || ""))))
212
+ : null)
213
+ }))
214
+ : null,
160
215
  h("div", { style: hint }, props.footNote || "命中内容只在内存里比对,报告只保留类型、位置与掩码,原文不落盘。"))
161
216
  }
162
217
 
@@ -173,9 +228,264 @@ window.__ModuleLoader__.load({
173
228
  f.suggestion ? h("div", { style: hint }, "建议:" + f.suggestion) : null)))
174
229
  }
175
230
 
231
+ const JOB_KIND_LABEL = { pack: "打包", install: "安装" }
232
+ const JOB_STATUS_TEXT = { running: "进行中", paused: "等决定", acked: "已确认", done: "完成", failed: "失败", cancelled: "已取消" }
233
+
234
+ function useJobs(intervalMs) {
235
+ const [jobs, setJobs] = useState([])
236
+ useEffect(() => {
237
+ let alive = true
238
+ const load = async () => {
239
+ try {
240
+ const res = await fetch(API + "/jobs")
241
+ if (!res.ok) return
242
+ const data = await res.json()
243
+ if (alive && data && Array.isArray(data.jobs)) setJobs(data.jobs)
244
+ } catch { /* 轮询失败不该打断界面,下一次再试 */ }
245
+ }
246
+ load()
247
+ const timer = setInterval(load, intervalMs || 900)
248
+ return () => { alive = false; clearInterval(timer) }
249
+ }, [intervalMs])
250
+ return jobs
251
+ }
252
+
253
+ function ProgressBar(props) {
254
+ const pct = Math.max(0, Math.min(100, Math.round(props.pct || 0)))
255
+ return h("div", { style: { height: "6px", borderRadius: "99px", background: "rgba(127,163,245,.18)", overflow: "hidden" } },
256
+ h("div", { style: { width: pct + "%", height: "100%", borderRadius: "99px", transition: "width .25s ease", background: props.tone || "linear-gradient(90deg,#7FA3F5,#4C7DF0)" } }))
257
+ }
258
+
259
+ // 进度窗:可以拖,拖过的位置记在浏览器本地;没有任务时自动收起,只留一枚唤出按钮。
260
+ const DOCK_POS_KEY = "dsh-modpack-kit:dock-pos"
261
+ function readDockPos() {
262
+ try {
263
+ const raw = typeof localStorage !== "undefined" ? localStorage.getItem(DOCK_POS_KEY) : null
264
+ if (!raw) return null
265
+ const parsed = JSON.parse(raw)
266
+ if (!parsed || typeof parsed !== "object") return null
267
+ if (!Number.isFinite(Number(parsed.x)) || !Number.isFinite(Number(parsed.y))) return null
268
+ return { x: Math.max(0, Math.round(Number(parsed.x))), y: Math.max(0, Math.round(Number(parsed.y))) }
269
+ } catch { return null }
270
+ }
271
+ function writeDockPos(pos) {
272
+ try { if (typeof localStorage !== "undefined" && pos) localStorage.setItem(DOCK_POS_KEY, JSON.stringify(pos)) } catch { /* 存不了就算了,不影响本场使用 */ }
273
+ }
274
+ function viewportSize() {
275
+ const width = typeof window !== "undefined" && Number(window.innerWidth) ? Number(window.innerWidth) : 1280
276
+ const height = typeof window !== "undefined" && Number(window.innerHeight) ? Number(window.innerHeight) : 800
277
+ return { width, height }
278
+ }
279
+
280
+ function JobDock(props) {
281
+ const jobs = Array.isArray(props.jobs) ? props.jobs : []
282
+ const [pos, setPos] = useState(readDockPos())
283
+ const [pinned, setPinned] = useState(false) // 手动唤出:没有任务时也显示
284
+ const [hidden, setHidden] = useState(false) // 手动收起:连进行中的也先藏起来
285
+ const [open, setOpen] = useState(false)
286
+ const [dockMsg, setDockMsg] = useState("")
287
+ const dragRef = useRef(null)
288
+ const boxRef = useRef(null)
289
+ const running = jobs.filter((job) => job.status === "running")
290
+ const visible = !hidden && (pinned || running.length > 0)
291
+
292
+ // 有任务开跑就自己冒出来(之前手动收起的也一并放出来)
293
+ useEffect(() => {
294
+ if (running.length > 0) { setHidden(false) }
295
+ }, [running.length])
296
+
297
+ const startDrag = (event) => {
298
+ if (!event || typeof event.clientX !== "number") return
299
+ const el = boxRef.current
300
+ const rect = el && el.getBoundingClientRect ? el.getBoundingClientRect() : { left: 0, top: 0, width: 0, height: 0 }
301
+ dragRef.current = {
302
+ dx: event.clientX - rect.left,
303
+ dy: event.clientY - rect.top,
304
+ width: rect.width,
305
+ height: rect.height,
306
+ startX: rect.left,
307
+ startY: rect.top,
308
+ moved: false,
309
+ last: null,
310
+ }
311
+ if (event.currentTarget && event.currentTarget.setPointerCapture && event.pointerId !== undefined) {
312
+ try { event.currentTarget.setPointerCapture(event.pointerId) } catch { /* 某些环境不支持捕获,照样能拖 */ }
313
+ }
314
+ }
315
+ const moveDrag = (event) => {
316
+ const drag = dragRef.current
317
+ if (!drag || !event || typeof event.clientX !== "number") return
318
+ const { width, height } = viewportSize()
319
+ const left = Math.min(Math.max(4, event.clientX - drag.dx), Math.max(4, width - drag.width - 4))
320
+ const top = Math.min(Math.max(4, event.clientY - drag.dy), Math.max(4, height - drag.height - 4))
321
+ if (Math.abs(left - drag.startX) > 3 || Math.abs(top - drag.startY) > 3) drag.moved = true
322
+ drag.last = { x: Math.round(left), y: Math.round(top) }
323
+ setPos(drag.last)
324
+ }
325
+ const endDrag = () => {
326
+ const drag = dragRef.current
327
+ if (!drag) return
328
+ dragRef.current = null
329
+ if (drag.moved) {
330
+ if (drag.last) writeDockPos(drag.last)
331
+ return
332
+ }
333
+ // 没拖动就是点了一下标题:展开 / 收起
334
+ setOpen((prev) => !prev)
335
+ }
336
+
337
+ if (!visible) {
338
+ const anchor = pos || null
339
+ const summonStyle = {
340
+ position: "fixed",
341
+ zIndex: 70,
342
+ display: "flex",
343
+ alignItems: "center",
344
+ gap: "6px",
345
+ padding: "7px 11px",
346
+ borderRadius: "999px",
347
+ border: "0.5px solid var(--dsw-alias-border-l2)",
348
+ background: "var(--dsw-alias-surface-1, rgba(24,26,31,.97))",
349
+ color: "var(--dsw-alias-label-primary)",
350
+ boxShadow: "0 6px 18px rgba(0,0,0,.28)",
351
+ cursor: "pointer",
352
+ fontSize: "12px",
353
+ ...(anchor ? { left: anchor.x + "px", top: anchor.y + "px" } : { right: "16px", bottom: "16px" }),
354
+ }
355
+ const badge = running.length || jobs.length
356
+ return h("button", { style: summonStyle, title: "打开整合包进度窗", onClick: () => { setPinned(true); setHidden(false) } },
357
+ h("span", { style: { width: "7px", height: "7px", borderRadius: "99px", background: running.length ? "#4C7DF0" : "rgba(127,163,245,.5)" } }),
358
+ "进度",
359
+ badge ? h("span", { style: { ...hint, marginLeft: "0", fontVariantNumeric: "tabular-nums" } }, String(badge)) : null)
360
+ }
361
+
362
+ const current = running[0] || jobs[0] || null
363
+ const headText = current
364
+ ? (running.length ? (current.note || "处理中") : (JOB_STATUS_TEXT[current.status] || "打包记录"))
365
+ : "还没有任务"
366
+ const headPct = current ? Math.round(current.status === "done" ? 100 : (current.pct || 0)) : 0
367
+ const stop = async (id) => {
368
+ try { await api("/jobs/cancel", { id }) } catch { /* 已经结束就忽略 */ }
369
+ }
370
+ const ack = async (id) => {
371
+ try { await api("/jobs/ack", { id }) } catch (error) { setDockMsg((error && error.message) || "确认失败") }
372
+ }
373
+ const dismiss = async (id) => {
374
+ try { await api("/jobs/dismiss", { id }) } catch (error) { setDockMsg((error && error.message) || "删除失败") }
375
+ }
376
+ const clearDone = async () => {
377
+ // 先试一次服务端的批量清空;老宿主上没有这个路由时,退回逐个删
378
+ try {
379
+ const data = await api("/jobs/clear", {})
380
+ setDockMsg(data && data.removed && data.removed.length ? "" : "没有可清空的进程")
381
+ fireClear()
382
+ return
383
+ } catch (error) {
384
+ const targets = jobs.filter((job) => job.status !== "running" && job.status !== "paused")
385
+ if (targets.length === 0) { setDockMsg((error && error.message) || "清空进程失败"); return }
386
+ let bad = 0
387
+ for (const job of targets) {
388
+ try { await api("/jobs/dismiss", { id: job.id }) } catch { bad += 1 }
389
+ }
390
+ fireClear()
391
+ setDockMsg(bad ? ("有 " + bad + " 条没删掉(可能还在跑),其余已清") : "")
392
+ }
393
+ }
394
+ // 只要有一条不是「在跑」或「停在风险点」,就给清空入口(状态再怪也算收尾)
395
+ const finished = jobs.filter((job) => job.status !== "running" && job.status !== "paused")
396
+
397
+ return h("div", {
398
+ ref: boxRef,
399
+ style: {
400
+ position: "fixed",
401
+ zIndex: 70,
402
+ ...(pos ? { left: pos.x + "px", top: pos.y + "px" } : { right: "16px", bottom: "16px" }),
403
+ width: open ? "380px" : "288px",
404
+ maxHeight: open ? "58vh" : "none",
405
+ overflow: "auto",
406
+ boxSizing: "border-box",
407
+ padding: "10px 12px",
408
+ borderRadius: "10px",
409
+ border: "0.5px solid var(--dsw-alias-border-l2)",
410
+ background: "var(--dsw-alias-surface-1, rgba(24,26,31,.97))",
411
+ boxShadow: "0 10px 30px rgba(0,0,0,.35)",
412
+ display: "flex",
413
+ flexDirection: "column",
414
+ gap: "7px",
415
+ },
416
+ },
417
+ h("div", {
418
+ style: { display: "flex", alignItems: "center", gap: "8px", cursor: "grab", userSelect: "none", touchAction: "none" },
419
+ title: "按住可以拖动;点一下展开或收起",
420
+ onPointerDown: startDrag,
421
+ onPointerMove: moveDrag,
422
+ onPointerUp: endDrag,
423
+ onPointerCancel: endDrag,
424
+ },
425
+ h("span", { style: { fontSize: "12px", color: "var(--dsw-alias-label-secondary, #b6bac3)", minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, headText),
426
+ h("span", { style: { marginLeft: "auto", fontSize: "12px", fontVariantNumeric: "tabular-nums" } }, headPct + "%"),
427
+ running.length > 1 ? h("span", { style: { ...hint, marginLeft: "0" } }, "+" + (running.length - 1)) : null,
428
+ finished.length
429
+ ? h("button", {
430
+ style: { ...chipBtn, marginLeft: "2px", padding: "0 6px", lineHeight: "18px" },
431
+ title: "清掉所有收尾与失败的进程(跑着的和停在风险点的留着)",
432
+ onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation(); clearDone() },
433
+ }, "清空进程")
434
+ : null,
435
+ h("button", {
436
+ style: { ...chipBtn, marginLeft: "2px", padding: "0 6px", lineHeight: "18px" },
437
+ title: "收起(有任务时还会再冒出来)",
438
+ onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation(); setHidden(true); setPinned(false) },
439
+ }, "收起")),
440
+ current ? h(ProgressBar, { pct: headPct, tone: current.status === "failed" ? "#ff6b6b" : current.status === "cancelled" ? "#8b8f99" : undefined }) : null,
441
+ open
442
+ ? (jobs.length === 0
443
+ ? h("div", { style: hint }, "还没有打包或安装任务。开始一个就会出现在这里。")
444
+ : h("div", { style: { display: "flex", flexDirection: "column", gap: "8px", marginTop: "2px" } },
445
+ jobs.map((job) => h("div", { key: job.id, style: { display: "flex", flexDirection: "column", gap: "4px", paddingTop: "7px", borderTop: "0.5px solid var(--dsw-alias-border-l2)" } },
446
+ h("div", { style: row },
447
+ h("span", { style: { ...label, fontSize: "12.5px" } }, job.label || JOB_KIND_LABEL[job.kind] || "任务"),
448
+ h("span", { style: { ...hint, marginLeft: "auto" } }, (JOB_STATUS_TEXT[job.status] || job.status) + " · " + Math.round(job.pct || 0) + "%")),
449
+ h("div", { style: hint }, job.note || ""),
450
+ job.risk && job.status === "paused"
451
+ ? h("div", { style: { ...hint, color: "#ff9b9b", display: "flex", flexDirection: "column", gap: "2px" } },
452
+ h("div", null, "检测到风险:高 " + (job.risk.high || 0) + " · 中 " + (job.risk.medium || 0) + " · 低 " + (job.risk.low || 0)),
453
+ h("div", { style: { fontSize: "10.5px" } }, job.risk.message || ""),
454
+ job.risk.groups && job.risk.groups.length
455
+ ? h("div", { style: { fontSize: "10.5px" } },
456
+ job.risk.groups.map((g) => (g.label || "") + "(高 " + ((g.counts && g.counts.high) || 0) + " / 中 " + ((g.counts && g.counts.medium) || 0) + ")").join(" "))
457
+ : null)
458
+ : null,
459
+ h(ProgressBar, { pct: job.pct, tone: job.status === "failed" || job.status === "paused" ? "#ff6b6b" : job.status === "cancelled" ? "#8b8f99" : undefined }),
460
+ h("div", { style: { display: "flex", flexWrap: "wrap", gap: "6px" } },
461
+ job.status === "running" ? h("button", { style: { ...chipBtn }, onClick: () => stop(job.id) }, "终止") : null,
462
+ job.status === "done" && job.kind === "pack" && job.data && job.data.token
463
+ ? h("button", {
464
+ style: { ...chipBtn, color: "#4C7DF0", borderColor: "#4C7DF0" },
465
+ title: "跳到打包页的下载部分",
466
+ onClick: () => { if (typeof props.onOpenResult === "function") props.onOpenResult(job) },
467
+ }, "下载安装包")
468
+ : null,
469
+ job.canAck
470
+ ? h("button", { style: { ...chipBtn, color: "#ff6b6b", borderColor: "#ff6b6b" }, title: "忽略风险,在同一个任务里接着跑完", onClick: () => ack(job.id) }, "我知道在干什么")
471
+ : null,
472
+ job.canDismiss
473
+ ? h("button", { style: { ...chipBtn, color: "var(--dsw-alias-label-tertiary, #8b8f99)" }, title: "从列表里删掉这条记录", onClick: () => dismiss(job.id) }, "删除该进程")
474
+ : null,
475
+ job.error && job.status !== "paused" ? h("span", { style: { ...hint, color: "#ff6b6b" } }, job.error) : null)))))
476
+ : h("div", { style: { ...hint, fontSize: "10.5px" } },
477
+ (running.length ? running.length + " 个任务进行中 · " : "") + "按住标题能拖动,点标题展开看详情、也能中途终止"),
478
+ dockMsg
479
+ ? h("div", { style: { ...hint, fontSize: "10.5px", color: "#ff6b6b", display: "flex", gap: "6px", alignItems: "center" } },
480
+ dockMsg,
481
+ h("button", { style: { ...chipBtn, marginLeft: "auto" }, onClick: () => setDockMsg("") }, "知道了"))
482
+ : null)
483
+ }
484
+
176
485
  // —— 打包 ——
177
486
  function PackPanel(props) {
178
487
  const status = props.status
488
+ const jobs = Array.isArray(props.jobs) ? props.jobs : []
179
489
  const pageSize = (status && status.config && status.config.catalogPageSize) || 20
180
490
  const [installed, setInstalled] = useState((status && status.installed) || [])
181
491
  const [marketInfo, setMarketInfo] = useState({}) // name -> 市场同名条目(标题/版本/分类)
@@ -190,7 +500,6 @@ window.__ModuleLoader__.load({
190
500
  const [options, setOptions] = useState({
191
501
  includePayload: true,
192
502
  includeConfig: true,
193
- includeLocalEdits: false,
194
503
  scanBeforePack: true,
195
504
  confirmLicense: false,
196
505
  name: "DSH 整合包",
@@ -198,9 +507,15 @@ window.__ModuleLoader__.load({
198
507
  author: "",
199
508
  })
200
509
  const [busy, setBusy] = useState("")
201
- const [result, setResult] = useState(null)
510
+ // 结果由 Home 保管(模块级缓存),切页签回来仍然在
511
+ const result = props.result === undefined ? null : props.result
512
+ const setResult = typeof props.setResult === "function" ? props.setResult : () => {}
513
+ const [started, setStarted] = useState("")
514
+ const [seenJobs, setSeenJobs] = useState({})
515
+ const [mountAt] = useState(() => Date.now())
202
516
  const [error, setError] = useState("")
203
517
  const [packNag, firePackNag] = useNag()
518
+ const resultRef = useRef(null)
204
519
 
205
520
  const active = query.trim() !== "" || category !== "all"
206
521
 
@@ -320,7 +635,7 @@ window.__ModuleLoader__.load({
320
635
  name: entry.name,
321
636
  source: entry.source,
322
637
  spec: entry.version || "",
323
- mode: entry.source === "profile" ? (options.includeLocalEdits ? "local" : "base") : "base",
638
+ mode: "base",
324
639
  }
325
640
  return next
326
641
  })
@@ -334,20 +649,82 @@ window.__ModuleLoader__.load({
334
649
  ...prev,
335
650
  [entry.name]: toMarket
336
651
  ? { name: entry.name, source: "npm", spec: entry.marketVersion || "", mode: "base" }
337
- : { name: entry.name, source: "profile", spec: entry.version || "", mode: options.includeLocalEdits ? "local" : "base" },
652
+ : { name: entry.name, source: "profile", spec: entry.version || "", mode: "base" },
338
653
  }
339
654
  })
340
655
 
341
- const doPack = async () => {
342
- setBusy("pack"); setError(""); setResult(null)
656
+ const addAllLocal = () => setSelected((prev) => {
657
+ const next = { ...prev }
658
+ for (const entry of localRows) {
659
+ if (!next[entry.name]) next[entry.name] = { name: entry.name, source: "profile", spec: entry.version || "", mode: "base" }
660
+ }
661
+ return next
662
+ })
663
+ const clearSelected = () => setSelected({})
664
+
665
+ const [jobMsg, setJobMsg] = useState("")
666
+ const pausedJobs = (props.jobs || []).filter((job) => job.kind === "pack" && job.status === "paused" && job.risk)
667
+
668
+ const ackJob = async (id) => {
669
+ setJobMsg("")
670
+ try {
671
+ const data = await api("/jobs/ack", { id })
672
+ if (!data || !data.ok) setJobMsg((data && data.error) || "确认失败")
673
+ } catch (e) { setJobMsg(String((e && e.message) || e)) }
674
+ }
675
+ // 停在风险点的任务:按插件分栏列出命中项,确认/删除都在这里做
676
+ const pausedRiskNodes = []
677
+ if (pausedJobs.length > 0) {
678
+ pausedRiskNodes.push(h("div", { key: "title", style: { ...strong, color: "#ff6b6b" } }, "打包停在风险点(" + pausedJobs.length + " 个任务)"))
679
+ pausedRiskNodes.push(h("div", { key: "hint", style: hint }, "下面是每个插件自己的命中项。确认后原任务从这个检测点接着跑完,不再重复检测。"))
680
+ for (const job of pausedJobs) {
681
+ const groupNodes = (job.risk.groups || []).map((group, index) => {
682
+ const sampleNodes = (group.samples || []).map((sample, i) => h("div", {
683
+ key: i,
684
+ style: { color: LEVEL_COLOR[sample.severity] || "inherit" },
685
+ }, "· " + (sample.label || "") + " " + (sample.file || "") + (sample.line ? ":" + sample.line : "")))
686
+ return h("div", {
687
+ key: index,
688
+ style: { ...box, padding: "8px 10px", background: "transparent", display: "flex", flexDirection: "column", gap: "4px" },
689
+ },
690
+ h("div", { style: row },
691
+ h(Tag, null, group.plugin || group.label),
692
+ h("span", { style: hint }, ORIGIN_LABEL[group.origin] || group.origin || ""),
693
+ h("span", { style: hint }, "高 " + ((group.counts && group.counts.high) || 0) + " · 中 " + ((group.counts && group.counts.medium) || 0) + " · 低 " + ((group.counts && group.counts.low) || 0))),
694
+ sampleNodes.length > 0
695
+ ? h("div", { style: { ...mono, display: "flex", flexDirection: "column", gap: "2px" } }, sampleNodes)
696
+ : h("div", { style: hint }, "命中详情写进了包内 security/report.txt。"))
697
+ })
698
+ pausedRiskNodes.push(h("div", { key: job.id, style: { display: "flex", flexDirection: "column", gap: "6px" } },
699
+ h("div", { style: { ...row, justifyContent: "space-between" } },
700
+ h("div", { style: strong }, job.label || "打包任务"),
701
+ h("div", { style: row },
702
+ h("button", { style: { ...btn, borderColor: "#ff6b6b", color: "#ff6b6b" }, onClick: () => ackJob(job.id) }, "我知道在干什么"),
703
+ h("button", { style: btn, onClick: () => dismissJob(job.id) }, "删除该进程"))),
704
+ groupNodes))
705
+ }
706
+ pausedRiskNodes.push(h("div", { key: "msg", style: hint }, jobMsg))
707
+ }
708
+
709
+ const dismissJob = async (id) => {
710
+ setJobMsg("")
711
+ try {
712
+ const data = await api("/jobs/dismiss", { id })
713
+ if (!data || !data.ok) setJobMsg((data && data.error) || "删除失败")
714
+ } catch (e) { setJobMsg(String((e && e.message) || e)) }
715
+ }
716
+
717
+ const doPack = async (ack) => {
718
+ setError(""); setStarted(""); setBusy("start")
343
719
  try {
344
720
  const data = await api("/pack", {
721
+ async: true,
345
722
  selection: picked.map((name) => selected[name]),
346
723
  options: {
347
724
  includePayload: options.includePayload,
348
725
  includeConfig: options.includeConfig,
349
- includeLocalEdits: options.includeLocalEdits,
350
- scanBeforePack: options.scanBeforePack,
726
+ acknowledge: ack === true,
727
+ force: false,
351
728
  confirmLicense: options.confirmLicense,
352
729
  name: options.name,
353
730
  description: options.description,
@@ -355,13 +732,44 @@ window.__ModuleLoader__.load({
355
732
  },
356
733
  })
357
734
  if (!data) { setError("没有响应"); return }
358
- if (!data.ok) { setResult({ refused: data.refused, error: data.error, scan: data.scan }); return }
359
- setResult(data)
735
+ if (!data.ok) { setError(data.error || "打包请求被拒绝"); return }
736
+ setStarted((data.job && data.job.label) || "打包任务")
360
737
  } catch (e) {
361
738
  setError(String((e && e.message) || e))
362
739
  } finally { setBusy("") }
363
740
  }
364
741
 
742
+ // 后台任务完成后,把结果搬回这一页(可以同时打好几个包)
743
+ useEffect(() => {
744
+ const finished = (props.jobs || []).filter((job) => job.kind === "pack" && job.status !== "running" && job.data && Date.parse(job.startedAt) >= mountAt)
745
+ const fresh = finished.filter((job) => !seenJobs[job.id])
746
+ if (fresh.length === 0) return
747
+ const nextSeen = { ...seenJobs }
748
+ for (const job of fresh) nextSeen[job.id] = true
749
+ setSeenJobs(nextSeen)
750
+ const payload = fresh[fresh.length - 1].data
751
+ if (payload && payload.ok) setResult(payload)
752
+ else if (payload && payload.refused) setResult({ refused: true, needsAck: payload.needsAck === true, trustedOnly: payload.trustedOnly === true, error: payload.error, scan: payload.scan, scanGroups: payload.scanGroups })
753
+ else if (payload && payload.cancelled) { setResult(null); setError(payload.error || "已取消") }
754
+ else { setResult(null); setError((payload && payload.error) || "打包失败,详情见左下角") }
755
+ }, [props.jobs])
756
+
757
+ // 从进度窗点「下载安装包」跳过来:滚到结果那一块
758
+ useEffect(() => {
759
+ if (!props.focus) return
760
+ const el = resultRef.current
761
+ if (el && typeof el.scrollIntoView === "function") {
762
+ try { el.scrollIntoView({ block: "start", behavior: "smooth" }) } catch { /* 老浏览器不支持行为参数,忽略 */ }
763
+ }
764
+ }, [props.focus])
765
+
766
+ // 「清空进程」之后,打包页上的旧报错与失败结果也一起收掉
767
+ useEffect(() => subscribeClear(() => {
768
+ setError("")
769
+ const current = props.result
770
+ if (current && (current.refused || current.error)) setResult(null)
771
+ }), [props.result])
772
+
365
773
  const downloadPack = async () => {
366
774
  if (!result || !result.token) return
367
775
  setBusy("download")
@@ -395,17 +803,19 @@ window.__ModuleLoader__.load({
395
803
 
396
804
  return h("div", { style: { display: "flex", flexDirection: "column", gap: "14px" } },
397
805
  h(Notice, null,
398
- h("b", null, "打包就是把这些插件打成一个 .dshpack"),
399
- " 完整版连插件本体一起装进包里;轻量版只记录名字和版本,装的时候联网按版本取。两种都不改你的 profile,直到你真的点安装。",
806
+ h("b", null, "打包:将所选插件封装为一个 .dshpack 文件"),
807
+ " 完整版包含插件本体的全部文件;轻量版仅记录插件名称与版本,安装时按版本从插件市场下载。两种包在安装前均不修改 profile 内容。",
400
808
  status && status.market && status.market.installed
401
- ? h("div", { style: { ...hint, marginTop: "6px" } }, "插件市场 v" + status.market.version + " 已装:目录、本机列表、安装链路都是同一条;本插件不依赖它,拆掉也照常打包与装包。")
402
- : h("div", { style: { ...hint, marginTop: "6px" } }, "没装插件市场也能用:打包、装包、检测全在本地跑。建议先装一下 dshmarket —— 分类、搜索、「(切换市场版)」会更顺手;不装的话第一次自己点一次「建立目录索引」即可,其余体验不受影响。"),
403
- h("div", { style: hint }, "市场里若有同名插件,那多半就是它的市场版:行末小字「(切换市场版)」可以改成打上游原版,装出来和你从市场装一样。")),
809
+ ? h("div", { style: { ...hint, marginTop: "6px" } }, "已检测到插件市场 v" + status.market.version + ":本插件与其共用目录源与安装链路,但不依赖该插件,移除后打包与安装功能不受影响。")
810
+ : h("div", { style: { ...hint, marginTop: "6px" } }, "未检测到插件市场,功能不受影响:打包、安装与检测均在本地完成。建议先安装 dshmarket 以获得分类、搜索与「切换市场版」入口;未安装时,首次使用请点击「建立目录索引」。"),
811
+ h("div", { style: hint }, "目录中存在同名插件时,该条目末尾提供「(切换市场版)」入口:可将打包源切换为上架市场的上游原版,安装结果与从市场安装一致。")),
404
812
  h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
405
813
  h("div", { style: row },
406
814
  h("div", { style: strong }, "选择插件"),
407
815
  h("input", { style: { ...input, flex: "1 1 200px" }, placeholder: "搜索插件名 / 描述(在插件市场目录里搜)", value: query, onChange: (e) => setQuery(e.target.value) }),
408
816
  active ? h("button", { style: btn, onClick: () => { setQuery(""); setCategory("all") } }, "回到已装") : null,
817
+ h("button", { style: btn, onClick: addAllLocal, title: "把本机已装的全部插件加入选择(默认按基础配置打包,可逐个改)" }, "全部加入"),
818
+ h("button", { style: btn, disabled: picked.length === 0, onClick: clearSelected, title: "清空当前选择" }, "清除选择"),
409
819
  h("span", { style: hint }, loading ? "读取中…" : active
410
820
  ? ("已选 " + picked.length + " · 匹配 " + search.total + " 条" + (searching ? " · 搜索中…" : "") + (search.total > rows.length ? " · 已加载 " + rows.length : ""))
411
821
  : ("已选 " + picked.length + " 个 · 本机已装 " + localRows.length + " 个"))),
@@ -425,7 +835,7 @@ window.__ModuleLoader__.load({
425
835
  search.error ? h("div", { style: { ...hint, color: "#ffb020" } }, search.error) : null,
426
836
  h("div", { style: { display: "flex", flexDirection: "column", gap: "3px", maxHeight: "320px", overflow: "auto" } },
427
837
  rows.length === 0
428
- ? h("div", { style: hint }, loading ? "稍等…" : active ? (searching ? "搜索中…" : "没有匹配的插件") : "本机还没有装插件")
838
+ ? h("div", { style: hint }, loading ? "读取中…" : active ? (searching ? "搜索中…" : "无匹配条目") : "本机尚未安装插件")
429
839
  : rows.map((entry) => {
430
840
  const on = Boolean(selected[entry.name])
431
841
  return h("div", { key: entry.name, style: { display: "flex", gap: "8px", alignItems: "center", padding: "5px 2px", borderTop: "0.5px solid var(--dsw-alias-border-l2)", flexWrap: "wrap" } },
@@ -462,7 +872,6 @@ window.__ModuleLoader__.load({
462
872
  h("div", { style: { ...row, rowGap: "6px" } },
463
873
  h(Switch, { checked: options.includePayload, label: "包含插件本体(关=轻量版)", onChange: (v) => setOptions({ ...options, includePayload: v }) }),
464
874
  h(Switch, { checked: options.includeConfig, label: "包含配置与数据快照", onChange: (v) => setOptions({ ...options, includeConfig: v }) }),
465
- h(Switch, { checked: options.includeLocalEdits, label: "默认打包本机修改(勾选后可逐个改)", onChange: (v) => setOptions({ ...options, includeLocalEdits: v }) }),
466
875
  h(ForcedSwitch, { label: "打包前安全检测(强制)", onNag: () => firePackNag("你想干什么") })),
467
876
  h(NagText, { text: packNag }),
468
877
  h("div", { style: { ...row, rowGap: "6px" } },
@@ -471,18 +880,27 @@ window.__ModuleLoader__.load({
471
880
  h("input", { style: { ...input, width: "100%" }, placeholder: "一句话描述(可空)", value: options.description, onChange: (e) => setOptions({ ...options, description: e.target.value }) }),
472
881
  h(Switch, { checked: options.confirmLicense, label: "我确认所选插件的许可证允许再分发,或已获得作者授权", onChange: (v) => setOptions({ ...options, confirmLicense: v }) }),
473
882
  h("div", { style: row },
474
- h("button", { style: btnPrimary, disabled: picked.length === 0 || busy === "pack", onClick: doPack }, busy === "pack" ? "打包中…" : ("打包 " + picked.length + " 个插件")),
883
+ h("button", { style: btnPrimary, disabled: picked.length === 0 || busy === "start", onClick: doPack }, busy === "start" ? "提交中…" : ("打包 " + picked.length + " 个插件")),
884
+ started ? h("span", { style: hint }, "已开始:" + started + "(进度在左下角,可以接着选别的再打一个)") : null,
475
885
  status ? h("span", { style: hint }, "DSH " + (status.dshVersion || "?") + " · profile " + status.profile) : null)),
886
+ pausedRiskNodes.length ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px", borderColor: "#d9534f" } }, pausedRiskNodes) : null,
476
887
  error ? h(Notice, { tone: "bad" }, error) : null,
477
- result ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
888
+ result ? h("div", { ref: resultRef, style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
478
889
  result.refused || result.error
479
- ? h(Notice, { tone: "warn" }, h("b", null, "已停止:"), result.error || "未通过检查", result.scan ? null : null)
890
+ ? h(Notice, { tone: "warn" },
891
+ h("b", null, "已停止:"), result.error || "未通过检查",
892
+ result.needsAck ? h("div", { style: { ...row, marginTop: "8px" } },
893
+ h("button", {
894
+ style: { ...btn, borderColor: "#ff6b6b", color: "#ff6b6b" },
895
+ disabled: busy === "start",
896
+ onClick: () => doPack(true),
897
+ }, busy === "start" ? "提交中…" : "我已知晓其中风险,继续打包")) : null)
480
898
  : h("div", { style: row },
481
899
  h("div", { style: strong }, result.fileName),
482
900
  h(Tag, { color: "#2bb673" }, bytes(result.size)),
483
901
  h(Tag, null, FORMAT_TEXT[result.manifest && result.manifest.format] || ""),
484
902
  h("span", { style: hint }, "包内插件 " + ((result.manifest && result.manifest.plugins) || []).length + " 个")),
485
- result.scan ? h(ScanReport, { scan: result.scan, footNote: "报告已写进包内 security/report.txt(只含类型与掩码)。" }) : null,
903
+ result.scan ? h(ScanReport, { scan: result.scan, groups: result.scanGroups, footNote: "报告已写进包内 security/report.txt(只含类型与掩码)。" }) : null,
486
904
  result.manifest && result.manifest.plugins && result.manifest.plugins.length
487
905
  ? h("div", { style: { display: "flex", flexDirection: "column", gap: "2px" } },
488
906
  result.manifest.plugins.map((p) => h("div", { key: p.name, style: mono },
@@ -494,7 +912,7 @@ window.__ModuleLoader__.load({
494
912
  h("button", { style: btnPrimary, disabled: busy !== "", onClick: downloadPack }, busy === "download" ? "准备下载…" : "下载 .dshpack"),
495
913
  h("button", { style: btn, disabled: busy !== "", onClick: savePack }, busy === "save" ? "保存中…" : "保存到本机 packs/"),
496
914
  result.savedPath ? h("span", { style: hint }, "已存:" + result.savedPath) : null),
497
- result.refused || result.error ? null : h("div", { style: hint }, "下载完点「安装 / 导入」页签就能读回来,或把文件发给别人。"))
915
+ result.refused || result.error ? null : h("div", { style: hint }, "下载后可在「安装 / 导入」页签读回,或将该文件转交他人。"))
498
916
  : null)
499
917
  }
500
918
 
@@ -587,7 +1005,7 @@ window.__ModuleLoader__.load({
587
1005
  h("div", { style: { display: "flex", flexDirection: "column", gap: "2px" } },
588
1006
  preview.manifest.plugins.map((p) => h("div", { key: p.name, style: mono },
589
1007
  "· " + p.name + "@" + p.version + (p.localEdits ? " [含本机修改]" : "") + (p.configIncluded ? " [有配置]" : "") + (p.dataIncluded ? " [有数据快照]" : "")))),
590
- h(ScanReport, { scan: preview.scan }),
1008
+ h(ScanReport, { scan: preview.scan, groups: preview.scanGroups }),
591
1009
  h(CompatList, { compat: preview.compat }),
592
1010
  preview.notes && preview.notes.length ? h("div", { style: hint }, preview.notes.map((n, i) => h("div", { key: i }, "· " + n))) : null,
593
1011
  h("div", { style: row },
@@ -603,7 +1021,7 @@ window.__ModuleLoader__.load({
603
1021
  (a.ok ? "✓ " : "✗ ") + a.plugin + " · " + a.action + " · " + a.message)),
604
1022
  (done.lines || []).length ? h("details", null, h("summary", { style: hint }, "命令输出(" + done.lines.length + " 行)"),
605
1023
  h("pre", { style: { ...mono, maxHeight: "200px", overflow: "auto", whiteSpace: "pre-wrap" } }, done.lines.join("\n"))) : null,
606
- done.scan ? h(ScanReport, { scan: done.scan }) : null)
1024
+ done.scan ? h(ScanReport, { scan: done.scan, groups: done.scanGroups }) : null)
607
1025
  : null)
608
1026
  }
609
1027
 
@@ -720,7 +1138,23 @@ window.__ModuleLoader__.load({
720
1138
 
721
1139
  function Home(props) {
722
1140
  const [tab, setTab] = useState("pack")
1141
+ const jobs = useJobs()
723
1142
  const status = props.status
1143
+ const [packResult, setPackResult] = useState(() => readPackValue())
1144
+ const [focus, setFocus] = useState(0)
1145
+ useEffect(() => subscribePack((value) => { setPackResult(value) }), [])
1146
+ const savePackResult = (value) => {
1147
+ setPackValue(value)
1148
+ setPackResult(value)
1149
+ }
1150
+ // 进度窗里点「下载安装包」→ 切到打包页、把那次的结果放进去、滚到下载那一块
1151
+ const openResult = (job) => {
1152
+ const payload = job && job.data ? job.data : null
1153
+ if (!payload) return
1154
+ savePackResult(payload)
1155
+ setTab("pack")
1156
+ setFocus((n) => n + 1)
1157
+ }
724
1158
  const tabs = [
725
1159
  ["pack", "打包"],
726
1160
  ["install", "安装 / 导入"],
@@ -745,10 +1179,11 @@ window.__ModuleLoader__.load({
745
1179
  h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)),
746
1180
  h("span", { style: { ...hint, marginLeft: "auto" } },
747
1181
  status ? ("DSH " + (status.dshVersion || "?") + " · 已装 " + ((status.installed || []).length) + " 个 · v" + (status.pluginVersion || "?")) : "读取环境…")),
748
- tab === "pack" ? h(PackPanel, { status }) : null,
1182
+ tab === "pack" ? h(PackPanel, { status, jobs, result: packResult, setResult: savePackResult, focus }) : null,
749
1183
  tab === "install" ? h(InstallPanel, { status }) : null,
750
1184
  tab === "settings" ? h(SettingsPanel, { status }) : null,
751
- h("div", { style: hint }, "说明:整合包只打包你选择的插件与必要配置。打包与安装安全检测在内存中进行,命中原文不落盘;请遵守插件作者许可证与你所在地区的法律法规。"))
1185
+ h("div", { style: hint }, "说明:整合包只打包你选择的插件与必要配置。打包与安装安全检测在内存中进行,命中原文不落盘;请遵守插件作者许可证与你所在地区的法律法规。")),
1186
+ h(JobDock, { jobs, onOpenResult: openResult })
752
1187
  )
753
1188
  }
754
1189