dsh-modpack-kit 0.1.1 → 0.1.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/README.md +92 -9
- package/assets/icon-180.png +0 -0
- package/assets/install-stub.cmd +15 -0
- package/assets/install-stub.mjs +299 -0
- package/assets/install-stub.sh +9 -0
- package/client.js +827 -58
- package/docs/DETAIL.md +47 -1
- package/index.js +591 -69
- package/lib/install.mjs +102 -40
- package/lib/manifest.mjs +20 -10
- package/lib/pack.mjs +90 -12
- package/lib/scan.mjs +47 -0
- package/lib/store.mjs +10 -2
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +4 -3
package/client.js
CHANGED
|
@@ -60,6 +60,68 @@ 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 importStore = { value: [], subs: new Set() }
|
|
81
|
+
function readImports() {
|
|
82
|
+
return importStore.value.slice()
|
|
83
|
+
}
|
|
84
|
+
function setImports(next) {
|
|
85
|
+
importStore.value = Array.isArray(next) ? next.slice(0, 8) : []
|
|
86
|
+
for (const fn of [...importStore.subs]) { try { fn(readImports()) } catch (e) { /* 订阅出错不影响别的 */ } }
|
|
87
|
+
}
|
|
88
|
+
function subscribeImports(fn) {
|
|
89
|
+
importStore.subs.add(fn)
|
|
90
|
+
return () => importStore.subs.delete(fn)
|
|
91
|
+
}
|
|
92
|
+
function importEntry(data, fileName) {
|
|
93
|
+
const manifest = (data && data.manifest) || {}
|
|
94
|
+
return {
|
|
95
|
+
token: data.token,
|
|
96
|
+
fileName: fileName || "",
|
|
97
|
+
name: manifest.name || "(未命名整合包)",
|
|
98
|
+
description: manifest.description || "",
|
|
99
|
+
author: manifest.author || "",
|
|
100
|
+
format: manifest.format || "",
|
|
101
|
+
createdAt: manifest.createdAt || "",
|
|
102
|
+
plugins: Array.isArray(manifest.plugins) ? manifest.plugins.length : 0,
|
|
103
|
+
importedAt: new Date().toISOString(),
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function addImport(entry) {
|
|
107
|
+
if (!entry || !entry.token) return
|
|
108
|
+
const rest = importStore.value.filter((item) => item.token !== entry.token)
|
|
109
|
+
setImports([entry, ...rest])
|
|
110
|
+
}
|
|
111
|
+
function removeImport(token) {
|
|
112
|
+
setImports(importStore.value.filter((item) => item.token !== token))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 点了「清空进程」:打包页上的旧报错、旧的失败结果也一起收掉,别留着当幽灵
|
|
116
|
+
const clearSignal = { subs: new Set() }
|
|
117
|
+
function fireClear() {
|
|
118
|
+
for (const fn of [...clearSignal.subs]) { try { fn() } catch (e) { /* 一个订阅出错不该拖垮别的 */ } }
|
|
119
|
+
}
|
|
120
|
+
function subscribeClear(fn) {
|
|
121
|
+
clearSignal.subs.add(fn)
|
|
122
|
+
return () => clearSignal.subs.delete(fn)
|
|
123
|
+
}
|
|
124
|
+
|
|
63
125
|
async function api(pathname, body) {
|
|
64
126
|
const init = body === undefined ? { headers: { Accept: "application/json" } } : {
|
|
65
127
|
method: "POST",
|
|
@@ -87,6 +149,51 @@ window.__ModuleLoader__.load({
|
|
|
87
149
|
return data
|
|
88
150
|
}
|
|
89
151
|
|
|
152
|
+
// 宿主有没有原生的目录选择器:有就能点「浏览文件夹…」,没有就退回手填
|
|
153
|
+
let pickDirectoryHost = null
|
|
154
|
+
|
|
155
|
+
const arrayBufferToBase64 = (buffer) => {
|
|
156
|
+
const view = new Uint8Array(buffer)
|
|
157
|
+
const chunk = 0x8000
|
|
158
|
+
let text = ""
|
|
159
|
+
for (let i = 0; i < view.length; i += chunk) {
|
|
160
|
+
text += String.fromCharCode.apply(null, view.subarray(i, i + chunk))
|
|
161
|
+
}
|
|
162
|
+
return btoa(text)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 把 .dshpack 交给宿主读:先按原始字节 POST,环境不允许时退回 base64 JSON
|
|
166
|
+
async function uploadPackFile(file) {
|
|
167
|
+
if (!file) throw new Error("没有拿到文件")
|
|
168
|
+
if (file.size && file.size > 250 * 1024 * 1024) throw new Error("文件太大(超过 250 MB)")
|
|
169
|
+
let firstError = ""
|
|
170
|
+
try {
|
|
171
|
+
const res = await fetch(API + "/pack/drop", {
|
|
172
|
+
method: "POST",
|
|
173
|
+
headers: { "Content-Type": "application/octet-stream" },
|
|
174
|
+
body: file,
|
|
175
|
+
})
|
|
176
|
+
const text = await res.text()
|
|
177
|
+
let data = null
|
|
178
|
+
try { data = JSON.parse(text) } catch {}
|
|
179
|
+
if (res.ok && data && data.ok) return data
|
|
180
|
+
firstError = (data && data.error) || ("HTTP " + res.status + (text ? ":" + text.slice(0, 120) : ""))
|
|
181
|
+
} catch (e) {
|
|
182
|
+
firstError = (e && e.message) || String(e)
|
|
183
|
+
}
|
|
184
|
+
// 退回 base64:有些环境不许 POST 二进制,JSON 一定通
|
|
185
|
+
let buffer
|
|
186
|
+
try { buffer = await file.arrayBuffer() } catch (e) { throw new Error("读文件失败:" + ((e && e.message) || e)) }
|
|
187
|
+
let data
|
|
188
|
+
try {
|
|
189
|
+
data = await api("/pack/drop", { name: file.name || "dropped.dshpack", data: arrayBufferToBase64(buffer) })
|
|
190
|
+
} catch (e) {
|
|
191
|
+
throw new Error(((e && e.message) || String(e)) + "(原始字节也没通:" + firstError + ")")
|
|
192
|
+
}
|
|
193
|
+
if (!data || !data.ok) throw new Error((data && data.error) || ("读取失败:" + firstError))
|
|
194
|
+
return data
|
|
195
|
+
}
|
|
196
|
+
|
|
90
197
|
const bytes = (n) => {
|
|
91
198
|
const v = Number(n) || 0
|
|
92
199
|
if (v < 1024) return v + " B"
|
|
@@ -141,22 +248,51 @@ window.__ModuleLoader__.load({
|
|
|
141
248
|
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
249
|
}
|
|
143
250
|
|
|
251
|
+
const ORIGIN_LABEL = { local: "本机", market: "市场", config: "配置", data: "数据", pack: "整合包" }
|
|
252
|
+
|
|
144
253
|
function ScanReport(props) {
|
|
145
254
|
const scan = props.scan
|
|
255
|
+
const counts = (scan && scan.counts) || { high: 0, medium: 0, low: 0 }
|
|
256
|
+
const findings = scan && Array.isArray(scan.findings) ? scan.findings : []
|
|
257
|
+
const [open, setOpen] = useState(counts.high > 0)
|
|
258
|
+
const [openGroup, setOpenGroup] = useState({})
|
|
146
259
|
if (!scan) return null
|
|
147
|
-
const
|
|
148
|
-
|
|
260
|
+
const groups = Array.isArray(props.groups) && props.groups.length
|
|
261
|
+
? props.groups
|
|
262
|
+
: (findings.length ? [{ key: "all", label: "全部命中", origin: "", counts, findings }] : [])
|
|
263
|
+
const toggleGroup = (key) => setOpenGroup((prev) => ({ ...prev, [key]: !prev[key] }))
|
|
264
|
+
const toggleOpen = () => setOpen((prev) => !prev)
|
|
149
265
|
return h("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } },
|
|
150
266
|
h("div", { style: row },
|
|
151
267
|
h("div", { style: strong }, "安全检测"),
|
|
152
268
|
h(Tag, { color: counts.high ? "#ff6b6b" : counts.medium ? "#ffb020" : "#2bb673" },
|
|
153
269
|
"高 " + counts.high + " · 中 " + counts.medium + " · 低 " + counts.low),
|
|
154
|
-
h("span", { style: hint }, "扫描 " + (scan.scannedFiles || 0) + " 个文件 / " + bytes(scan.scannedBytes || 0) + (scan.note ? " · " + scan.note : ""))
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
270
|
+
h("span", { style: hint }, "扫描 " + (scan.scannedFiles || 0) + " 个文件 / " + bytes(scan.scannedBytes || 0) + (scan.note ? " · " + scan.note : "")),
|
|
271
|
+
findings.length
|
|
272
|
+
? h("button", { style: { ...chipBtn, marginLeft: "auto" }, onClick: toggleOpen },
|
|
273
|
+
open ? "收起风险列表(" + findings.length + " 条)" : "展开风险列表(" + findings.length + " 条)")
|
|
274
|
+
: null),
|
|
275
|
+
findings.length === 0 ? h("div", { style: hint }, "没有命中敏感信息或可疑代码规则。") : null,
|
|
276
|
+
open && findings.length
|
|
277
|
+
? h("div", { style: { display: "flex", flexDirection: "column", gap: "6px" } },
|
|
278
|
+
groups.map((group) => {
|
|
279
|
+
const expanded = openGroup[group.key] === true
|
|
280
|
+
return h("div", { key: group.key, style: { border: "0.5px solid var(--dsw-alias-border-l2)", borderRadius: "6px", overflow: "hidden" } },
|
|
281
|
+
h("div", {
|
|
282
|
+
style: { display: "flex", alignItems: "center", gap: "8px", padding: "6px 9px", cursor: "pointer", background: "var(--dsw-alias-bg-l2, transparent)" },
|
|
283
|
+
onClick: () => toggleGroup(group.key),
|
|
284
|
+
},
|
|
285
|
+
h("span", { style: { ...label, fontSize: "12.5px" } }, group.label),
|
|
286
|
+
group.origin ? h(Tag, null, ORIGIN_LABEL[group.origin] || group.origin) : null,
|
|
287
|
+
h("span", { style: hint }, "高 " + group.counts.high + " · 中 " + group.counts.medium + " · 低 " + group.counts.low),
|
|
288
|
+
h("span", { style: { ...hint, marginLeft: "auto" } }, expanded ? "收起" : "展开")),
|
|
289
|
+
expanded
|
|
290
|
+
? h("div", { style: { display: "flex", flexDirection: "column", gap: "3px", padding: "0 9px 8px", maxHeight: "220px", overflow: "auto" } },
|
|
291
|
+
group.findings.map((f, i) => h("div", { key: i, style: { ...mono, color: LEVEL_COLOR[f.severity] || "inherit" } },
|
|
292
|
+
"[" + String(f.severity || "").toUpperCase() + "] " + (f.label || f.rule) + " · " + f.file + (f.line ? ":" + f.line : "") + " · " + (f.masked || ""))))
|
|
293
|
+
: null)
|
|
294
|
+
}))
|
|
295
|
+
: null,
|
|
160
296
|
h("div", { style: hint }, props.footNote || "命中内容只在内存里比对,报告只保留类型、位置与掩码,原文不落盘。"))
|
|
161
297
|
}
|
|
162
298
|
|
|
@@ -173,9 +309,285 @@ window.__ModuleLoader__.load({
|
|
|
173
309
|
f.suggestion ? h("div", { style: hint }, "建议:" + f.suggestion) : null)))
|
|
174
310
|
}
|
|
175
311
|
|
|
312
|
+
const JOB_KIND_LABEL = { pack: "打包", install: "安装" }
|
|
313
|
+
const JOB_STATUS_TEXT = { running: "进行中", paused: "等决定", acked: "已确认", done: "完成", failed: "失败", cancelled: "已取消" }
|
|
314
|
+
|
|
315
|
+
function useJobs(intervalMs) {
|
|
316
|
+
const [jobs, setJobs] = useState([])
|
|
317
|
+
useEffect(() => {
|
|
318
|
+
let alive = true
|
|
319
|
+
const load = async () => {
|
|
320
|
+
try {
|
|
321
|
+
const res = await fetch(API + "/jobs")
|
|
322
|
+
if (!res.ok) return
|
|
323
|
+
const data = await res.json()
|
|
324
|
+
if (alive && data && Array.isArray(data.jobs)) setJobs(data.jobs)
|
|
325
|
+
} catch { /* 轮询失败不该打断界面,下一次再试 */ }
|
|
326
|
+
}
|
|
327
|
+
load()
|
|
328
|
+
const timer = setInterval(load, intervalMs || 900)
|
|
329
|
+
return () => { alive = false; clearInterval(timer) }
|
|
330
|
+
}, [intervalMs])
|
|
331
|
+
return jobs
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function ProgressBar(props) {
|
|
335
|
+
const pct = Math.max(0, Math.min(100, Math.round(props.pct || 0)))
|
|
336
|
+
return h("div", { style: { height: "6px", borderRadius: "99px", background: "rgba(127,163,245,.18)", overflow: "hidden" } },
|
|
337
|
+
h("div", { style: { width: pct + "%", height: "100%", borderRadius: "99px", transition: "width .25s ease", background: props.tone || "linear-gradient(90deg,#7FA3F5,#4C7DF0)" } }))
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// 进度窗:可以拖,拖过的位置记在浏览器本地;没有任务时自动收起,只留一枚唤出按钮。
|
|
341
|
+
const DOCK_POS_KEY = "dsh-modpack-kit:dock-pos"
|
|
342
|
+
function readDockPos() {
|
|
343
|
+
try {
|
|
344
|
+
const raw = typeof localStorage !== "undefined" ? localStorage.getItem(DOCK_POS_KEY) : null
|
|
345
|
+
if (!raw) return null
|
|
346
|
+
const parsed = JSON.parse(raw)
|
|
347
|
+
if (!parsed || typeof parsed !== "object") return null
|
|
348
|
+
if (!Number.isFinite(Number(parsed.x)) || !Number.isFinite(Number(parsed.y))) return null
|
|
349
|
+
return { x: Math.max(0, Math.round(Number(parsed.x))), y: Math.max(0, Math.round(Number(parsed.y))) }
|
|
350
|
+
} catch { return null }
|
|
351
|
+
}
|
|
352
|
+
function writeDockPos(pos) {
|
|
353
|
+
try { if (typeof localStorage !== "undefined" && pos) localStorage.setItem(DOCK_POS_KEY, JSON.stringify(pos)) } catch { /* 存不了就算了,不影响本场使用 */ }
|
|
354
|
+
}
|
|
355
|
+
function viewportSize() {
|
|
356
|
+
const width = typeof window !== "undefined" && Number(window.innerWidth) ? Number(window.innerWidth) : 1280
|
|
357
|
+
const height = typeof window !== "undefined" && Number(window.innerHeight) ? Number(window.innerHeight) : 800
|
|
358
|
+
return { width, height }
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function JobDock(props) {
|
|
362
|
+
const given = Array.isArray(props.jobs) ? props.jobs : []
|
|
363
|
+
// 「清空进程」之后,就算服务端还残留一条,也在界面上立刻拿掉
|
|
364
|
+
const [cleared, setCleared] = useState([])
|
|
365
|
+
const jobs = given.filter((job) => !cleared.includes(job.id))
|
|
366
|
+
useEffect(() => {
|
|
367
|
+
setCleared((prev) => (prev.length === 0 ? prev : prev.filter((id) => given.some((job) => job.id === id))))
|
|
368
|
+
}, [given])
|
|
369
|
+
const [pos, setPos] = useState(readDockPos())
|
|
370
|
+
const [pinned, setPinned] = useState(false) // 手动唤出:没有任务时也显示
|
|
371
|
+
const [hidden, setHidden] = useState(false) // 手动收起:连进行中的也先藏起来
|
|
372
|
+
const [open, setOpen] = useState(false)
|
|
373
|
+
const [dockMsg, setDockMsg] = useState("")
|
|
374
|
+
const dragRef = useRef(null)
|
|
375
|
+
const boxRef = useRef(null)
|
|
376
|
+
const running = jobs.filter((job) => job.status === "running")
|
|
377
|
+
const visible = !hidden && (pinned || running.length > 0)
|
|
378
|
+
|
|
379
|
+
// 有任务开跑就自己冒出来(之前手动收起的也一并放出来)
|
|
380
|
+
useEffect(() => {
|
|
381
|
+
if (running.length > 0) { setHidden(false) }
|
|
382
|
+
}, [running.length])
|
|
383
|
+
|
|
384
|
+
const startDrag = (event) => {
|
|
385
|
+
if (!event || typeof event.clientX !== "number") return
|
|
386
|
+
// 按在按钮上就别当拖动:否则指针捕获会把 click 抢走,按钮点不到,
|
|
387
|
+
// 而且抬手时还会顺带把窗口展开/收起(就是「判定重叠」那个毛病)
|
|
388
|
+
if (event.target && typeof event.target.closest === "function" && event.target.closest("button")) return
|
|
389
|
+
const el = boxRef.current
|
|
390
|
+
const rect = el && el.getBoundingClientRect ? el.getBoundingClientRect() : { left: 0, top: 0, width: 0, height: 0 }
|
|
391
|
+
dragRef.current = {
|
|
392
|
+
dx: event.clientX - rect.left,
|
|
393
|
+
dy: event.clientY - rect.top,
|
|
394
|
+
width: rect.width,
|
|
395
|
+
height: rect.height,
|
|
396
|
+
startX: rect.left,
|
|
397
|
+
startY: rect.top,
|
|
398
|
+
moved: false,
|
|
399
|
+
last: null,
|
|
400
|
+
}
|
|
401
|
+
if (event.currentTarget && event.currentTarget.setPointerCapture && event.pointerId !== undefined) {
|
|
402
|
+
try { event.currentTarget.setPointerCapture(event.pointerId) } catch { /* 某些环境不支持捕获,照样能拖 */ }
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
const moveDrag = (event) => {
|
|
406
|
+
const drag = dragRef.current
|
|
407
|
+
if (!drag || !event || typeof event.clientX !== "number") return
|
|
408
|
+
const { width, height } = viewportSize()
|
|
409
|
+
const left = Math.min(Math.max(4, event.clientX - drag.dx), Math.max(4, width - drag.width - 4))
|
|
410
|
+
const top = Math.min(Math.max(4, event.clientY - drag.dy), Math.max(4, height - drag.height - 4))
|
|
411
|
+
if (Math.abs(left - drag.startX) > 3 || Math.abs(top - drag.startY) > 3) drag.moved = true
|
|
412
|
+
drag.last = { x: Math.round(left), y: Math.round(top) }
|
|
413
|
+
setPos(drag.last)
|
|
414
|
+
}
|
|
415
|
+
const endDrag = () => {
|
|
416
|
+
const drag = dragRef.current
|
|
417
|
+
if (!drag) return
|
|
418
|
+
dragRef.current = null
|
|
419
|
+
if (drag.moved) {
|
|
420
|
+
if (drag.last) writeDockPos(drag.last)
|
|
421
|
+
return
|
|
422
|
+
}
|
|
423
|
+
// 没拖动就是点了一下标题:展开 / 收起
|
|
424
|
+
setOpen((prev) => !prev)
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (!visible) {
|
|
428
|
+
const anchor = pos || null
|
|
429
|
+
const summonStyle = {
|
|
430
|
+
position: "fixed",
|
|
431
|
+
zIndex: 70,
|
|
432
|
+
display: "flex",
|
|
433
|
+
alignItems: "center",
|
|
434
|
+
gap: "6px",
|
|
435
|
+
padding: "7px 11px",
|
|
436
|
+
borderRadius: "999px",
|
|
437
|
+
border: "0.5px solid var(--dsw-alias-border-l2)",
|
|
438
|
+
background: "var(--dsw-alias-surface-1, rgba(24,26,31,.97))",
|
|
439
|
+
color: "var(--dsw-alias-label-primary)",
|
|
440
|
+
boxShadow: "0 6px 18px rgba(0,0,0,.28)",
|
|
441
|
+
cursor: "pointer",
|
|
442
|
+
fontSize: "12px",
|
|
443
|
+
...(anchor ? { left: anchor.x + "px", top: anchor.y + "px" } : { right: "16px", bottom: "16px" }),
|
|
444
|
+
}
|
|
445
|
+
const badge = running.length || jobs.length
|
|
446
|
+
return h("button", { style: summonStyle, title: "打开整合包进度窗", onClick: () => { setPinned(true); setHidden(false) } },
|
|
447
|
+
h("span", { style: { width: "7px", height: "7px", borderRadius: "99px", background: running.length ? "#4C7DF0" : "rgba(127,163,245,.5)" } }),
|
|
448
|
+
"进度",
|
|
449
|
+
badge ? h("span", { style: { ...hint, marginLeft: "0", fontVariantNumeric: "tabular-nums" } }, String(badge)) : null)
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const current = running[0] || jobs[0] || null
|
|
453
|
+
const headText = current
|
|
454
|
+
? (running.length ? (current.note || "处理中") : (JOB_STATUS_TEXT[current.status] || "打包记录"))
|
|
455
|
+
: "还没有任务"
|
|
456
|
+
const headPct = current ? Math.round(current.status === "done" ? 100 : (current.pct || 0)) : 0
|
|
457
|
+
const stop = async (id) => {
|
|
458
|
+
try { await api("/jobs/cancel", { id }) } catch { /* 已经结束就忽略 */ }
|
|
459
|
+
}
|
|
460
|
+
const ack = async (id) => {
|
|
461
|
+
try { await api("/jobs/ack", { id }) } catch (error) { setDockMsg((error && error.message) || "确认失败") }
|
|
462
|
+
}
|
|
463
|
+
const dismiss = async (id) => {
|
|
464
|
+
try {
|
|
465
|
+
await api("/jobs/dismiss", { id })
|
|
466
|
+
// 删掉一条也算收尾:安装页那条「完成 · 100%」的结论一起收掉
|
|
467
|
+
setCleared((prev) => (prev.includes(id) ? prev : [...prev, id]))
|
|
468
|
+
fireClear()
|
|
469
|
+
} catch (error) { setDockMsg((error && error.message) || "删除失败") }
|
|
470
|
+
}
|
|
471
|
+
const clearDone = async () => {
|
|
472
|
+
// 只看「收尾」的:正在跑的和停在风险点等你决定的,一律留着、照常显示
|
|
473
|
+
const targets = given.filter((job) => job.status !== "running" && job.status !== "paused")
|
|
474
|
+
if (targets.length === 0) {
|
|
475
|
+
setDockMsg("没有可清空的进程(正在跑的和停在风险点的会留着)")
|
|
476
|
+
return
|
|
477
|
+
}
|
|
478
|
+
// 先摘行:服务端慢一点也能立刻看到效果,不用等下一轮轮询
|
|
479
|
+
setCleared((prev) => [...new Set([...prev, ...targets.map((job) => job.id)])])
|
|
480
|
+
fireClear()
|
|
481
|
+
setDockMsg("已清 " + targets.length + " 条")
|
|
482
|
+
try {
|
|
483
|
+
await api("/jobs/clear", {})
|
|
484
|
+
return
|
|
485
|
+
} catch (ignored) { /* 老宿主没有这条路由:退回逐条删 */ }
|
|
486
|
+
let bad = 0
|
|
487
|
+
for (const job of targets) {
|
|
488
|
+
try { await api("/jobs/dismiss", { id: job.id }) } catch (error) { bad += 1 }
|
|
489
|
+
}
|
|
490
|
+
if (bad) setDockMsg("有 " + bad + " 条没删掉(可能还在跑),其余已清")
|
|
491
|
+
}
|
|
492
|
+
// 只要有一条不是「在跑」或「停在风险点」,就给清空入口(状态再怪也算收尾)
|
|
493
|
+
const finished = jobs.filter((job) => job.status !== "running" && job.status !== "paused")
|
|
494
|
+
|
|
495
|
+
return h("div", {
|
|
496
|
+
ref: boxRef,
|
|
497
|
+
style: {
|
|
498
|
+
position: "fixed",
|
|
499
|
+
zIndex: 70,
|
|
500
|
+
...(pos ? { left: pos.x + "px", top: pos.y + "px" } : { right: "16px", bottom: "16px" }),
|
|
501
|
+
width: open ? "380px" : "288px",
|
|
502
|
+
maxHeight: open ? "58vh" : "none",
|
|
503
|
+
overflow: "auto",
|
|
504
|
+
boxSizing: "border-box",
|
|
505
|
+
padding: "10px 12px",
|
|
506
|
+
borderRadius: "10px",
|
|
507
|
+
border: "0.5px solid var(--dsw-alias-border-l2)",
|
|
508
|
+
background: "var(--dsw-alias-surface-1, rgba(24,26,31,.97))",
|
|
509
|
+
boxShadow: "0 10px 30px rgba(0,0,0,.35)",
|
|
510
|
+
display: "flex",
|
|
511
|
+
flexDirection: "column",
|
|
512
|
+
gap: "7px",
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
h("div", {
|
|
516
|
+
style: { display: "flex", alignItems: "center", gap: "8px", cursor: "grab", userSelect: "none", touchAction: "none" },
|
|
517
|
+
title: "按住可以拖动;点一下展开或收起",
|
|
518
|
+
onPointerDown: startDrag,
|
|
519
|
+
onPointerMove: moveDrag,
|
|
520
|
+
onPointerUp: endDrag,
|
|
521
|
+
onPointerCancel: endDrag,
|
|
522
|
+
},
|
|
523
|
+
h("span", { style: { fontSize: "12px", color: "var(--dsw-alias-label-secondary, #b6bac3)", minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, headText),
|
|
524
|
+
h("span", { style: { marginLeft: "auto", fontSize: "12px", fontVariantNumeric: "tabular-nums" } }, headPct + "%"),
|
|
525
|
+
running.length > 1 ? h("span", { style: { ...hint, marginLeft: "0" } }, "+" + (running.length - 1)) : null,
|
|
526
|
+
jobs.length > 0
|
|
527
|
+
? h("button", {
|
|
528
|
+
type: "button",
|
|
529
|
+
style: { ...chipBtn, marginLeft: "2px", padding: "2px 8px", lineHeight: "18px", flexShrink: 0 },
|
|
530
|
+
title: "清掉所有收尾与失败的进程(跑着的和停在风险点的留着)",
|
|
531
|
+
onPointerDown: (event) => { if (event && event.stopPropagation) event.stopPropagation() },
|
|
532
|
+
onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation(); clearDone() },
|
|
533
|
+
}, "清空进程")
|
|
534
|
+
: null,
|
|
535
|
+
h("button", {
|
|
536
|
+
type: "button",
|
|
537
|
+
style: { ...chipBtn, marginLeft: "2px", padding: "2px 8px", lineHeight: "18px", flexShrink: 0 },
|
|
538
|
+
title: "收起(有任务时还会再冒出来)",
|
|
539
|
+
onPointerDown: (event) => { if (event && event.stopPropagation) event.stopPropagation() },
|
|
540
|
+
onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation(); setHidden(true); setPinned(false) },
|
|
541
|
+
}, "收起")),
|
|
542
|
+
current ? h(ProgressBar, { pct: headPct, tone: current.status === "failed" ? "#ff6b6b" : current.status === "cancelled" ? "#8b8f99" : undefined }) : null,
|
|
543
|
+
open
|
|
544
|
+
? (jobs.length === 0
|
|
545
|
+
? h("div", { style: hint }, "还没有打包或安装任务。开始一个就会出现在这里。")
|
|
546
|
+
: h("div", { style: { display: "flex", flexDirection: "column", gap: "8px", marginTop: "2px" } },
|
|
547
|
+
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)" } },
|
|
548
|
+
h("div", { style: row },
|
|
549
|
+
h("span", { style: { ...label, fontSize: "12.5px" } }, job.label || JOB_KIND_LABEL[job.kind] || "任务"),
|
|
550
|
+
h("span", { style: { ...hint, marginLeft: "auto" } }, (JOB_STATUS_TEXT[job.status] || job.status) + " · " + Math.round(job.pct || 0) + "%")),
|
|
551
|
+
h("div", { style: hint }, job.note || ""),
|
|
552
|
+
job.risk && job.status === "paused"
|
|
553
|
+
? h("div", { style: { ...hint, color: "#ff9b9b", display: "flex", flexDirection: "column", gap: "2px" } },
|
|
554
|
+
h("div", null, "检测到风险:高 " + (job.risk.high || 0) + " · 中 " + (job.risk.medium || 0) + " · 低 " + (job.risk.low || 0)),
|
|
555
|
+
h("div", { style: { fontSize: "10.5px" } }, job.risk.message || ""),
|
|
556
|
+
job.risk.groups && job.risk.groups.length
|
|
557
|
+
? h("div", { style: { fontSize: "10.5px" } },
|
|
558
|
+
job.risk.groups.map((g) => (g.label || "") + "(高 " + ((g.counts && g.counts.high) || 0) + " / 中 " + ((g.counts && g.counts.medium) || 0) + ")").join(" "))
|
|
559
|
+
: null)
|
|
560
|
+
: null,
|
|
561
|
+
h(ProgressBar, { pct: job.pct, tone: job.status === "failed" || job.status === "paused" ? "#ff6b6b" : job.status === "cancelled" ? "#8b8f99" : undefined }),
|
|
562
|
+
h("div", { style: { display: "flex", flexWrap: "wrap", gap: "6px" } },
|
|
563
|
+
job.status === "running" ? h("button", { style: { ...chipBtn }, onClick: () => stop(job.id) }, "终止") : null,
|
|
564
|
+
job.status === "done" && job.kind === "pack" && job.data && job.data.token
|
|
565
|
+
? h("button", {
|
|
566
|
+
style: { ...chipBtn, color: "#4C7DF0", borderColor: "#4C7DF0" },
|
|
567
|
+
title: "跳到打包页的下载部分",
|
|
568
|
+
onClick: () => { if (typeof props.onOpenResult === "function") props.onOpenResult(job) },
|
|
569
|
+
}, "下载安装包")
|
|
570
|
+
: null,
|
|
571
|
+
job.canAck
|
|
572
|
+
? h("button", { style: { ...chipBtn, color: "#ff6b6b", borderColor: "#ff6b6b" }, title: "忽略风险,在同一个任务里接着跑完", onClick: () => ack(job.id) }, "我知道在干什么")
|
|
573
|
+
: null,
|
|
574
|
+
job.status !== "running" && job.status !== "paused"
|
|
575
|
+
? h("button", { style: { ...chipBtn, color: "var(--dsw-alias-label-tertiary, #8b8f99)" }, title: "从列表里删掉这条记录", onClick: () => dismiss(job.id) }, "删除该进程")
|
|
576
|
+
: null,
|
|
577
|
+
job.error && job.status !== "paused" ? h("span", { style: { ...hint, color: "#ff6b6b" } }, job.error) : null)))))
|
|
578
|
+
: h("div", { style: { ...hint, fontSize: "10.5px" } },
|
|
579
|
+
(running.length ? running.length + " 个任务进行中 · " : "") + "按住标题能拖动,点标题展开看详情、也能中途终止"),
|
|
580
|
+
dockMsg
|
|
581
|
+
? h("div", { style: { ...hint, fontSize: "10.5px", color: "#ff6b6b", display: "flex", gap: "6px", alignItems: "center" } },
|
|
582
|
+
dockMsg,
|
|
583
|
+
h("button", { style: { ...chipBtn, marginLeft: "auto" }, onClick: () => setDockMsg("") }, "知道了"))
|
|
584
|
+
: null)
|
|
585
|
+
}
|
|
586
|
+
|
|
176
587
|
// —— 打包 ——
|
|
177
588
|
function PackPanel(props) {
|
|
178
589
|
const status = props.status
|
|
590
|
+
const jobs = Array.isArray(props.jobs) ? props.jobs : []
|
|
179
591
|
const pageSize = (status && status.config && status.config.catalogPageSize) || 20
|
|
180
592
|
const [installed, setInstalled] = useState((status && status.installed) || [])
|
|
181
593
|
const [marketInfo, setMarketInfo] = useState({}) // name -> 市场同名条目(标题/版本/分类)
|
|
@@ -190,7 +602,6 @@ window.__ModuleLoader__.load({
|
|
|
190
602
|
const [options, setOptions] = useState({
|
|
191
603
|
includePayload: true,
|
|
192
604
|
includeConfig: true,
|
|
193
|
-
includeLocalEdits: false,
|
|
194
605
|
scanBeforePack: true,
|
|
195
606
|
confirmLicense: false,
|
|
196
607
|
name: "DSH 整合包",
|
|
@@ -198,9 +609,15 @@ window.__ModuleLoader__.load({
|
|
|
198
609
|
author: "",
|
|
199
610
|
})
|
|
200
611
|
const [busy, setBusy] = useState("")
|
|
201
|
-
|
|
612
|
+
// 结果由 Home 保管(模块级缓存),切页签回来仍然在
|
|
613
|
+
const result = props.result === undefined ? null : props.result
|
|
614
|
+
const setResult = typeof props.setResult === "function" ? props.setResult : () => {}
|
|
615
|
+
const [started, setStarted] = useState("")
|
|
616
|
+
const [seenJobs, setSeenJobs] = useState({})
|
|
617
|
+
const [mountAt] = useState(() => Date.now())
|
|
202
618
|
const [error, setError] = useState("")
|
|
203
619
|
const [packNag, firePackNag] = useNag()
|
|
620
|
+
const resultRef = useRef(null)
|
|
204
621
|
|
|
205
622
|
const active = query.trim() !== "" || category !== "all"
|
|
206
623
|
|
|
@@ -312,15 +729,17 @@ window.__ModuleLoader__.load({
|
|
|
312
729
|
}
|
|
313
730
|
|
|
314
731
|
const picked = Object.keys(selected)
|
|
732
|
+
// 市场里没装的插件也能打包:走 npm 源(安装时由市场按版本取包)
|
|
733
|
+
const entrySource = (entry) => (entry.installed === false ? "npm" : "profile")
|
|
315
734
|
const toggle = (entry) => {
|
|
316
735
|
setSelected((prev) => {
|
|
317
736
|
const next = { ...prev }
|
|
318
737
|
if (next[entry.name]) delete next[entry.name]
|
|
319
738
|
else next[entry.name] = {
|
|
320
739
|
name: entry.name,
|
|
321
|
-
source: entry
|
|
740
|
+
source: entrySource(entry),
|
|
322
741
|
spec: entry.version || "",
|
|
323
|
-
mode:
|
|
742
|
+
mode: "base",
|
|
324
743
|
}
|
|
325
744
|
return next
|
|
326
745
|
})
|
|
@@ -334,20 +753,82 @@ window.__ModuleLoader__.load({
|
|
|
334
753
|
...prev,
|
|
335
754
|
[entry.name]: toMarket
|
|
336
755
|
? { name: entry.name, source: "npm", spec: entry.marketVersion || "", mode: "base" }
|
|
337
|
-
: { name: entry.name, source: "profile", spec: entry.version || "", mode:
|
|
756
|
+
: { name: entry.name, source: "profile", spec: entry.version || "", mode: "base" },
|
|
338
757
|
}
|
|
339
758
|
})
|
|
340
759
|
|
|
341
|
-
const
|
|
342
|
-
|
|
760
|
+
const addAllLocal = () => setSelected((prev) => {
|
|
761
|
+
const next = { ...prev }
|
|
762
|
+
for (const entry of localRows) {
|
|
763
|
+
if (!next[entry.name]) next[entry.name] = { name: entry.name, source: "profile", spec: entry.version || "", mode: "base" }
|
|
764
|
+
}
|
|
765
|
+
return next
|
|
766
|
+
})
|
|
767
|
+
const clearSelected = () => setSelected({})
|
|
768
|
+
|
|
769
|
+
const [jobMsg, setJobMsg] = useState("")
|
|
770
|
+
const pausedJobs = (props.jobs || []).filter((job) => job.kind === "pack" && job.status === "paused" && job.risk)
|
|
771
|
+
|
|
772
|
+
const ackJob = async (id) => {
|
|
773
|
+
setJobMsg("")
|
|
774
|
+
try {
|
|
775
|
+
const data = await api("/jobs/ack", { id })
|
|
776
|
+
if (!data || !data.ok) setJobMsg((data && data.error) || "确认失败")
|
|
777
|
+
} catch (e) { setJobMsg(String((e && e.message) || e)) }
|
|
778
|
+
}
|
|
779
|
+
// 停在风险点的任务:按插件分栏列出命中项,确认/删除都在这里做
|
|
780
|
+
const pausedRiskNodes = []
|
|
781
|
+
if (pausedJobs.length > 0) {
|
|
782
|
+
pausedRiskNodes.push(h("div", { key: "title", style: { ...strong, color: "#ff6b6b" } }, "打包停在风险点(" + pausedJobs.length + " 个任务)"))
|
|
783
|
+
pausedRiskNodes.push(h("div", { key: "hint", style: hint }, "下面是每个插件自己的命中项。确认后原任务从这个检测点接着跑完,不再重复检测。"))
|
|
784
|
+
for (const job of pausedJobs) {
|
|
785
|
+
const groupNodes = (job.risk.groups || []).map((group, index) => {
|
|
786
|
+
const sampleNodes = (group.samples || []).map((sample, i) => h("div", {
|
|
787
|
+
key: i,
|
|
788
|
+
style: { color: LEVEL_COLOR[sample.severity] || "inherit" },
|
|
789
|
+
}, "· " + (sample.label || "") + " " + (sample.file || "") + (sample.line ? ":" + sample.line : "")))
|
|
790
|
+
return h("div", {
|
|
791
|
+
key: index,
|
|
792
|
+
style: { ...box, padding: "8px 10px", background: "transparent", display: "flex", flexDirection: "column", gap: "4px" },
|
|
793
|
+
},
|
|
794
|
+
h("div", { style: row },
|
|
795
|
+
h(Tag, null, group.plugin || group.label),
|
|
796
|
+
h("span", { style: hint }, ORIGIN_LABEL[group.origin] || group.origin || ""),
|
|
797
|
+
h("span", { style: hint }, "高 " + ((group.counts && group.counts.high) || 0) + " · 中 " + ((group.counts && group.counts.medium) || 0) + " · 低 " + ((group.counts && group.counts.low) || 0))),
|
|
798
|
+
sampleNodes.length > 0
|
|
799
|
+
? h("div", { style: { ...mono, display: "flex", flexDirection: "column", gap: "2px" } }, sampleNodes)
|
|
800
|
+
: h("div", { style: hint }, "命中详情写进了包内 security/report.txt。"))
|
|
801
|
+
})
|
|
802
|
+
pausedRiskNodes.push(h("div", { key: job.id, style: { display: "flex", flexDirection: "column", gap: "6px" } },
|
|
803
|
+
h("div", { style: { ...row, justifyContent: "space-between" } },
|
|
804
|
+
h("div", { style: strong }, job.label || "打包任务"),
|
|
805
|
+
h("div", { style: row },
|
|
806
|
+
h("button", { style: { ...btn, borderColor: "#ff6b6b", color: "#ff6b6b" }, onClick: () => ackJob(job.id) }, "我知道在干什么"),
|
|
807
|
+
h("button", { style: btn, onClick: () => dismissJob(job.id) }, "删除该进程"))),
|
|
808
|
+
groupNodes))
|
|
809
|
+
}
|
|
810
|
+
pausedRiskNodes.push(h("div", { key: "msg", style: hint }, jobMsg))
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
const dismissJob = async (id) => {
|
|
814
|
+
setJobMsg("")
|
|
815
|
+
try {
|
|
816
|
+
const data = await api("/jobs/dismiss", { id })
|
|
817
|
+
if (!data || !data.ok) setJobMsg((data && data.error) || "删除失败")
|
|
818
|
+
} catch (e) { setJobMsg(String((e && e.message) || e)) }
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
const doPack = async (ack) => {
|
|
822
|
+
setError(""); setStarted(""); setBusy("start")
|
|
343
823
|
try {
|
|
344
824
|
const data = await api("/pack", {
|
|
825
|
+
async: true,
|
|
345
826
|
selection: picked.map((name) => selected[name]),
|
|
346
827
|
options: {
|
|
347
828
|
includePayload: options.includePayload,
|
|
348
829
|
includeConfig: options.includeConfig,
|
|
349
|
-
|
|
350
|
-
|
|
830
|
+
acknowledge: ack === true,
|
|
831
|
+
force: false,
|
|
351
832
|
confirmLicense: options.confirmLicense,
|
|
352
833
|
name: options.name,
|
|
353
834
|
description: options.description,
|
|
@@ -355,13 +836,44 @@ window.__ModuleLoader__.load({
|
|
|
355
836
|
},
|
|
356
837
|
})
|
|
357
838
|
if (!data) { setError("没有响应"); return }
|
|
358
|
-
if (!data.ok) {
|
|
359
|
-
|
|
839
|
+
if (!data.ok) { setError(data.error || "打包请求被拒绝"); return }
|
|
840
|
+
setStarted((data.job && data.job.label) || "打包任务")
|
|
360
841
|
} catch (e) {
|
|
361
842
|
setError(String((e && e.message) || e))
|
|
362
843
|
} finally { setBusy("") }
|
|
363
844
|
}
|
|
364
845
|
|
|
846
|
+
// 后台任务完成后,把结果搬回这一页(可以同时打好几个包)
|
|
847
|
+
useEffect(() => {
|
|
848
|
+
const finished = (props.jobs || []).filter((job) => job.kind === "pack" && job.status !== "running" && job.data && Date.parse(job.startedAt) >= mountAt)
|
|
849
|
+
const fresh = finished.filter((job) => !seenJobs[job.id])
|
|
850
|
+
if (fresh.length === 0) return
|
|
851
|
+
const nextSeen = { ...seenJobs }
|
|
852
|
+
for (const job of fresh) nextSeen[job.id] = true
|
|
853
|
+
setSeenJobs(nextSeen)
|
|
854
|
+
const payload = fresh[fresh.length - 1].data
|
|
855
|
+
if (payload && payload.ok) setResult(payload)
|
|
856
|
+
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 })
|
|
857
|
+
else if (payload && payload.cancelled) { setResult(null); setError(payload.error || "已取消") }
|
|
858
|
+
else { setResult(null); setError((payload && payload.error) || "打包失败,详情见左下角") }
|
|
859
|
+
}, [props.jobs])
|
|
860
|
+
|
|
861
|
+
// 从进度窗点「下载安装包」跳过来:滚到结果那一块
|
|
862
|
+
useEffect(() => {
|
|
863
|
+
if (!props.focus) return
|
|
864
|
+
const el = resultRef.current
|
|
865
|
+
if (el && typeof el.scrollIntoView === "function") {
|
|
866
|
+
try { el.scrollIntoView({ block: "start", behavior: "smooth" }) } catch { /* 老浏览器不支持行为参数,忽略 */ }
|
|
867
|
+
}
|
|
868
|
+
}, [props.focus])
|
|
869
|
+
|
|
870
|
+
// 「清空进程」之后,打包页上的旧报错与失败结果也一起收掉
|
|
871
|
+
useEffect(() => subscribeClear(() => {
|
|
872
|
+
setError("")
|
|
873
|
+
const current = props.result
|
|
874
|
+
if (current && (current.refused || current.error)) setResult(null)
|
|
875
|
+
}), [props.result])
|
|
876
|
+
|
|
365
877
|
const downloadPack = async () => {
|
|
366
878
|
if (!result || !result.token) return
|
|
367
879
|
setBusy("download")
|
|
@@ -395,17 +907,19 @@ window.__ModuleLoader__.load({
|
|
|
395
907
|
|
|
396
908
|
return h("div", { style: { display: "flex", flexDirection: "column", gap: "14px" } },
|
|
397
909
|
h(Notice, null,
|
|
398
|
-
h("b", null, "
|
|
399
|
-
"
|
|
910
|
+
h("b", null, "打包:将所选插件封装为一个 .dshpack 文件"),
|
|
911
|
+
" 完整版包含插件本体的全部文件;轻量版仅记录插件名称与版本,安装时按版本从插件市场下载。两种包在安装前均不修改 profile 内容。",
|
|
400
912
|
status && status.market && status.market.installed
|
|
401
|
-
? h("div", { style: { ...hint, marginTop: "6px" } }, "
|
|
402
|
-
: h("div", { style: { ...hint, marginTop: "6px" } }, "
|
|
403
|
-
h("div", { style: hint }, "
|
|
913
|
+
? h("div", { style: { ...hint, marginTop: "6px" } }, "已检测到插件市场 v" + status.market.version + ":本插件与其共用目录源与安装链路,但不依赖该插件,移除后打包与安装功能不受影响。")
|
|
914
|
+
: h("div", { style: { ...hint, marginTop: "6px" } }, "未检测到插件市场,功能不受影响:打包、安装与检测均在本地完成。建议先安装 dshmarket 以获得分类、搜索与「切换市场版」入口;未安装时,首次使用请点击「建立目录索引」。"),
|
|
915
|
+
h("div", { style: hint }, "目录中存在同名插件时,该条目末尾提供「(切换市场版)」入口:可将打包源切换为上架市场的上游原版,安装结果与从市场安装一致。")),
|
|
404
916
|
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
|
|
405
917
|
h("div", { style: row },
|
|
406
918
|
h("div", { style: strong }, "选择插件"),
|
|
407
919
|
h("input", { style: { ...input, flex: "1 1 200px" }, placeholder: "搜索插件名 / 描述(在插件市场目录里搜)", value: query, onChange: (e) => setQuery(e.target.value) }),
|
|
408
920
|
active ? h("button", { style: btn, onClick: () => { setQuery(""); setCategory("all") } }, "回到已装") : null,
|
|
921
|
+
h("button", { style: btn, onClick: addAllLocal, title: "把本机已装的全部插件加入选择(默认按基础配置打包,可逐个改)" }, "全部加入"),
|
|
922
|
+
h("button", { style: btn, disabled: picked.length === 0, onClick: clearSelected, title: "清空当前选择" }, "清除选择"),
|
|
409
923
|
h("span", { style: hint }, loading ? "读取中…" : active
|
|
410
924
|
? ("已选 " + picked.length + " · 匹配 " + search.total + " 条" + (searching ? " · 搜索中…" : "") + (search.total > rows.length ? " · 已加载 " + rows.length : ""))
|
|
411
925
|
: ("已选 " + picked.length + " 个 · 本机已装 " + localRows.length + " 个"))),
|
|
@@ -425,7 +939,7 @@ window.__ModuleLoader__.load({
|
|
|
425
939
|
search.error ? h("div", { style: { ...hint, color: "#ffb020" } }, search.error) : null,
|
|
426
940
|
h("div", { style: { display: "flex", flexDirection: "column", gap: "3px", maxHeight: "320px", overflow: "auto" } },
|
|
427
941
|
rows.length === 0
|
|
428
|
-
? h("div", { style: hint }, loading ? "
|
|
942
|
+
? h("div", { style: hint }, loading ? "读取中…" : active ? (searching ? "搜索中…" : "无匹配条目") : "本机尚未安装插件")
|
|
429
943
|
: rows.map((entry) => {
|
|
430
944
|
const on = Boolean(selected[entry.name])
|
|
431
945
|
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" } },
|
|
@@ -433,12 +947,12 @@ window.__ModuleLoader__.load({
|
|
|
433
947
|
h("div", { style: { flex: "1 1 220px", minWidth: "180px" } },
|
|
434
948
|
h("div", { style: label }, entry.title || entry.name, " ", h("span", { style: hint }, "@" + (entry.version || "?"))),
|
|
435
949
|
h("div", { style: hint }, (entry.description || "").slice(0, 110))),
|
|
436
|
-
h("span", { style: chip }, entry.installed === false ? "市场" : "本机"),
|
|
950
|
+
h("span", { style: chip }, entry.installed === false ? "市场 · 未装" : "本机"),
|
|
437
951
|
h("span", { style: { ...chip, color: "var(--dsw-alias-label-tertiary)" } }, labelOf(categoryOf(entry))),
|
|
438
952
|
entry.updateAvailable ? h(Tag, { color: "#2bb673" }, "市场版 " + (entry.marketVersion || entry.version) + " 更新") : null,
|
|
439
953
|
on ? h("input", {
|
|
440
954
|
style: { ...input, width: "120px" },
|
|
441
|
-
placeholder: selected[entry.name].source === "npm" ? "
|
|
955
|
+
placeholder: selected[entry.name].source === "npm" ? "版本,空=最新(从市场取包)" : "版本,空=本机版本",
|
|
442
956
|
value: selected[entry.name].spec || "",
|
|
443
957
|
onChange: (e) => setSpec(entry.name, e.target.value),
|
|
444
958
|
}) : null,
|
|
@@ -455,14 +969,13 @@ window.__ModuleLoader__.load({
|
|
|
455
969
|
h("button", { style: btn, disabled: searching, onClick: loadMore }, searching ? "加载中…" : ("加载更多(还有 " + Math.max(0, search.total - rows.length) + " 条)"))) : null,
|
|
456
970
|
h("div", { style: hint }, active
|
|
457
971
|
? "排序:已装的排前面,其余按插件市场的相关度与目录顺序。分类和词条都来自插件市场目录。"
|
|
458
|
-
: "
|
|
972
|
+
: "首屏只列本机已装。搜索或点分类才会去插件市场目录里查,服务端分页、一次一页。搜索结果里没装的插件也能直接勾选——打包时按版本从插件市场取包,装的时候同样从市场下载。")
|
|
459
973
|
),
|
|
460
974
|
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
461
975
|
h("div", { style: strong }, "包选项"),
|
|
462
976
|
h("div", { style: { ...row, rowGap: "6px" } },
|
|
463
977
|
h(Switch, { checked: options.includePayload, label: "包含插件本体(关=轻量版)", onChange: (v) => setOptions({ ...options, includePayload: v }) }),
|
|
464
978
|
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
979
|
h(ForcedSwitch, { label: "打包前安全检测(强制)", onNag: () => firePackNag("你想干什么") })),
|
|
467
980
|
h(NagText, { text: packNag }),
|
|
468
981
|
h("div", { style: { ...row, rowGap: "6px" } },
|
|
@@ -471,18 +984,27 @@ window.__ModuleLoader__.load({
|
|
|
471
984
|
h("input", { style: { ...input, width: "100%" }, placeholder: "一句话描述(可空)", value: options.description, onChange: (e) => setOptions({ ...options, description: e.target.value }) }),
|
|
472
985
|
h(Switch, { checked: options.confirmLicense, label: "我确认所选插件的许可证允许再分发,或已获得作者授权", onChange: (v) => setOptions({ ...options, confirmLicense: v }) }),
|
|
473
986
|
h("div", { style: row },
|
|
474
|
-
h("button", { style: btnPrimary, disabled: picked.length === 0 || busy === "
|
|
987
|
+
h("button", { style: btnPrimary, disabled: picked.length === 0 || busy === "start", onClick: doPack }, busy === "start" ? "提交中…" : ("打包 " + picked.length + " 个插件")),
|
|
988
|
+
started ? h("span", { style: hint }, "已开始:" + started + "(进度在左下角,可以接着选别的再打一个)") : null,
|
|
475
989
|
status ? h("span", { style: hint }, "DSH " + (status.dshVersion || "?") + " · profile " + status.profile) : null)),
|
|
990
|
+
pausedRiskNodes.length ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px", borderColor: "#d9534f" } }, pausedRiskNodes) : null,
|
|
476
991
|
error ? h(Notice, { tone: "bad" }, error) : null,
|
|
477
|
-
result ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
|
|
992
|
+
result ? h("div", { ref: resultRef, style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
|
|
478
993
|
result.refused || result.error
|
|
479
|
-
? h(Notice, { tone: "warn" },
|
|
994
|
+
? h(Notice, { tone: "warn" },
|
|
995
|
+
h("b", null, "已停止:"), result.error || "未通过检查",
|
|
996
|
+
result.needsAck ? h("div", { style: { ...row, marginTop: "8px" } },
|
|
997
|
+
h("button", {
|
|
998
|
+
style: { ...btn, borderColor: "#ff6b6b", color: "#ff6b6b" },
|
|
999
|
+
disabled: busy === "start",
|
|
1000
|
+
onClick: () => doPack(true),
|
|
1001
|
+
}, busy === "start" ? "提交中…" : "我已知晓其中风险,继续打包")) : null)
|
|
480
1002
|
: h("div", { style: row },
|
|
481
1003
|
h("div", { style: strong }, result.fileName),
|
|
482
1004
|
h(Tag, { color: "#2bb673" }, bytes(result.size)),
|
|
483
1005
|
h(Tag, null, FORMAT_TEXT[result.manifest && result.manifest.format] || ""),
|
|
484
1006
|
h("span", { style: hint }, "包内插件 " + ((result.manifest && result.manifest.plugins) || []).length + " 个")),
|
|
485
|
-
result.scan ? h(ScanReport, { scan: result.scan, footNote: "报告已写进包内 security/report.txt(只含类型与掩码)。" }) : null,
|
|
1007
|
+
result.scan ? h(ScanReport, { scan: result.scan, groups: result.scanGroups, footNote: "报告已写进包内 security/report.txt(只含类型与掩码)。" }) : null,
|
|
486
1008
|
result.manifest && result.manifest.plugins && result.manifest.plugins.length
|
|
487
1009
|
? h("div", { style: { display: "flex", flexDirection: "column", gap: "2px" } },
|
|
488
1010
|
result.manifest.plugins.map((p) => h("div", { key: p.name, style: mono },
|
|
@@ -494,7 +1016,7 @@ window.__ModuleLoader__.load({
|
|
|
494
1016
|
h("button", { style: btnPrimary, disabled: busy !== "", onClick: downloadPack }, busy === "download" ? "准备下载…" : "下载 .dshpack"),
|
|
495
1017
|
h("button", { style: btn, disabled: busy !== "", onClick: savePack }, busy === "save" ? "保存中…" : "保存到本机 packs/"),
|
|
496
1018
|
result.savedPath ? h("span", { style: hint }, "已存:" + result.savedPath) : null),
|
|
497
|
-
result.refused || result.error ? null : h("div", { style: hint }, "
|
|
1019
|
+
result.refused || result.error ? null : h("div", { style: hint }, "下载后可在「安装 / 导入」页签读回,或将该文件转交他人。"))
|
|
498
1020
|
: null)
|
|
499
1021
|
}
|
|
500
1022
|
|
|
@@ -502,22 +1024,100 @@ window.__ModuleLoader__.load({
|
|
|
502
1024
|
function InstallPanel(props) {
|
|
503
1025
|
const [source, setSource] = useState({ kind: "url", url: "", file: "" })
|
|
504
1026
|
const [packs, setPacks] = useState([])
|
|
1027
|
+
const [dirInput, setDirInput] = useState((props.status && props.status.paths && props.status.paths.packs) || "")
|
|
1028
|
+
const [dirInfo, setDirInfo] = useState({ dir: (props.status && props.status.paths && props.status.paths.packs) || "", error: "" })
|
|
505
1029
|
const [preview, setPreview] = useState(null)
|
|
506
1030
|
const [busy, setBusy] = useState("")
|
|
507
1031
|
const [error, setError] = useState("")
|
|
508
1032
|
const [done, setDone] = useState(null)
|
|
509
|
-
const [options, setOptions] = useState({ keepLocal: true, applyConfig: true, force: false, dryRun: false, enableBundles: !!((props.status && props.status.config && props.status.config.enableOnInstall) === true) })
|
|
1033
|
+
const [options, setOptions] = useState({ keepLocal: true, applyConfig: true, force: false, dryRun: false, preferMarket: !!((props.status && props.status.config && props.status.config.preferMarketOnInstall !== false)), enableBundles: !!((props.status && props.status.config && props.status.config.enableOnInstall) === true) })
|
|
1034
|
+
// 安装也走任务队列:进度直接显示在左下角那个窗里,这里留一份给页面内看
|
|
1035
|
+
const [progress, setProgress] = useState(null)
|
|
1036
|
+
const [deferred, setDeferred] = useState([])
|
|
1037
|
+
const [askReplace, setAskReplace] = useState(false)
|
|
1038
|
+
const [imports, setImportsState] = useState(readImports())
|
|
1039
|
+
|
|
1040
|
+
// 已导入的几份包各自留在列表里:切页签、开关进度窗都不丢
|
|
1041
|
+
useEffect(() => subscribeImports((next) => setImportsState(next)), [])
|
|
1042
|
+
|
|
1043
|
+
// 进度窗里点了「清空进程」:安装页上那条「完成 / 失败」的结论也一起收掉,别留着当幽灵
|
|
1044
|
+
useEffect(() => subscribeClear(() => {
|
|
1045
|
+
setProgress(null)
|
|
1046
|
+
setDone(null)
|
|
1047
|
+
setDeferred([])
|
|
1048
|
+
setAskReplace(false)
|
|
1049
|
+
setError("")
|
|
1050
|
+
}), [])
|
|
1051
|
+
|
|
1052
|
+
const fileRef = useRef(null)
|
|
1053
|
+
|
|
1054
|
+
// 用「打开文件」的方式挑一个 .dshpack:字节直接读,不要求你写路径
|
|
1055
|
+
const pickFile = async (file) => {
|
|
1056
|
+
if (!file) return
|
|
1057
|
+
if (!/\.dshpack$/i.test(file.name || "")) { setError("只认 .dshpack 整合包"); return }
|
|
1058
|
+
setBusy("upload"); setError(""); setDone(null); setDeferred([]); setAskReplace(false)
|
|
1059
|
+
try {
|
|
1060
|
+
const data = await uploadPackFile(file)
|
|
1061
|
+
setSource({ kind: "token", token: data.token, url: "", file: "" })
|
|
1062
|
+
setPreview(data)
|
|
1063
|
+
addImport(importEntry(data, file.name))
|
|
1064
|
+
} catch (e) {
|
|
1065
|
+
setError((e && e.message) || String(e))
|
|
1066
|
+
} finally { setBusy("") }
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
// 从「已导入的整合包」里挑一份:重新读一遍拿预览(token 过期就提示并去掉这条)
|
|
1070
|
+
const pickImport = async (item) => {
|
|
1071
|
+
if (!item || !item.token) return
|
|
1072
|
+
setBusy("import"); setError(""); setDone(null); setDeferred([]); setAskReplace(false)
|
|
1073
|
+
try {
|
|
1074
|
+
const data = await api("/inspect", { token: item.token })
|
|
1075
|
+
if (!data || data.ok !== true) throw new Error((data && data.error) || "这份导入的包已经过期了,重新导入一次")
|
|
1076
|
+
setSource({ kind: "token", token: item.token, url: "", file: "" })
|
|
1077
|
+
setPreview(data)
|
|
1078
|
+
} catch (e) {
|
|
1079
|
+
const message = (e && e.message) || String(e)
|
|
1080
|
+
setError(message)
|
|
1081
|
+
if (/过期|找不到|expired/iu.test(message)) removeImport(item.token)
|
|
1082
|
+
} finally { setBusy("") }
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
// 原生目录选择器:拿到绝对路径就填进去并列出该目录的 .dshpack
|
|
1086
|
+
const browseFolder = async () => {
|
|
1087
|
+
if (typeof pickDirectoryHost !== "function") {
|
|
1088
|
+
setDirInfo({ ...dirInfo, error: "这个环境没有系统目录选择器,直接在上面填路径也能用" })
|
|
1089
|
+
return
|
|
1090
|
+
}
|
|
1091
|
+
setBusy("dir")
|
|
1092
|
+
try {
|
|
1093
|
+
const picked = await pickDirectoryHost()
|
|
1094
|
+
if (picked) {
|
|
1095
|
+
setDirInput(picked)
|
|
1096
|
+
await reloadPacks(picked)
|
|
1097
|
+
}
|
|
1098
|
+
} catch (e) {
|
|
1099
|
+
setDirInfo({ ...dirInfo, error: "打不开目录选择器:" + ((e && e.message) || e) })
|
|
1100
|
+
} finally { setBusy("") }
|
|
1101
|
+
}
|
|
510
1102
|
|
|
511
|
-
|
|
1103
|
+
// 列目录:不传目录就看插件自己的 packs,传了就看你指定的目录
|
|
1104
|
+
const reloadPacks = useCallback(async (dir) => {
|
|
1105
|
+
const want = typeof dir === "string" ? dir.trim() : ""
|
|
512
1106
|
try {
|
|
513
|
-
const data = await api("/packs")
|
|
514
|
-
if (data && data.
|
|
515
|
-
|
|
1107
|
+
const data = want ? await api("/packs", { dir: want }) : await api("/packs")
|
|
1108
|
+
if (data && data.items) setPacks(data.items)
|
|
1109
|
+
setDirInfo({ dir: (data && data.dir) || want, error: (data && data.error) || "" })
|
|
1110
|
+
} catch (e) {
|
|
1111
|
+
setDirInfo({ dir: want, error: (e && e.message) || String(e) })
|
|
1112
|
+
}
|
|
516
1113
|
}, [])
|
|
517
1114
|
useEffect(() => { reloadPacks() }, [reloadPacks])
|
|
518
1115
|
|
|
1116
|
+
// 拖进来的包:外面读好了,这里接住直接当预览
|
|
1117
|
+
|
|
519
1118
|
const bodyFor = () => {
|
|
520
1119
|
if (source.kind === "url") return { url: source.url.trim() }
|
|
1120
|
+
if (source.kind === "token") return { token: source.token }
|
|
521
1121
|
return { file: source.file }
|
|
522
1122
|
}
|
|
523
1123
|
|
|
@@ -532,18 +1132,73 @@ window.__ModuleLoader__.load({
|
|
|
532
1132
|
} finally { setBusy("") }
|
|
533
1133
|
}
|
|
534
1134
|
|
|
1135
|
+
// 等一个任务跑完(安装同样在后台跑,进度窗里能看到)
|
|
1136
|
+
const waitJob = async (jobId) => {
|
|
1137
|
+
const started = Date.now()
|
|
1138
|
+
while (Date.now() - started < 15 * 60 * 1000) {
|
|
1139
|
+
const data = await api("/jobs")
|
|
1140
|
+
const job = data && data.jobs ? data.jobs.find((item) => item.id === jobId) : null
|
|
1141
|
+
if (!job) throw new Error("任务不见了(可能已过期),再试一次")
|
|
1142
|
+
setProgress({ pct: job.pct, note: job.note, status: job.status })
|
|
1143
|
+
if (job.status !== "running") return job
|
|
1144
|
+
await new Promise((resolve) => setTimeout(resolve, 700))
|
|
1145
|
+
}
|
|
1146
|
+
throw new Error("等了 15 分钟还没结束,去左下角看看是不是卡住了")
|
|
1147
|
+
}
|
|
1148
|
+
|
|
535
1149
|
const install = async () => {
|
|
536
|
-
setBusy("install"); setError(""); setDone(null)
|
|
1150
|
+
setBusy("install"); setError(""); setDone(null); setDeferred([]); setAskReplace(false); setProgress(null)
|
|
537
1151
|
try {
|
|
538
|
-
const data = await api("/install", { ...bodyFor(), ...options })
|
|
539
|
-
if (!data.ok) {
|
|
540
|
-
|
|
1152
|
+
const data = await api("/install", { ...bodyFor(), ...options, async: true })
|
|
1153
|
+
if (!data || data.ok !== true || !data.job) {
|
|
1154
|
+
// 老宿主不认 async:退回同步调用
|
|
1155
|
+
const plain = await api("/install", { ...bodyFor(), ...options })
|
|
1156
|
+
if (!plain.ok) {
|
|
1157
|
+
setDone({ ok: false, error: plain.error, refused: plain.refused, scan: plain.scan, report: plain.report })
|
|
1158
|
+
return
|
|
1159
|
+
}
|
|
1160
|
+
setDone(plain)
|
|
1161
|
+
setDeferred(Array.isArray(plain.deferred) ? plain.deferred : [])
|
|
1162
|
+
setAskReplace(Array.isArray(plain.deferred) && plain.deferred.length > 0)
|
|
1163
|
+
return
|
|
1164
|
+
}
|
|
1165
|
+
const job = await waitJob(data.job.id)
|
|
1166
|
+
const payload = job.data || {}
|
|
1167
|
+
// 结果已经拿到页面上了,这条任务就从进度窗里摘掉:不用你再去点一次清空
|
|
1168
|
+
try { await api("/jobs/dismiss", { id: job.id }) } catch (ignored) { /* 老宿主没有这条路由就留着 */ }
|
|
1169
|
+
if (job.status === "cancelled") { setDone({ ok: false, error: "已取消(没有改动 profile)" }); return }
|
|
1170
|
+
if (!payload.ok) {
|
|
1171
|
+
setDone({ ok: false, error: payload.error || job.error || "安装失败", refused: Boolean(payload.refused), scan: payload.scan, report: payload.report })
|
|
541
1172
|
return
|
|
542
1173
|
}
|
|
543
|
-
setDone(
|
|
1174
|
+
setDone(payload)
|
|
1175
|
+
setDeferred(Array.isArray(payload.deferred) ? payload.deferred : [])
|
|
1176
|
+
setAskReplace(Array.isArray(payload.deferred) && payload.deferred.length > 0)
|
|
544
1177
|
} catch (e) {
|
|
545
1178
|
setDone({ ok: false, error: e.message || String(e), scan: (e.data && e.data.scan) || null, report: (e.data && e.data.report) || "", refused: Boolean(e.data && e.data.refused) })
|
|
546
|
-
} finally { setBusy("") }
|
|
1179
|
+
} finally { setBusy(""); setProgress(null) }
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
// 把刚才跳过的换成包内版本
|
|
1183
|
+
const replaceDeferred = async (names) => {
|
|
1184
|
+
if (!done || !done.token) { setError("这次安装的上下文过期了,重新读一遍包"); return }
|
|
1185
|
+
setBusy("replace"); setError("")
|
|
1186
|
+
try {
|
|
1187
|
+
const data = await api("/install/replace", { token: done.token, names, async: true })
|
|
1188
|
+
if (!data || data.ok !== true || !data.job) {
|
|
1189
|
+
const plain = await api("/install/replace", { token: done.token, names })
|
|
1190
|
+
if (!plain.ok) { setError(plain.error || "替换失败"); return }
|
|
1191
|
+
setDone(plain); setDeferred(Array.isArray(plain.deferred) ? plain.deferred : []); setAskReplace(false)
|
|
1192
|
+
return
|
|
1193
|
+
}
|
|
1194
|
+
const job = await waitJob(data.job.id)
|
|
1195
|
+
const payload = job.data || {}
|
|
1196
|
+
try { await api("/jobs/dismiss", { id: job.id }) } catch (ignored) { /* 同上 */ }
|
|
1197
|
+
if (!payload.ok) { setError(payload.error || job.error || "替换失败"); return }
|
|
1198
|
+
setDone(payload); setDeferred([]); setAskReplace(false)
|
|
1199
|
+
} catch (e) {
|
|
1200
|
+
setError(e.message || String(e))
|
|
1201
|
+
} finally { setBusy(""); setProgress(null) }
|
|
547
1202
|
}
|
|
548
1203
|
|
|
549
1204
|
return h("div", { style: { display: "flex", flexDirection: "column", gap: "14px" } },
|
|
@@ -551,28 +1206,106 @@ window.__ModuleLoader__.load({
|
|
|
551
1206
|
h("b", null, "先看清楚,再装"),
|
|
552
1207
|
" 读取阶段解压、校验完整性、扫一遍风险,全部在内存里完成;只有你点「安装」才会碰 profile。安装走官方 ",
|
|
553
1208
|
h("code", { style: mono }, "dsh plugin add"), ",不手改 node_modules。"),
|
|
1209
|
+
imports.length > 0
|
|
1210
|
+
? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
1211
|
+
h("div", { style: row },
|
|
1212
|
+
h("div", { style: strong }, "已导入的整合包"),
|
|
1213
|
+
h("span", { style: hint }, imports.length + " 份 · 可以同时留着,各自显示打包时的名字、作者与描述"),
|
|
1214
|
+
h("button", { style: { ...chipBtn, marginLeft: "auto" }, onClick: () => setImports([]) }, "全部移除")),
|
|
1215
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "8px", maxHeight: "260px", overflow: "auto" } },
|
|
1216
|
+
imports.map((item) => h("div", {
|
|
1217
|
+
key: item.token,
|
|
1218
|
+
style: {
|
|
1219
|
+
display: "flex",
|
|
1220
|
+
flexDirection: "column",
|
|
1221
|
+
gap: "3px",
|
|
1222
|
+
padding: "8px 10px",
|
|
1223
|
+
borderRadius: "8px",
|
|
1224
|
+
border: "0.5px solid " + (source.kind === "token" && source.token === item.token ? "#4C7DF0" : "var(--dsw-alias-border-l2)"),
|
|
1225
|
+
},
|
|
1226
|
+
},
|
|
1227
|
+
h("div", { style: row },
|
|
1228
|
+
h("span", { style: { ...label, fontSize: "13px" } }, item.name),
|
|
1229
|
+
h(Tag, null, FORMAT_TEXT[item.format] || item.format || "整合包"),
|
|
1230
|
+
h("span", { style: hint }, item.plugins + " 个插件"),
|
|
1231
|
+
h("button", {
|
|
1232
|
+
style: { ...chipBtn, marginLeft: "auto" },
|
|
1233
|
+
disabled: busy !== "",
|
|
1234
|
+
onClick: () => pickImport(item),
|
|
1235
|
+
}, source.kind === "token" && source.token === item.token ? "当前选中" : "选择"),
|
|
1236
|
+
h("button", {
|
|
1237
|
+
style: { ...chipBtn, color: "var(--dsw-alias-label-tertiary, #8b8f99)" },
|
|
1238
|
+
onClick: () => {
|
|
1239
|
+
removeImport(item.token)
|
|
1240
|
+
if (source.kind === "token" && source.token === item.token) {
|
|
1241
|
+
setSource({ kind: "url", url: "", file: "" })
|
|
1242
|
+
setPreview(null)
|
|
1243
|
+
}
|
|
1244
|
+
},
|
|
1245
|
+
}, "移除")),
|
|
1246
|
+
h("div", { style: { ...hint, fontSize: "10.5px" } },
|
|
1247
|
+
"作者:" + (item.author || "未填写") + " · 生成于 " + (item.createdAt ? when(item.createdAt) : "未知")),
|
|
1248
|
+
item.description ? h("div", { style: { ...hint, fontSize: "11.5px", color: "var(--dsw-alias-label-secondary, #b6bac3)" } }, item.description) : null,
|
|
1249
|
+
item.fileName ? h("div", { style: { ...hint, fontSize: "10px" } }, item.fileName) : null))))
|
|
1250
|
+
: null,
|
|
554
1251
|
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
|
|
555
1252
|
h("div", { style: row },
|
|
556
1253
|
h("button", { style: source.kind === "url" ? btnPrimary : btn, onClick: () => setSource({ ...source, kind: "url" }) }, "从链接读取"),
|
|
557
|
-
h("button", { style: source.kind === "file" ? btnPrimary : btn, onClick: () => setSource({ ...source, kind: "file" }) }, "
|
|
1254
|
+
h("button", { style: source.kind === "file" ? btnPrimary : btn, onClick: () => setSource({ ...source, kind: "file" }) }, "从本机文件读取"),
|
|
1255
|
+
h("input", {
|
|
1256
|
+
type: "file",
|
|
1257
|
+
accept: ".dshpack",
|
|
1258
|
+
ref: fileRef,
|
|
1259
|
+
style: { display: "none" },
|
|
1260
|
+
onChange: (e) => {
|
|
1261
|
+
const picked = e && e.target && e.target.files ? e.target.files[0] : null
|
|
1262
|
+
if (picked) pickFile(picked)
|
|
1263
|
+
if (e && e.target) e.target.value = ""
|
|
1264
|
+
},
|
|
1265
|
+
}),
|
|
1266
|
+
h("button", { style: btn, disabled: busy !== "", onClick: () => { if (fileRef.current) fileRef.current.click() } }, busy === "upload" ? "读取中…" : "选择文件…"),
|
|
1267
|
+
source.kind === "token"
|
|
1268
|
+
? h("button", { style: btnPrimary, onClick: () => { if (imports.length === 0) setSource({ ...source, kind: "url" }) } }, "已导入的整合包")
|
|
1269
|
+
: null),
|
|
558
1270
|
source.kind === "url"
|
|
559
1271
|
? h("input", { style: { ...input, width: "100%" }, placeholder: "https://…/xxx.dshpack", value: source.url, onChange: (e) => setSource({ ...source, url: e.target.value }) })
|
|
560
|
-
: h("div", { style:
|
|
561
|
-
h("div", { style:
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
1272
|
+
: h("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } },
|
|
1273
|
+
h("div", { style: row },
|
|
1274
|
+
h("input", {
|
|
1275
|
+
style: { ...input, flex: "1 1 320px" },
|
|
1276
|
+
placeholder: "整合包所在的目录(默认是插件自己的 packs)",
|
|
1277
|
+
value: dirInput,
|
|
1278
|
+
onChange: (e) => setDirInput(e.target.value),
|
|
1279
|
+
onKeyDown: (e) => { if (e.key === "Enter") reloadPacks(dirInput) },
|
|
1280
|
+
}),
|
|
1281
|
+
h("button", { style: btn, disabled: busy !== "", onClick: browseFolder }, busy === "dir" ? "选择中…" : "浏览文件夹…"),
|
|
1282
|
+
h("button", { style: btn, onClick: () => reloadPacks(dirInput) }, "读这个目录"),
|
|
1283
|
+
h("button", { style: btn, onClick: () => reloadPacks() }, "回到默认")),
|
|
1284
|
+
dirInfo.error ? h("div", { style: { ...hint, color: "#ff6b6b" } }, dirInfo.error) : null,
|
|
1285
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "3px", maxHeight: "170px", overflow: "auto" } },
|
|
1286
|
+
packs.length === 0 ? h("div", { style: hint }, "这个目录里没有 .dshpack。先去打包页生成一个,或者把文件拖到界面上。") : null,
|
|
1287
|
+
packs.map((p) => h("label", { key: p.path || p.name, style: { ...row, gap: "6px", cursor: "pointer" } },
|
|
1288
|
+
h("input", { type: "radio", name: "packfile", checked: source.file === (p.path || p.name), onChange: () => setSource({ ...source, file: p.path || p.name }) }),
|
|
565
1289
|
h("span", { style: label }, p.name),
|
|
566
1290
|
h("span", { style: hint }, bytes(p.size) + " · " + when(p.mtime))))),
|
|
567
|
-
h("
|
|
1291
|
+
dirInfo.dir ? h("div", { style: { ...hint, fontSize: "10.5px" } }, "当前目录:" + dirInfo.dir) : null),
|
|
568
1292
|
h("div", { style: row },
|
|
569
1293
|
h(Switch, { checked: options.keepLocal, label: "保留本地已有修改(不覆盖已装插件)", onChange: (v) => setOptions({ ...options, keepLocal: v }) }),
|
|
570
1294
|
h(Switch, { checked: options.applyConfig, label: "安装后回填包内配置", onChange: (v) => setOptions({ ...options, applyConfig: v }) }),
|
|
1295
|
+
h(Switch, { checked: options.preferMarket, label: "联网时优先用插件市场的版本(市场查不到就用包内的)", onChange: (v) => setOptions({ ...options, preferMarket: v }) }),
|
|
571
1296
|
h(Switch, { checked: options.enableBundles, label: "安装后直接启用(登记 bundle,重启后加载;默认关)", onChange: (v) => setOptions({ ...options, enableBundles: v }) }),
|
|
572
1297
|
h(Switch, { checked: options.force, label: "忽略阻断(我知道自己在干什么)", onChange: (v) => setOptions({ ...options, force: v }) })),
|
|
573
1298
|
h("div", { style: row },
|
|
574
1299
|
h("button", { style: btnPrimary, disabled: busy !== "" || (source.kind === "url" ? !source.url.trim() : !source.file), onClick: inspect }, busy === "inspect" ? "检测中…" : "检测这个包"),
|
|
575
|
-
source.kind === "file" && source.file ? h("span", { style: hint }, "选中:" + source.file) : null
|
|
1300
|
+
source.kind === "file" && source.file ? h("span", { style: hint }, "选中:" + source.file) : null,
|
|
1301
|
+
source.kind === "token" ? h("span", { style: hint }, "这份是导入到列表里的包,已经读过一遍;点上面的「选择」可以换另一份") : null)),
|
|
1302
|
+
progress
|
|
1303
|
+
? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
1304
|
+
h("div", { style: row },
|
|
1305
|
+
h("div", { style: strong }, "正在安装"),
|
|
1306
|
+
h("span", { style: hint }, (progress.note || "") + " " + Math.round(progress.pct || 0) + "%")),
|
|
1307
|
+
h(ProgressBar, { pct: progress.pct }))
|
|
1308
|
+
: null,
|
|
576
1309
|
error ? h(Notice, { tone: "bad" }, error) : null,
|
|
577
1310
|
preview ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
|
|
578
1311
|
h("div", { style: row },
|
|
@@ -587,13 +1320,23 @@ window.__ModuleLoader__.load({
|
|
|
587
1320
|
h("div", { style: { display: "flex", flexDirection: "column", gap: "2px" } },
|
|
588
1321
|
preview.manifest.plugins.map((p) => h("div", { key: p.name, style: mono },
|
|
589
1322
|
"· " + p.name + "@" + p.version + (p.localEdits ? " [含本机修改]" : "") + (p.configIncluded ? " [有配置]" : "") + (p.dataIncluded ? " [有数据快照]" : "")))),
|
|
590
|
-
h(ScanReport, { scan: preview.scan }),
|
|
1323
|
+
h(ScanReport, { scan: preview.scan, groups: preview.scanGroups }),
|
|
591
1324
|
h(CompatList, { compat: preview.compat }),
|
|
592
1325
|
preview.notes && preview.notes.length ? h("div", { style: hint }, preview.notes.map((n, i) => h("div", { key: i }, "· " + n))) : null,
|
|
593
1326
|
h("div", { style: row },
|
|
594
1327
|
h(Switch, { checked: options.dryRun, label: "只演练不落地", onChange: (v) => setOptions({ ...options, dryRun: v }) }),
|
|
595
1328
|
h("button", { style: btnPrimary, disabled: busy !== "", onClick: install }, busy === "install" ? "安装中…" : (options.dryRun ? "演练一次" : "安装这个整合包"))))
|
|
596
1329
|
: null,
|
|
1330
|
+
askReplace && deferred.length > 0
|
|
1331
|
+
? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
1332
|
+
h("div", { style: { ...label, color: "#ffb020" } }, "以下 " + deferred.length + " 个插件本机已经装了,这次先跳过没动它们:"),
|
|
1333
|
+
deferred.map((d) => h("div", { key: d.name, style: mono },
|
|
1334
|
+
"· " + d.name + " 本机 " + (d.localVersion || "未知") + " → 包内 " + (d.packVersion || "未知") + (d.sameVersion ? "(版本相同)" : ""))),
|
|
1335
|
+
h("div", { style: hint }, "要保留本机版本就直接完成;要换成包内版本点下面这个(会覆盖本机那份)。"),
|
|
1336
|
+
h("div", { style: row },
|
|
1337
|
+
h("button", { style: btn, disabled: busy !== "", onClick: () => { setAskReplace(false) } }, "直接完成(保留本机版本)"),
|
|
1338
|
+
h("button", { style: btnPrimary, disabled: busy !== "", onClick: () => replaceDeferred(deferred.map((d) => d.name)) }, "替换为包内版本(" + deferred.length + " 个)")))
|
|
1339
|
+
: null,
|
|
597
1340
|
done ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
598
1341
|
h("div", { style: row },
|
|
599
1342
|
h("div", { style: strong }, done.ok ? "安装完成" : "没有装成"),
|
|
@@ -603,7 +1346,7 @@ window.__ModuleLoader__.load({
|
|
|
603
1346
|
(a.ok ? "✓ " : "✗ ") + a.plugin + " · " + a.action + " · " + a.message)),
|
|
604
1347
|
(done.lines || []).length ? h("details", null, h("summary", { style: hint }, "命令输出(" + done.lines.length + " 行)"),
|
|
605
1348
|
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)
|
|
1349
|
+
done.scan ? h(ScanReport, { scan: done.scan, groups: done.scanGroups }) : null)
|
|
607
1350
|
: null)
|
|
608
1351
|
}
|
|
609
1352
|
|
|
@@ -720,7 +1463,23 @@ window.__ModuleLoader__.load({
|
|
|
720
1463
|
|
|
721
1464
|
function Home(props) {
|
|
722
1465
|
const [tab, setTab] = useState("pack")
|
|
1466
|
+
const jobs = useJobs()
|
|
723
1467
|
const status = props.status
|
|
1468
|
+
const [packResult, setPackResult] = useState(() => readPackValue())
|
|
1469
|
+
const [focus, setFocus] = useState(0)
|
|
1470
|
+
useEffect(() => subscribePack((value) => { setPackResult(value) }), [])
|
|
1471
|
+
const savePackResult = (value) => {
|
|
1472
|
+
setPackValue(value)
|
|
1473
|
+
setPackResult(value)
|
|
1474
|
+
}
|
|
1475
|
+
// 进度窗里点「下载安装包」→ 切到打包页、把那次的结果放进去、滚到下载那一块
|
|
1476
|
+
const openResult = (job) => {
|
|
1477
|
+
const payload = job && job.data ? job.data : null
|
|
1478
|
+
if (!payload) return
|
|
1479
|
+
savePackResult(payload)
|
|
1480
|
+
setTab("pack")
|
|
1481
|
+
setFocus((n) => n + 1)
|
|
1482
|
+
}
|
|
724
1483
|
const tabs = [
|
|
725
1484
|
["pack", "打包"],
|
|
726
1485
|
["install", "安装 / 导入"],
|
|
@@ -737,7 +1496,9 @@ window.__ModuleLoader__.load({
|
|
|
737
1496
|
},
|
|
738
1497
|
}, text)
|
|
739
1498
|
|
|
740
|
-
return h("div", {
|
|
1499
|
+
return h("div", {
|
|
1500
|
+
style: { height: "100%", overflow: "auto", boxSizing: "border-box", padding: "22px 26px 44px", color: "var(--dsw-alias-label-primary)", position: "relative" },
|
|
1501
|
+
},
|
|
741
1502
|
h("div", { style: { maxWidth: "1020px", margin: "0 auto", display: "flex", flexDirection: "column", gap: "14px" } },
|
|
742
1503
|
h("div", { style: { display: "flex", alignItems: "baseline", gap: "10px", flexWrap: "wrap" } },
|
|
743
1504
|
h("h2", { style: { margin: 0, fontSize: "20px", fontWeight: 600 } }, "整合包"),
|
|
@@ -745,10 +1506,11 @@ window.__ModuleLoader__.load({
|
|
|
745
1506
|
h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)),
|
|
746
1507
|
h("span", { style: { ...hint, marginLeft: "auto" } },
|
|
747
1508
|
status ? ("DSH " + (status.dshVersion || "?") + " · 已装 " + ((status.installed || []).length) + " 个 · v" + (status.pluginVersion || "?")) : "读取环境…")),
|
|
748
|
-
tab === "pack" ? h(PackPanel, { status }) : null,
|
|
1509
|
+
tab === "pack" ? h(PackPanel, { status, jobs, result: packResult, setResult: savePackResult, focus }) : null,
|
|
749
1510
|
tab === "install" ? h(InstallPanel, { status }) : null,
|
|
750
1511
|
tab === "settings" ? h(SettingsPanel, { status }) : null,
|
|
751
|
-
h("div", { style: hint }, "说明:整合包只打包你选择的插件与必要配置。打包与安装安全检测在内存中进行,命中原文不落盘;请遵守插件作者许可证与你所在地区的法律法规。"))
|
|
1512
|
+
h("div", { style: hint }, "说明:整合包只打包你选择的插件与必要配置。打包与安装安全检测在内存中进行,命中原文不落盘;请遵守插件作者许可证与你所在地区的法律法规。")),
|
|
1513
|
+
h(JobDock, { jobs, onOpenResult: openResult })
|
|
752
1514
|
)
|
|
753
1515
|
}
|
|
754
1516
|
|
|
@@ -822,6 +1584,13 @@ window.__ModuleLoader__.load({
|
|
|
822
1584
|
else for (const item of items) unmount(group + ":" + item.slot)
|
|
823
1585
|
}
|
|
824
1586
|
}
|
|
1587
|
+
try {
|
|
1588
|
+
const workspace = ctx.get('uiWorkspace')
|
|
1589
|
+
if (workspace && typeof workspace.pickDirectory === "function") {
|
|
1590
|
+
pickDirectoryHost = () => workspace.pickDirectory()
|
|
1591
|
+
}
|
|
1592
|
+
} catch {}
|
|
1593
|
+
|
|
825
1594
|
ctx.effect(() => {
|
|
826
1595
|
const unsubscribe = subscribePlacement(sync)
|
|
827
1596
|
sync(placement.value)
|