@alequet/dsh-patchkeeper 0.0.0-stage → 0.6.0
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/LICENSE +21 -0
- package/README.md +78 -2
- package/bin/cli.mjs +905 -0
- package/client.js +497 -0
- package/cordis.patch.yml +6 -0
- package/index.js +280 -0
- package/package.json +41 -4
package/client.js
ADDED
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-patchkeeper 客户端 UI(免构建手写 bundle,形态参照 dsh-meme/dshmarket)。
|
|
3
|
+
*
|
|
4
|
+
* 槽位:
|
|
5
|
+
* plugins.detail.badge —— 失配插件详情页标题旁的「补丁未加载」徽章
|
|
6
|
+
* plugins.detail.section —— 失配插件详情页底部的适配卡片
|
|
7
|
+
* plugins.bundle.config (key=dsh-patchkeeper) —— patchkeeper 自己详情页的补丁管理台
|
|
8
|
+
* shell.overlay —— 开机绿泡泡(正向确认)/ 常驻红黄牌警告
|
|
9
|
+
*
|
|
10
|
+
* 数据来源:Node 侧 /dsh-patchkeeper-api(GET 清单 / POST 操作)。
|
|
11
|
+
*/
|
|
12
|
+
window.__ModuleLoader__.load({
|
|
13
|
+
id: 'dsh-patchkeeper',
|
|
14
|
+
factory: (require) => {
|
|
15
|
+
const React = require('react')
|
|
16
|
+
const h = React.createElement
|
|
17
|
+
const API = '/dsh-patchkeeper-api'
|
|
18
|
+
|
|
19
|
+
// 需要在详情页挂牌的异常状态(disabled 是用户主动关的,不算异常)
|
|
20
|
+
const BAD_STATUSES = ['version-mismatch', 'conflict', 'apply-failed', 'missing-target']
|
|
21
|
+
|
|
22
|
+
async function fetchList() {
|
|
23
|
+
try {
|
|
24
|
+
const res = await fetch(API)
|
|
25
|
+
if (!res.ok) return null
|
|
26
|
+
return await res.json()
|
|
27
|
+
} catch {
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function postAction(action, name, extra) {
|
|
33
|
+
const res = await fetch(API, {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: { 'Content-Type': 'application/json' },
|
|
36
|
+
body: JSON.stringify({ action, name, ...(extra || {}) }),
|
|
37
|
+
})
|
|
38
|
+
return res.json()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 取某个插件的异常补丁记录(无异常 → null → 不渲染)
|
|
42
|
+
function useMismatch(subject) {
|
|
43
|
+
const [tick, setTick] = React.useState(0)
|
|
44
|
+
const [data, setData] = React.useState(null)
|
|
45
|
+
React.useEffect(() => {
|
|
46
|
+
let live = true
|
|
47
|
+
fetchList().then((s) => live && setData(s))
|
|
48
|
+
return () => {
|
|
49
|
+
live = false
|
|
50
|
+
}
|
|
51
|
+
}, [tick])
|
|
52
|
+
const pkgName = subject && subject.kind === 'bundle' ? subject.pkg && subject.pkg.name : null
|
|
53
|
+
const record =
|
|
54
|
+
pkgName && data && Array.isArray(data.patches)
|
|
55
|
+
? data.patches.find((r) => r.name === pkgName && BAD_STATUSES.includes(r.status)) || null
|
|
56
|
+
: null
|
|
57
|
+
return { record, refresh: () => setTick((t) => t + 1) }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const badgeStyle = {
|
|
61
|
+
display: 'inline-block',
|
|
62
|
+
marginLeft: 8,
|
|
63
|
+
padding: '1px 8px',
|
|
64
|
+
borderRadius: 8,
|
|
65
|
+
fontSize: 12,
|
|
66
|
+
lineHeight: '18px',
|
|
67
|
+
color: '#8a5a00',
|
|
68
|
+
background: 'rgba(250, 173, 20, 0.18)',
|
|
69
|
+
border: '1px solid rgba(250, 173, 20, 0.45)',
|
|
70
|
+
verticalAlign: 'middle',
|
|
71
|
+
whiteSpace: 'nowrap',
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function MismatchBadge(props) {
|
|
75
|
+
const { record } = useMismatch(props.subject)
|
|
76
|
+
if (!record) return null
|
|
77
|
+
return h('span', { style: badgeStyle, title: `补丁版本 ${record.version},已装版本 ${record.installedVersion || '未知'}` }, '补丁未加载')
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const cardStyle = {
|
|
81
|
+
margin: '12px 0',
|
|
82
|
+
padding: '12px 14px',
|
|
83
|
+
borderRadius: 10,
|
|
84
|
+
border: '1px solid rgba(250, 173, 20, 0.45)',
|
|
85
|
+
background: 'rgba(250, 173, 20, 0.08)',
|
|
86
|
+
fontSize: 13,
|
|
87
|
+
lineHeight: 1.7,
|
|
88
|
+
}
|
|
89
|
+
const btnStyle = {
|
|
90
|
+
marginRight: 8,
|
|
91
|
+
marginTop: 8,
|
|
92
|
+
padding: '4px 12px',
|
|
93
|
+
borderRadius: 6,
|
|
94
|
+
border: '1px solid rgba(250, 173, 20, 0.6)',
|
|
95
|
+
background: 'transparent',
|
|
96
|
+
color: 'inherit',
|
|
97
|
+
cursor: 'pointer',
|
|
98
|
+
fontSize: 13,
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function MismatchSection(props) {
|
|
102
|
+
const { record, refresh } = useMismatch(props.subject)
|
|
103
|
+
const [busy, setBusy] = React.useState('')
|
|
104
|
+
const [msg, setMsg] = React.useState(null)
|
|
105
|
+
if (!record) return null
|
|
106
|
+
|
|
107
|
+
const run = async (action) => {
|
|
108
|
+
setBusy(action)
|
|
109
|
+
setMsg(null)
|
|
110
|
+
try {
|
|
111
|
+
const j = await postAction(action, record.name)
|
|
112
|
+
if (j.error) {
|
|
113
|
+
setMsg(`失败:${j.error}`)
|
|
114
|
+
} else if (action === 'adapt') {
|
|
115
|
+
const r = j.result && j.result.results && j.result.results[0]
|
|
116
|
+
const st = r && r.status
|
|
117
|
+
setMsg(
|
|
118
|
+
st === 'applied-now'
|
|
119
|
+
? '已强行打上旧补丁(有 fuzz 风险),重启 DSH 后生效;若插件异常请在管理台禁用。'
|
|
120
|
+
: st === 'applied'
|
|
121
|
+
? '补丁其实已处于应用状态。'
|
|
122
|
+
: `未能应用(${st || '未知'}),请手动合并 rejects/ 后用「以当前代码重建补丁」。`,
|
|
123
|
+
)
|
|
124
|
+
} else if (action === 'extract') {
|
|
125
|
+
const r = j.result && j.result.results && j.result.results[0]
|
|
126
|
+
setMsg(r && r.error ? `重建失败:${r.error}` : '已按当前代码重建补丁并入库,重启 DSH 后自动生效。')
|
|
127
|
+
} else {
|
|
128
|
+
setMsg('已回退该插件的补丁。')
|
|
129
|
+
}
|
|
130
|
+
} catch (err) {
|
|
131
|
+
setMsg(`请求失败:${err && err.message ? err.message : err}`)
|
|
132
|
+
} finally {
|
|
133
|
+
setBusy('')
|
|
134
|
+
refresh()
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const statusText = {
|
|
139
|
+
'version-mismatch': `插件已升级到 ${record.installedVersion || '?'},补丁是按 ${record.version} 做的,为避免加载失败本次未打。`,
|
|
140
|
+
conflict: '补丁与当前代码冲突,未能应用。',
|
|
141
|
+
'apply-failed': '补丁应用失败,reject 详情见数据目录 rejects/。',
|
|
142
|
+
'missing-target': '补丁目标插件当前未安装。',
|
|
143
|
+
}[record.status] || record.status
|
|
144
|
+
|
|
145
|
+
return h('section', { style: cardStyle }, [
|
|
146
|
+
h('div', { key: 't', style: { fontWeight: 600 } }, '⚠ 本地补丁未加载'),
|
|
147
|
+
h('div', { key: 'd' }, statusText),
|
|
148
|
+
h('div', { key: 'b' }, [
|
|
149
|
+
h(
|
|
150
|
+
'button',
|
|
151
|
+
{ key: 'adapt', style: btnStyle, disabled: !!busy, onClick: () => run('adapt') },
|
|
152
|
+
busy === 'adapt' ? '适配中…' : '尝试重新适配(force)',
|
|
153
|
+
),
|
|
154
|
+
h(
|
|
155
|
+
'button',
|
|
156
|
+
{ key: 'extract', style: btnStyle, disabled: !!busy, onClick: () => run('extract') },
|
|
157
|
+
busy === 'extract' ? '重建中…' : '以当前代码重建补丁',
|
|
158
|
+
),
|
|
159
|
+
]),
|
|
160
|
+
msg ? h('div', { key: 'm', style: { marginTop: 8, opacity: 0.85 } }, msg) : null,
|
|
161
|
+
])
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ---------- patchkeeper 自己的详情页:补丁管理台 ----------
|
|
165
|
+
|
|
166
|
+
function statusOf(p, bootTs) {
|
|
167
|
+
if (p.mounted && p.mountedAt && bootTs && Date.parse(p.mountedAt) > bootTs) return ['✓ 已挂载·重启后生效', '#d29922']
|
|
168
|
+
return statusMeta[p.status] || [p.status, '#8b8b8b']
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const statusMeta = {
|
|
172
|
+
applied: ['· 挂载中', '#2ea043'],
|
|
173
|
+
'applied-now': ['✓ 刚挂载', '#2ea043'],
|
|
174
|
+
'not-applied': ['○ 未挂载', '#8b8b8b'],
|
|
175
|
+
disabled: ['⏸ 已禁用', '#8b8b8b'],
|
|
176
|
+
'version-mismatch': ['⊘ 版本不匹配', '#d29922'],
|
|
177
|
+
conflict: ['✗ 冲突', '#dc3c3c'],
|
|
178
|
+
'apply-failed': ['✗ 挂载失败', '#dc3c3c'],
|
|
179
|
+
'missing-target': ['✗ 目标缺失', '#dc3c3c'],
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const toggleStyle = (on) => ({
|
|
183
|
+
width: 36,
|
|
184
|
+
height: 20,
|
|
185
|
+
borderRadius: 10,
|
|
186
|
+
border: 'none',
|
|
187
|
+
cursor: 'pointer',
|
|
188
|
+
background: on ? '#2ea043' : 'rgba(128,128,128,0.4)',
|
|
189
|
+
position: 'relative',
|
|
190
|
+
flexShrink: 0,
|
|
191
|
+
transition: 'background 0.15s',
|
|
192
|
+
})
|
|
193
|
+
const knobStyle = (on) => ({
|
|
194
|
+
position: 'absolute',
|
|
195
|
+
top: 2,
|
|
196
|
+
left: on ? 18 : 2,
|
|
197
|
+
width: 16,
|
|
198
|
+
height: 16,
|
|
199
|
+
borderRadius: 8,
|
|
200
|
+
background: '#fff',
|
|
201
|
+
transition: 'left 0.15s',
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
// 常驻红字维测:失败状态必须给出足够的诊断信息
|
|
205
|
+
function diagOf(p) {
|
|
206
|
+
switch (p.status) {
|
|
207
|
+
case 'version-mismatch':
|
|
208
|
+
return `未挂载:补丁按 v${p.version} 制作,当前安装 v${p.installedVersion || '?'},版本闸已拦截(防止旧补丁打崩新代码)。点「尝试重新适配」或改补丁后 remount。`
|
|
209
|
+
case 'conflict':
|
|
210
|
+
return `挂载失败:补丁与当前代码冲突${p.lastError ? `(${p.lastError})` : ''},reject 详情见数据目录 rejects/。`
|
|
211
|
+
case 'apply-failed':
|
|
212
|
+
return `挂载失败${p.lastError ? `:${p.lastError}` : '(原因见 state.json)'}`
|
|
213
|
+
case 'missing-target':
|
|
214
|
+
return '目标插件未安装,补丁悬空。'
|
|
215
|
+
default:
|
|
216
|
+
return null
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function PatchRow({ p, busy, op, bootTs, onToggle, onSaveNote, onRetry }) {
|
|
221
|
+
const [note, setNote] = React.useState(p.note || '')
|
|
222
|
+
const [dirty, setDirty] = React.useState(false)
|
|
223
|
+
const meta = statusOf(p, bootTs)
|
|
224
|
+
const diag = diagOf(p)
|
|
225
|
+
return h(
|
|
226
|
+
'div',
|
|
227
|
+
{
|
|
228
|
+
style: {
|
|
229
|
+
padding: '10px 0',
|
|
230
|
+
borderBottom: '1px solid rgba(128,128,128,0.2)',
|
|
231
|
+
display: 'flex',
|
|
232
|
+
gap: 12,
|
|
233
|
+
alignItems: 'flex-start',
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
h(
|
|
237
|
+
'button',
|
|
238
|
+
{
|
|
239
|
+
style: toggleStyle(p.enabled),
|
|
240
|
+
title: p.enabled ? '点击禁用(恢复原插件、清除副本)' : '启用(创建副本并挂载)',
|
|
241
|
+
disabled: busy,
|
|
242
|
+
onClick: () => onToggle(p),
|
|
243
|
+
},
|
|
244
|
+
h('span', { style: knobStyle(p.enabled) }),
|
|
245
|
+
),
|
|
246
|
+
h('div', { style: { flex: 1, minWidth: 0 } }, [
|
|
247
|
+
h('div', { key: 'n', style: { fontWeight: 600, fontSize: 13 } }, [
|
|
248
|
+
`${p.name} `,
|
|
249
|
+
h('span', { key: 'v', style: { fontWeight: 400, opacity: 0.7, fontSize: 12 } }, `补丁 ${p.version} / 已装 ${p.installedVersion || '?'}`),
|
|
250
|
+
]),
|
|
251
|
+
h('div', { key: 's', style: { fontSize: 12, color: meta[1], marginTop: 2 } }, meta[0] + (p.files?.length ? ` · ${p.files.length} 个文件` : '')),
|
|
252
|
+
p.files?.length
|
|
253
|
+
? h('div', { key: 'f', style: { fontSize: 11, opacity: 0.6, marginTop: 2, wordBreak: 'break-all' } }, p.files.join('、'))
|
|
254
|
+
: null,
|
|
255
|
+
diag ? h('div', { key: 'diag', style: { fontSize: 12, color: '#dc3c3c', marginTop: 4, lineHeight: 1.6 } }, diag) : null,
|
|
256
|
+
p.risk ? h('div', { key: 'risk', style: { fontSize: 12, color: '#d29922', marginTop: 4, lineHeight: 1.6 } }, `⚠ 禁用风险:${p.risk}`) : null,
|
|
257
|
+
p.adapt
|
|
258
|
+
? h('div', {
|
|
259
|
+
key: 'adapt',
|
|
260
|
+
style: {
|
|
261
|
+
fontSize: 12, marginTop: 4, lineHeight: 1.6,
|
|
262
|
+
color: p.adapt.outcome === 'ai-failed' ? '#dc3c3c' : p.adapt.outcome === 'adapted' ? '#2ea043' : '#d29922',
|
|
263
|
+
},
|
|
264
|
+
}, [
|
|
265
|
+
p.adapt.outcome === 'running' ? `🤖 补丁正在自动适配 v${p.installedVersion}(机械合并 → AI 解冲突)…` : null,
|
|
266
|
+
p.adapt.outcome === 'adapted' ? `✓ 补丁已自动适配 v${p.installedVersion}(${p.adapt.mode === 'ai' ? 'AI 解冲突' : '机械合并'}),重启 DSH 后自动挂载` : null,
|
|
267
|
+
p.adapt.outcome === 'ai-failed' ? `✗ 自动适配失败:${p.adapt.error || '未知原因'}——已转人工,不再自动重试` : null,
|
|
268
|
+
p.adapt.outcome === 'ai-failed'
|
|
269
|
+
? h('button', {
|
|
270
|
+
key: 'retry',
|
|
271
|
+
style: { ...btnStyle, marginTop: 4, padding: '2px 10px', fontSize: 12, borderColor: 'rgba(220,60,60,0.5)' },
|
|
272
|
+
disabled: busy,
|
|
273
|
+
onClick: () => onRetry(p),
|
|
274
|
+
}, '人工重试 AI 适配')
|
|
275
|
+
: null,
|
|
276
|
+
])
|
|
277
|
+
: null,
|
|
278
|
+
op
|
|
279
|
+
? h('div', { key: 'op', style: { fontSize: 12, fontWeight: 600, marginTop: 4, color: op.ok ? '#2ea043' : '#dc3c3c' } }, op.text)
|
|
280
|
+
: null,
|
|
281
|
+
h('div', { key: 'note', style: { display: 'flex', gap: 6, marginTop: 6 } }, [
|
|
282
|
+
h('input', {
|
|
283
|
+
key: 'i',
|
|
284
|
+
value: note,
|
|
285
|
+
placeholder: '补丁效果说明(点击填写…)',
|
|
286
|
+
onChange: (e) => {
|
|
287
|
+
setNote(e.target.value)
|
|
288
|
+
setDirty(true)
|
|
289
|
+
},
|
|
290
|
+
style: {
|
|
291
|
+
flex: 1,
|
|
292
|
+
fontSize: 12,
|
|
293
|
+
padding: '3px 8px',
|
|
294
|
+
borderRadius: 6,
|
|
295
|
+
border: '1px solid rgba(128,128,128,0.35)',
|
|
296
|
+
background: 'transparent',
|
|
297
|
+
color: 'inherit',
|
|
298
|
+
},
|
|
299
|
+
}),
|
|
300
|
+
dirty
|
|
301
|
+
? h(
|
|
302
|
+
'button',
|
|
303
|
+
{
|
|
304
|
+
key: 'sv',
|
|
305
|
+
style: { ...btnStyle, marginTop: 0, padding: '2px 10px', fontSize: 12 },
|
|
306
|
+
disabled: busy,
|
|
307
|
+
onClick: () => onSaveNote(p, note).then(() => setDirty(false)),
|
|
308
|
+
},
|
|
309
|
+
'保存',
|
|
310
|
+
)
|
|
311
|
+
: null,
|
|
312
|
+
]),
|
|
313
|
+
]),
|
|
314
|
+
)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function PatchPanel() {
|
|
318
|
+
const [data, setData] = React.useState(null)
|
|
319
|
+
const [busy, setBusy] = React.useState(false)
|
|
320
|
+
const [hint, setHint] = React.useState(null)
|
|
321
|
+
const [ops, setOps] = React.useState({}) // 每个补丁最近一次操作的结果反馈
|
|
322
|
+
const refresh = () => fetchList().then(setData)
|
|
323
|
+
React.useEffect(() => {
|
|
324
|
+
refresh()
|
|
325
|
+
}, [])
|
|
326
|
+
if (!data) return h('div', { style: { padding: 8, opacity: 0.6 } }, '补丁清单加载中…')
|
|
327
|
+
const patches = data.patches || []
|
|
328
|
+
|
|
329
|
+
const setOp = (name, ok, text) => setOps((m) => ({ ...m, [name]: { ok, text } }))
|
|
330
|
+
|
|
331
|
+
const act = async (action, p, extra) => {
|
|
332
|
+
setBusy(true)
|
|
333
|
+
setHint(null)
|
|
334
|
+
try {
|
|
335
|
+
const j = await postAction(action, p.name, extra)
|
|
336
|
+
if (j.error) {
|
|
337
|
+
setOp(p.name, false, `操作失败:${j.error}`)
|
|
338
|
+
} else {
|
|
339
|
+
const r = j.result && j.result.results && j.result.results[0]
|
|
340
|
+
const live = j.reload === 'reloaded'
|
|
341
|
+
const suffix = live ? '(已热重载,即时生效)' : '(后端代码重启 DSH 后切换)'
|
|
342
|
+
if (action === 'enable') {
|
|
343
|
+
if (r && (r.status === 'applied-now' || r.status === 'applied')) setOp(p.name, true, `✓ 已启用:副本已创建并挂载${suffix}`)
|
|
344
|
+
else setOp(p.name, false, `✗ 启用失败:${(r && (r.error || r.status)) || '未知原因'}`)
|
|
345
|
+
} else if (action === 'disable') {
|
|
346
|
+
if (r && (r.status === 'reverted' || r.status === 'not-applied')) setOp(p.name, true, `✓ 已禁用:恢复原插件、副本已清除${suffix}`)
|
|
347
|
+
else setOp(p.name, false, `✗ 禁用失败:${(r && (r.error || r.status)) || '未知原因'}`)
|
|
348
|
+
} else if (action === 'note') {
|
|
349
|
+
setOp(p.name, true, '✓ 说明已保存')
|
|
350
|
+
}
|
|
351
|
+
if (j.list) setData(j.list)
|
|
352
|
+
}
|
|
353
|
+
} catch (err) {
|
|
354
|
+
setOp(p.name, false, `请求失败:${err && err.message ? err.message : err}`)
|
|
355
|
+
} finally {
|
|
356
|
+
setBusy(false)
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return h('div', { style: { fontSize: 13 } }, [
|
|
361
|
+
data.alarm
|
|
362
|
+
? h('div', { key: 'alarm', style: { ...cardStyle, borderColor: 'rgba(220,60,60,0.5)', background: 'rgba(220,60,60,0.1)', fontWeight: 600 } }, data.alarm)
|
|
363
|
+
: null,
|
|
364
|
+
patches.length
|
|
365
|
+
? h('div', { key: 'rows' }, patches.map((p) =>
|
|
366
|
+
h(PatchRow, {
|
|
367
|
+
key: p.name,
|
|
368
|
+
p,
|
|
369
|
+
busy,
|
|
370
|
+
op: ops[p.name],
|
|
371
|
+
bootTs: data.bootTs,
|
|
372
|
+
onToggle: (pp) => {
|
|
373
|
+
if (pp.enabled && pp.risk && !window.confirm(`禁用风险:${pp.risk}\n\n确认禁用?`)) return
|
|
374
|
+
act(pp.enabled ? 'disable' : 'enable', pp)
|
|
375
|
+
},
|
|
376
|
+
onSaveNote: (pp, note) => act('note', pp, { note }),
|
|
377
|
+
onRetry: (pp) => {
|
|
378
|
+
setOp(pp.name, true, '🤖 已重新开始 AI 适配…')
|
|
379
|
+
act('adapt-retry', pp)
|
|
380
|
+
},
|
|
381
|
+
}),
|
|
382
|
+
))
|
|
383
|
+
: h('div', { key: 'empty', style: { opacity: 0.6, padding: '8px 0' } }, '补丁库为空——改了插件代码后跑 extract 入库。'),
|
|
384
|
+
hint ? h('div', { key: 'hint', style: { marginTop: 8, fontSize: 12, opacity: 0.75 } }, hint) : null,
|
|
385
|
+
h('div', { key: 'ft', style: { marginTop: 10, fontSize: 11, opacity: 0.55 } },
|
|
386
|
+
'补丁库:~/.dsh/patch-manager/patches(git 管理)· 副本挂载于运行期,原版插件永远干净'),
|
|
387
|
+
])
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// ---------- 开机 toast ----------
|
|
391
|
+
|
|
392
|
+
function BootToast() {
|
|
393
|
+
const [info, setInfo] = React.useState(null)
|
|
394
|
+
const [gone, setGone] = React.useState(false)
|
|
395
|
+
React.useEffect(() => {
|
|
396
|
+
let live = true
|
|
397
|
+
fetchList().then((s) => {
|
|
398
|
+
if (!live || !s) return
|
|
399
|
+
if (s.alarm) {
|
|
400
|
+
setInfo({ level: 'alarm', text: s.alarm })
|
|
401
|
+
return
|
|
402
|
+
}
|
|
403
|
+
const patches = Array.isArray(s.patches) ? s.patches : []
|
|
404
|
+
const bootTs = s.bootTs || 0
|
|
405
|
+
const effective = patches.filter((r) => r.mounted && r.mountedAt && Date.parse(r.mountedAt) <= bootTs).length
|
|
406
|
+
const pending = patches.filter((r) => r.mounted && (!r.mountedAt || Date.parse(r.mountedAt) > bootTs)).length
|
|
407
|
+
const bad = patches.filter((r) => BAD_STATUSES.includes(r.status)).length
|
|
408
|
+
if (bad) setInfo({ level: 'warn', text: `补丁管家:${bad} 个补丁未挂载,请到插件管理页处理` })
|
|
409
|
+
else if (pending) setInfo({ level: 'ok', text: `补丁管家:${pending} 个补丁已挂载(本轮启动的冻结快照更早,重启后生效)` })
|
|
410
|
+
else if (effective) setInfo({ level: 'ok', text: `补丁管家:${effective} 个补丁生效中 ✓` })
|
|
411
|
+
})
|
|
412
|
+
return () => {
|
|
413
|
+
live = false
|
|
414
|
+
}
|
|
415
|
+
}, [])
|
|
416
|
+
React.useEffect(() => {
|
|
417
|
+
if (info && info.level === 'ok') {
|
|
418
|
+
const t = setTimeout(() => setGone(true), 6000)
|
|
419
|
+
return () => clearTimeout(t)
|
|
420
|
+
}
|
|
421
|
+
}, [info])
|
|
422
|
+
if (!info || gone) return null
|
|
423
|
+
const palette = {
|
|
424
|
+
ok: { bg: 'rgba(46, 160, 67, 0.95)', fg: '#fff' },
|
|
425
|
+
warn: { bg: 'rgba(250, 173, 20, 0.95)', fg: '#3a2a00' },
|
|
426
|
+
alarm: { bg: 'rgba(220, 60, 60, 0.95)', fg: '#fff' },
|
|
427
|
+
}[info.level]
|
|
428
|
+
return h(
|
|
429
|
+
'div',
|
|
430
|
+
{
|
|
431
|
+
style: {
|
|
432
|
+
position: 'fixed',
|
|
433
|
+
top: 16,
|
|
434
|
+
right: 16,
|
|
435
|
+
zIndex: 99999,
|
|
436
|
+
padding: '10px 14px',
|
|
437
|
+
borderRadius: 10,
|
|
438
|
+
background: palette.bg,
|
|
439
|
+
color: palette.fg,
|
|
440
|
+
fontSize: 13,
|
|
441
|
+
lineHeight: 1.5,
|
|
442
|
+
maxWidth: 360,
|
|
443
|
+
boxShadow: '0 4px 16px rgba(0,0,0,0.25)',
|
|
444
|
+
display: 'flex',
|
|
445
|
+
gap: 10,
|
|
446
|
+
alignItems: 'flex-start',
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
h('span', { style: { flex: 1 } }, info.text),
|
|
450
|
+
h(
|
|
451
|
+
'button',
|
|
452
|
+
{
|
|
453
|
+
style: { background: 'none', border: 'none', color: palette.fg, cursor: 'pointer', fontSize: 14, padding: 0 },
|
|
454
|
+
onClick: () => setGone(true),
|
|
455
|
+
},
|
|
456
|
+
'×',
|
|
457
|
+
),
|
|
458
|
+
)
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function apply(ctx) {
|
|
462
|
+
const slots = ctx.slots ?? (typeof ctx.get === 'function' ? ctx.get('slots') : null)
|
|
463
|
+
if (!slots || typeof slots.inject !== 'function') return
|
|
464
|
+
// slots.inject:槽被宿主声明时才注册,未声明时安全静默(宿主版本差异不炸 UI)
|
|
465
|
+
slots.inject('plugins.detail.badge', () => {
|
|
466
|
+
try {
|
|
467
|
+
return slots.register({ name: 'plugins.detail.badge', id: 'patchkeeper-mismatch', order: 100 }, MismatchBadge)
|
|
468
|
+
} catch {
|
|
469
|
+
return () => {}
|
|
470
|
+
}
|
|
471
|
+
})
|
|
472
|
+
slots.inject('plugins.detail.section', () => {
|
|
473
|
+
try {
|
|
474
|
+
return slots.register({ name: 'plugins.detail.section', id: 'patchkeeper-mismatch', order: 100 }, MismatchSection)
|
|
475
|
+
} catch {
|
|
476
|
+
return () => {}
|
|
477
|
+
}
|
|
478
|
+
})
|
|
479
|
+
slots.inject('plugins.bundle.config', () => {
|
|
480
|
+
try {
|
|
481
|
+
return slots.register({ name: 'plugins.bundle.config', key: '@alequet/dsh-patchkeeper' }, PatchPanel)
|
|
482
|
+
} catch {
|
|
483
|
+
return () => {}
|
|
484
|
+
}
|
|
485
|
+
})
|
|
486
|
+
slots.inject('shell.overlay', () => {
|
|
487
|
+
try {
|
|
488
|
+
return slots.register({ name: 'shell.overlay', id: 'patchkeeper-boot-toast', order: 100 }, BootToast)
|
|
489
|
+
} catch {
|
|
490
|
+
return () => {}
|
|
491
|
+
}
|
|
492
|
+
})
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return { name: 'dsh-patchkeeper', inject: ['slots'], apply }
|
|
496
|
+
},
|
|
497
|
+
})
|