dsh-plugin-update-center 1.0.7 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -7
- package/client.js +280 -58
- package/docs/chip-before.png +0 -0
- package/docs/chip-dark.png +0 -0
- package/docs/chip-light.png +0 -0
- package/lib/engine.js +72 -12
- package/lib/http.js +2 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -4,18 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
GitHub: https://github.com/darkings/dsh-plugin-update-center · npm: https://www.npmjs.com/package/dsh-plugin-update-center
|
|
6
6
|
|
|
7
|
-
它只更新 **npm registry 来源的 profile
|
|
7
|
+
它只更新 **npm registry 来源的 profile 插件**,**包括它自己**。DSH 自带插件、`github:` / `git:` / `file:` / `link:` / `workspace:` 安装的插件、以及 DSH 本体更新都不在这里处理。
|
|
8
8
|
|
|
9
9
|
## 界面
|
|
10
10
|
|
|
11
11
|
- 入口:侧边栏底部**登录名右侧**,与 DSH 自己的更新提示并排(同一个 `triggerRow`,插件更新 chip 在账号按钮之后、DSH 更新 chip 之前)。
|
|
12
12
|
- 该位置没有官方 list 插槽,所以用 `shell.overlay` + React portal 把 chip 挂进账号行;chip 的高度、字号、品牌色 tint 与 DSH 的 `DesktopUpdateIndicator` 一致。
|
|
13
13
|
- **更新 chip**:下载图标;没有可更新插件时不显示;有更新时显示数量;排队时显示时钟图标;更新中显示旋转图标和 `n/total`。
|
|
14
|
-
-
|
|
15
|
-
-
|
|
14
|
+
- **重启 chip**:28×28 的方形图标按钮,配色全部取自 DSH 自己的 amber 阶梯——边框 `state-warn-primary`(#f59e0b)45%、底色同为 amber 14%、图标 `state-warn-label`(#dd8629),和蓝色的更新 chip、垃圾桶的残留 chip 一眼区分。只要 Host 还记着「已安装但未完整重启」,它就常驻账号行——关闭弹窗(稍后重启)、刷新页面、开始下一批更新都不会让它消失。有插件失败未回滚时换成错误色,提示先处理失败项。
|
|
15
|
+
- **残留 chip**:垃圾桶图标 + 警告色;发现卸载残留时出现,点击打开残留窗口。
|
|
16
|
+
- 点击更新 / 重启 chip 打开 DSH 原生风格的弹窗:默认显示**最新可更新列表**,上一批的结果收在「查看上一批结果」里,不会被旧进度视图挡住。
|
|
16
17
|
- 有任务在运行时,按钮变成「任务完成后自动更新」;点击进入队列,任务全部结束并静默后自动开始。
|
|
17
18
|
- 更新开始后弹窗切换为进度视图:总进度条、当前插件、每个插件的状态(等待 / 核对版本 / 移除旧版 / 安装新版 / 已更新 / 待重启 / 失败)。
|
|
18
|
-
-
|
|
19
|
+
- 完成后弹窗顶部出现重启提示条:正常时带「完整重启」按钮,点击后重新启动桌面应用;有未回滚的失败项时改为「重试失败项」,避免重启进一个坏掉的 profile。关闭弹窗只隐藏提示条,重启 chip 仍留在账号行。不再自动刷新页面。
|
|
19
20
|
- 不需要时可以关闭弹窗、让任务在后台继续;完成后再打开查看结果。
|
|
20
21
|
|
|
21
22
|
## 检查逻辑
|
|
@@ -48,6 +49,14 @@ installBundle(`${name}@${latest}`, { enabled: 原状态, saveExact: true, regist
|
|
|
48
49
|
- 有任务正在运行或已有更新任务时不会直接更新;可以选择「任务完成后自动更新」进入队列。
|
|
49
50
|
- 不自动重启 DSH,也不更新 DSH 本体。DSH 本体有更新(`available`/`downloading`/`installing`/`ready`)时禁止插件更新。
|
|
50
51
|
|
|
52
|
+
## 自更新
|
|
53
|
+
|
|
54
|
+
- 更新中心自己也走同一条检查 / 更新流程:列表里带「本插件自身 · 单独更新」标记,来源仍是 npm registry。
|
|
55
|
+
- **必须单独更新**:和别的插件一起勾选会被拒绝(`self-update-alone`,409),避免一批插件半更新后卡在一个说不清的重启提示后面。
|
|
56
|
+
- **安装时不做 remove**:直接 `installBundle` 覆盖正在运行的包,删掉自己会连带删掉 Host 正在执行的代码;覆盖安装被拒时才回退到官方 remove → install。
|
|
57
|
+
- 更新成功后**一定**要求完整重启(即使 `application === 'applied'`),新代码只在新 Host 进程里生效;重启后自己回到最新版本、不再显示为可更新。
|
|
58
|
+
- 失败时同样按单插件回滚:装回旧版本并校验,失败未回滚则标记 blocked,不给重启按钮。
|
|
59
|
+
|
|
51
60
|
进度条口径:由于官方 API 不暴露 pnpm 的字节级下载进度,进度按「已完成插件数 + 当前阶段权重」推进(核对 5% → 移除 35% → 安装 65% → 完成 100%),而不是按下载百分比。
|
|
52
61
|
|
|
53
62
|
## 排队与生效
|
|
@@ -56,8 +65,8 @@ installBundle(`${name}@${latest}`, { enabled: 原状态, saveExact: true, regist
|
|
|
56
65
|
- 队列等待所有任务空闲,再静默 10 秒,然后 5 秒倒计时开始;倒计时内来新任务会退回等待。
|
|
57
66
|
- 每个插件开始前再查一次任务;运行中来新 conversation,当前插件安装完后暂停,任务结束再恢复。
|
|
58
67
|
- 队列在页面刷新/关闭后保留(Host 内存);Host 重启后不自动续跑。
|
|
59
|
-
- 全部完成后聚合:任意失败项 → 不自动刷新,显示失败状态和「重试失败项」;任意成功插件带 `dsh.client` 或 `restart-required` →
|
|
60
|
-
- 失败插件保持旧版本,仍是「可更新」状态;可以立即重试,或重启 DSH
|
|
68
|
+
- 全部完成后聚合:任意失败项 → 不自动刷新,显示失败状态和「重试失败项」;任意成功插件带 `dsh.client` 或 `restart-required` → 记一条 **Host 级「待重启」**(不是 job 级):关弹窗、刷新页面、再更新一批都不会清掉,只有真正的新 Host 进程(即重启完成)才会归零;有未回滚失败时这条记录标记为 blocked,只提示重试、不给重启按钮。页面不会自动刷新(页面刷新只换客户端、不换 Host,可能启动失败);Host-only 更新由插件管理器按 applied 处理。
|
|
69
|
+
- 失败插件保持旧版本,仍是「可更新」状态;可以立即重试,或重启 DSH 后在更新列表里重新检查/更新。自更新失败时同理:自己会重新出现在列表里,可以再试一次。
|
|
61
70
|
- 客户端插件更新一律按「需要完整重启」处理,避免只刷新页面导致 Host/客户端版本不一致。
|
|
62
71
|
|
|
63
72
|
## DSH 本体更新
|
|
@@ -126,7 +135,15 @@ plugin_manager install_bundle C:\Users\Jie\Projects\dsh-plugins\dsh-plugin-updat
|
|
|
126
135
|
npm test
|
|
127
136
|
```
|
|
128
137
|
|
|
129
|
-
|
|
138
|
+
chip 的真实渲染(浅色 / 深色):
|
|
139
|
+
|
|
140
|
+
| 浅色 | 深色 |
|
|
141
|
+
| --- | --- |
|
|
142
|
+
|  |  |
|
|
143
|
+
|
|
144
|
+
测试里有一组**真实渲染**的截图用例(`test/chip-visual.test.mjs`):它直接从 `client.js` 里取 `STYLE`,用本机 Edge/Chrome 无头模式按 2× 渲染 chip,再解码 PNG 量出图标与数字的墨迹重心,要求两者偏差 < 0.25 CSS px(防止 28px chip 里那种亚像素错位回潮)。机器上没有 Chromium 系浏览器时这组用例自动 skip,不判失败。
|
|
145
|
+
|
|
146
|
+
覆盖:版本比较与 engines 范围、更新计划筛选、remove → install → 回滚顺序、发布变化中止、队列空闲等待/取消、失败重试与回滚续跑、重启与完整重启、自更新(单独更新 / 原地覆盖 / 强制重启)、残留扫描与安全清理、HTTP 路由的鉴权头/请求体/错误码、registry 回退与范围检查、chip 的真实渲染对齐与配色 token。
|
|
130
147
|
|
|
131
148
|
## 文件
|
|
132
149
|
|
package/client.js
CHANGED
|
@@ -66,6 +66,10 @@ window.__ModuleLoader__.load({
|
|
|
66
66
|
'done.snapshot': '更新前快照:{path}',
|
|
67
67
|
'risk.boot': '启动关键',
|
|
68
68
|
'risk.provider': '被 {count} 个插件依赖',
|
|
69
|
+
'risk.self': '本插件自身 · 单独更新',
|
|
70
|
+
'self.note': '{name} 是更新中心本体,只能单独更新;安装完成后必须完整重启 DSH。',
|
|
71
|
+
'self.alone': '本插件不能和其他插件一起更新。请只勾选它,或先取消勾选它。',
|
|
72
|
+
'error.self-update-alone': '本插件只能单独更新,请只勾选它。',
|
|
69
73
|
'risk.unselected': '{count} 个启动关键 / 被依赖插件未勾选。请单独更新它们,并在更新后立即重启验证。',
|
|
70
74
|
'risk.warning': '选中的插件包含启动关键项。更新后请立即重启验证;若 DSH 无法打开,在错误对话框点「禁用第三方插件、备份 profile patch 并重启」,或运行 repair.cmd 恢复快照。',
|
|
71
75
|
'done.summary': '已更新 {count} 个插件',
|
|
@@ -112,6 +116,16 @@ window.__ModuleLoader__.load({
|
|
|
112
116
|
'residue.cleaned': '已清理 {count} 项',
|
|
113
117
|
'residue.scan': '重新扫描',
|
|
114
118
|
'residue.line': '第 {line} 行',
|
|
119
|
+
'panel.resultsTitle': '上一批更新结果',
|
|
120
|
+
'restart.tooltip': '插件已更新,需要重启 DSH 生效',
|
|
121
|
+
'restart.tooltipBlocked': '更新未完成,先处理失败项',
|
|
122
|
+
'restart.banner': '已更新 {count} 个插件,需要完整重启 DSH 才能生效。',
|
|
123
|
+
'restart.bannerBlocked': '更新未完成:有插件更新失败且未回滚。请先重试失败项,再完整重启 DSH。',
|
|
124
|
+
'results.summary': '上一批:已更新 {updated} 个,{failed} 个失败',
|
|
125
|
+
'results.summaryClean': '上一批:已更新 {updated} 个插件',
|
|
126
|
+
'results.summaryEmpty': '上一批未完成',
|
|
127
|
+
'results.show': '查看上一批结果',
|
|
128
|
+
'results.back': '返回更新列表',
|
|
115
129
|
}
|
|
116
130
|
|
|
117
131
|
const en = {
|
|
@@ -162,6 +176,10 @@ window.__ModuleLoader__.load({
|
|
|
162
176
|
'done.snapshot': 'Pre-update snapshot: {path}',
|
|
163
177
|
'risk.boot': 'Boot-critical',
|
|
164
178
|
'risk.provider': 'Used by {count} plugins',
|
|
179
|
+
'risk.self': 'Update center itself · runs alone',
|
|
180
|
+
'self.note': '{name} is the update center itself. It can only be updated on its own, and a full DSH restart is required afterwards.',
|
|
181
|
+
'self.alone': 'The update center cannot be updated together with other plugins. Select only it.',
|
|
182
|
+
'error.self-update-alone': 'The update center must be updated alone. Select only it.',
|
|
165
183
|
'risk.unselected': '{count} boot-critical / depended-on plugins are not selected. Update them one at a time and restart to verify.',
|
|
166
184
|
'risk.warning': 'The selection includes boot-critical plugins. Restart and verify right after updating; if DSH will not open, use “Disable third-party plugins” in the error dialog or run repair.cmd to restore the snapshot.',
|
|
167
185
|
'done.summary': '{count} plugins updated',
|
|
@@ -208,17 +226,45 @@ window.__ModuleLoader__.load({
|
|
|
208
226
|
'residue.cleaned': 'Cleaned {count} items',
|
|
209
227
|
'residue.scan': 'Scan again',
|
|
210
228
|
'residue.line': 'line {line}',
|
|
229
|
+
'panel.resultsTitle': 'Last batch results',
|
|
230
|
+
'restart.tooltip': 'Plugins updated. Restart DSH to apply them.',
|
|
231
|
+
'restart.tooltipBlocked': 'The update did not finish. Handle the failed plugins first.',
|
|
232
|
+
'restart.banner': 'Updated {count} plugins. Restart DSH completely to apply them.',
|
|
233
|
+
'restart.bannerBlocked': 'The update did not finish: a plugin failed and was not rolled back. Retry the failed plugins, then restart DSH completely.',
|
|
234
|
+
'results.summary': 'Last batch: {updated} updated, {failed} failed',
|
|
235
|
+
'results.summaryClean': 'Last batch: {updated} plugins updated',
|
|
236
|
+
'results.summaryEmpty': 'The last batch did not finish',
|
|
237
|
+
'results.show': 'View last batch results',
|
|
238
|
+
'results.back': 'Back to updates',
|
|
211
239
|
}
|
|
212
240
|
|
|
213
241
|
const STYLE = [
|
|
214
242
|
'.dshpu-rowHost{display:inline-flex;flex:none;align-items:center;gap:4px;min-width:0}',
|
|
215
|
-
'.dshpu-chip{box-sizing:border-box;display:inline-
|
|
243
|
+
'.dshpu-chip{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:4px;height:28px;min-width:28px;padding:0 8px;border:1px solid color-mix(in srgb, var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6) 20%, transparent);border-radius:var(--dsw-radius-sm,8px);color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);background:color-mix(in srgb, var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6) 8%, transparent);font-family:inherit;font-size:12px;font-weight:500;line-height:18px;white-space:nowrap;cursor:pointer;flex:none}',
|
|
216
244
|
'.dshpu-chip:hover{background:color-mix(in srgb, var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6) 14%, transparent)}',
|
|
217
|
-
'.dshpu-chip.is-residue{border-color:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#
|
|
218
|
-
'.dshpu-chip.is-residue:hover{background:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#
|
|
245
|
+
'.dshpu-chip.is-residue{border-color:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#f59e0b) 25%, transparent);color:var(--dsw-alias-state-warn-label,#dd8629);background:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#f59e0b) 8%, transparent)}',
|
|
246
|
+
'.dshpu-chip.is-residue:hover{background:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#f59e0b) 14%, transparent)}',
|
|
247
|
+
// Restart chip in DSH's own amber ramp (static-amber-500 #f59e0b border and
|
|
248
|
+
// tint, amber-600 #dd8629 glyph) so it reads as a warning-grade action
|
|
249
|
+
// without inventing colours outside the design system.
|
|
250
|
+
'.dshpu-chip.is-restart{width:28px;padding:0;border-color:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#f59e0b) 45%, transparent);color:var(--dsw-alias-state-warn-label,#dd8629);background:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#f59e0b) 14%, transparent)}',
|
|
251
|
+
'.dshpu-chip.is-restart:hover{border-color:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#f59e0b) 62%, transparent);background:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#f59e0b) 22%, transparent)}',
|
|
252
|
+
'.dshpu-chip.is-restart[data-blocked="true"]{border-color:color-mix(in srgb, var(--dsw-alias-state-error-primary,#d93025) 45%, transparent);color:var(--dsw-alias-state-error-primary,#d93025);background:color-mix(in srgb, var(--dsw-alias-state-error-primary,#d93025) 10%, transparent)}',
|
|
253
|
+
'.dshpu-chip.is-restart[data-blocked="true"]:hover{background:color-mix(in srgb, var(--dsw-alias-state-error-primary,#d93025) 16%, transparent)}',
|
|
219
254
|
'.dshpu-chip:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary,#4d6bfe));outline-offset:2px}',
|
|
220
|
-
|
|
221
|
-
'
|
|
255
|
+
// The glyph box is exactly 14px and the flex line centres it, so the icon is
|
|
256
|
+
// already on the chip's optical centre; the SVG is blockified so no inline
|
|
257
|
+
// baseline gap can push it off.
|
|
258
|
+
'.dshpu-chipIcon{display:block;flex:none;width:14px;height:14px;line-height:0}',
|
|
259
|
+
'.dshpu-chipIcon>svg{display:block;width:14px;height:14px}',
|
|
260
|
+
// Centring a line box does not centre its ink: Segoe UI's ascent (1.08em)
|
|
261
|
+
// dwarfs its descent (0.25em), so cap-height digits land about 0.075em below
|
|
262
|
+
// the box centre - 0.9px at 12px. line-height cannot fix that (the span top
|
|
263
|
+
// and the baseline shift together), so the text carries its own nudge.
|
|
264
|
+
// -0.4px is the measured optimum: swept from 0 to -0.9px through a real
|
|
265
|
+
// headless render, it leaves the count 0.07 CSS px from the glyph centre,
|
|
266
|
+
// while -0.75px overshoots to -0.12px.
|
|
267
|
+
'.dshpu-chipText{display:block;line-height:14px;font-variant-numeric:tabular-nums;transform:translateY(-0.4px)}',
|
|
222
268
|
'.dshpu-spin{animation:dshpu-rotate 1s linear infinite}',
|
|
223
269
|
'@keyframes dshpu-rotate{to{transform:rotate(360deg)}}',
|
|
224
270
|
'.dshpu-body{display:flex;flex-direction:column;gap:14px;min-height:160px}',
|
|
@@ -265,6 +311,14 @@ window.__ModuleLoader__.load({
|
|
|
265
311
|
'.dshpu-actions{display:flex;justify-content:flex-end;align-items:center;gap:8px;width:100%}',
|
|
266
312
|
'.dshpu-footerError{flex:1;min-width:0;margin-right:8px;font-size:12px;line-height:18px;color:var(--dsw-alias-state-error-primary,#d93025);text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
267
313
|
'.dshpu-modal.dshpu-modal{width:560px;max-width:calc(100vw - 48px)}',
|
|
314
|
+
'.dshpu-banner{margin-bottom:14px}',
|
|
315
|
+
'.dshpu-restartBar{display:flex;align-items:center;gap:10px;border:1px solid color-mix(in srgb, var(--dsw-alias-state-warn-primary,#b26a00) 45%, transparent);border-radius:10px;padding:8px 10px 8px 12px;background:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#b26a00) 8%, transparent);color:var(--dsw-alias-state-warn-primary,#b26a00);font-size:12px;line-height:18px}',
|
|
316
|
+
'.dshpu-restartBar[data-blocked="true"]{border-color:color-mix(in srgb, var(--dsw-alias-state-error-primary,#d93025) 45%, transparent);background:color-mix(in srgb, var(--dsw-alias-state-error-primary,#d93025) 8%, transparent);color:var(--dsw-alias-state-error-primary,#d93025)}',
|
|
317
|
+
'.dshpu-restartBar svg{flex:none}',
|
|
318
|
+
'.dshpu-restartText{flex:1;min-width:0;word-break:break-word}',
|
|
319
|
+
'.dshpu-restartError{margin-top:2px;color:var(--dsw-alias-state-error-primary,#d93025)}',
|
|
320
|
+
'.dshpu-lastBatch{display:flex;align-items:center;justify-content:space-between;gap:12px;border:1px solid var(--dsw-alias-border-l1,#eceef2);border-radius:10px;padding:6px 8px 6px 12px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#657080);background:var(--dsw-alias-bg-layer-2,#f7f8fa)}',
|
|
321
|
+
'.dshpu-back{display:flex;justify-content:flex-start}',
|
|
268
322
|
'@media (prefers-reduced-motion: reduce){.dshpu-spin{animation:none}.dshpu-barFill{transition:none}}',
|
|
269
323
|
].join('')
|
|
270
324
|
|
|
@@ -301,6 +355,39 @@ window.__ModuleLoader__.load({
|
|
|
301
355
|
return Math.max(0, Math.min(job.state === 'running' ? 99 : 100, value))
|
|
302
356
|
}
|
|
303
357
|
|
|
358
|
+
/**
|
|
359
|
+
* A finished batch must not own the dialog: opening the entry after an
|
|
360
|
+
* update has to show the newest available updates, with the previous
|
|
361
|
+
* batch reachable on demand instead of hiding them.
|
|
362
|
+
*/
|
|
363
|
+
function resolvePanelView(job, resultsView) {
|
|
364
|
+
const state = job === null || job === undefined ? null : job.state
|
|
365
|
+
const active = state === 'queued' || state === 'starting' || state === 'running'
|
|
366
|
+
const finished = job !== null && job !== undefined && active !== true
|
|
367
|
+
&& ((job.results?.length ?? 0) > 0 || job.state === 'failed')
|
|
368
|
+
return { active, finished, showJob: active === true || (finished === true && resultsView === true) }
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* The restart requirement is Host state, not job state: it survives closing
|
|
373
|
+
* the dialog and later batches. `blocked` means the last batch left an
|
|
374
|
+
* unreconciled failure, so restarting now could boot a broken profile.
|
|
375
|
+
*/
|
|
376
|
+
function resolveRestart(snapshot) {
|
|
377
|
+
const job = snapshot?.job ?? null
|
|
378
|
+
const restart = snapshot?.restart ?? null
|
|
379
|
+
const jobPending = job !== null && job.restartRequired === true && job.unreconciled !== true
|
|
380
|
+
const pending = restart?.pending === true || jobPending === true
|
|
381
|
+
const blocked = restart?.blocked === true
|
|
382
|
+
|| (job !== null && job.unreconciled === true && job.restartRequired === true)
|
|
383
|
+
const names = Array.isArray(restart?.names) && restart.names.length > 0
|
|
384
|
+
? restart.names.filter((name) => typeof name === 'string')
|
|
385
|
+
: (job?.results ?? [])
|
|
386
|
+
.filter((entry) => entry.ok === true && (entry.restartRequired === true || entry.hasClient === true))
|
|
387
|
+
.map((entry) => entry.name)
|
|
388
|
+
.filter((name) => typeof name === 'string')
|
|
389
|
+
return { pending, blocked: pending === true && blocked === true, count: names.length, names }
|
|
390
|
+
}
|
|
304
391
|
function apply(ctx) {
|
|
305
392
|
const store = createStore({ snapshot: null, residue: null, loading: true, checking: false, error: null })
|
|
306
393
|
let disposed = false
|
|
@@ -320,7 +407,7 @@ window.__ModuleLoader__.load({
|
|
|
320
407
|
}
|
|
321
408
|
|
|
322
409
|
function message(code) {
|
|
323
|
-
const known = /^(busy|busy-session|check-first|release-changed|invalid-request|registry-unavailable|request-too-large|operation-failed|service-unavailable|snapshot-failed|rollback-unavailable|verification-failed|dsh-update)$/
|
|
410
|
+
const known = /^(busy|busy-session|check-first|release-changed|invalid-request|registry-unavailable|request-too-large|operation-failed|service-unavailable|snapshot-failed|rollback-unavailable|verification-failed|dsh-update|self-update-alone)$/
|
|
324
411
|
return t(known.test(code) ? 'error.' + code : 'error.operation-failed')
|
|
325
412
|
}
|
|
326
413
|
|
|
@@ -468,15 +555,6 @@ window.__ModuleLoader__.load({
|
|
|
468
555
|
}
|
|
469
556
|
}
|
|
470
557
|
|
|
471
|
-
async function dismissJob() {
|
|
472
|
-
try {
|
|
473
|
-
const snapshot = await api({ action: 'dismiss' })
|
|
474
|
-
publish({ snapshot })
|
|
475
|
-
} catch {
|
|
476
|
-
// A stale dismiss is harmless; the next state read reconciles it.
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
558
|
function schedule() {
|
|
481
559
|
if (disposed) return
|
|
482
560
|
if (timer !== null) clearTimeout(timer)
|
|
@@ -498,6 +576,7 @@ window.__ModuleLoader__.load({
|
|
|
498
576
|
return t('phase.' + (phase === 'verifying' || phase === 'removing' || phase === 'installing' || phase === 'finished' ? phase : 'finished'))
|
|
499
577
|
}
|
|
500
578
|
|
|
579
|
+
|
|
501
580
|
function StatusNote({ tone = 'info', icon, children }) {
|
|
502
581
|
return h('div', { className: 'dshpu-note', 'data-tone': tone },
|
|
503
582
|
icon,
|
|
@@ -505,9 +584,46 @@ window.__ModuleLoader__.load({
|
|
|
505
584
|
)
|
|
506
585
|
}
|
|
507
586
|
|
|
508
|
-
|
|
587
|
+
/**
|
|
588
|
+
* The one place a restart is offered. It stays visible for as long as the
|
|
589
|
+
* Host reports a pending restart, so `稍后` (closing the dialog) does not
|
|
590
|
+
* silently drop the requirement.
|
|
591
|
+
*/
|
|
592
|
+
function RestartBanner({ visible, count, blocked, restarting, errorText, retryBusy, onRestart, onRetryFailed }) {
|
|
593
|
+
if (visible !== true) return null
|
|
594
|
+
return h('div', { className: 'dshpu-banner' },
|
|
595
|
+
h('div', {
|
|
596
|
+
className: 'dshpu-restartBar',
|
|
597
|
+
role: 'status',
|
|
598
|
+
'data-blocked': blocked === true ? 'true' : undefined,
|
|
599
|
+
},
|
|
600
|
+
h(blocked === true ? UI.IconWarningOutlineMedium : UI.IconRefreshOutlineRegular, { size: 16 }),
|
|
601
|
+
h('div', { className: 'dshpu-restartText' },
|
|
602
|
+
blocked === true ? t('restart.bannerBlocked') : t('restart.banner', { count }),
|
|
603
|
+
errorText === null || errorText === undefined
|
|
604
|
+
? null
|
|
605
|
+
: h('div', { className: 'dshpu-restartError' }, errorText)),
|
|
606
|
+
blocked === true
|
|
607
|
+
? onRetryFailed === undefined
|
|
608
|
+
? null
|
|
609
|
+
: h(UI.Button, {
|
|
610
|
+
variant: 'outline',
|
|
611
|
+
disabled: retryBusy === true,
|
|
612
|
+
onClick: onRetryFailed,
|
|
613
|
+
}, retryBusy === true ? t('done.retryBusy') : t('done.retryFailed'))
|
|
614
|
+
: h(UI.Button, {
|
|
615
|
+
variant: 'primary',
|
|
616
|
+
disabled: restarting === true,
|
|
617
|
+
onClick: onRestart,
|
|
618
|
+
}, restarting === true ? t('done.restarting') : t('done.restartButton')),
|
|
619
|
+
),
|
|
620
|
+
)
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function UpdateRow({ name, description, from, to, disabled, status, tone, showCheckbox, checked, onToggle, bootCritical, dependents, self }) {
|
|
509
624
|
const risks = []
|
|
510
|
-
if (
|
|
625
|
+
if (self === true) risks.push(t('risk.self'))
|
|
626
|
+
else if (bootCritical === true) risks.push(t('risk.boot'))
|
|
511
627
|
if ((dependents?.length ?? 0) > 0) risks.push(t('risk.provider', { count: dependents.length }))
|
|
512
628
|
return h('li', { className: 'dshpu-row' },
|
|
513
629
|
showCheckbox
|
|
@@ -533,7 +649,7 @@ window.__ModuleLoader__.load({
|
|
|
533
649
|
)
|
|
534
650
|
}
|
|
535
651
|
|
|
536
|
-
function ProgressView({ job, refresh, retryFailed, retryBusy, restartApp, restarting, restartError }) {
|
|
652
|
+
function ProgressView({ job, refresh, retryFailed, retryBusy, restartApp, restarting, restartError, onBack }) {
|
|
537
653
|
const [, setTick] = useState(0)
|
|
538
654
|
const waiting = job.state === 'queued' || job.state === 'starting'
|
|
539
655
|
const needsReload = refresh?.needsReload === true
|
|
@@ -578,6 +694,10 @@ window.__ModuleLoader__.load({
|
|
|
578
694
|
: ' ' + (unreconciled.rollback.ok === true ? t('done.rollbackOk') : t('done.rollbackFailed'))
|
|
579
695
|
|
|
580
696
|
return h(React.Fragment, null,
|
|
697
|
+
onBack === undefined
|
|
698
|
+
? null
|
|
699
|
+
: h('div', { className: 'dshpu-back' },
|
|
700
|
+
h('button', { type: 'button', className: 'dshpu-link', onClick: onBack }, t('results.back'))),
|
|
581
701
|
waiting
|
|
582
702
|
? h(StatusNote, { tone: 'info', icon: h(UI.IconClockOutlineRegular, { size: 16 }) }, phaseText)
|
|
583
703
|
: h('div', { className: 'dshpu-progress' },
|
|
@@ -647,10 +767,6 @@ window.__ModuleLoader__.load({
|
|
|
647
767
|
? h(StatusNote, { tone: 'info', icon: h(UI.IconInfoOutlineRegular, { size: 16 }) },
|
|
648
768
|
t('done.skipped', { count: skipped.length }))
|
|
649
769
|
: null,
|
|
650
|
-
job.state === 'done' && failures.length === 0 && job.restartRequired === true
|
|
651
|
-
? h(StatusNote, { tone: 'info', icon: h(UI.IconInfoOutlineRegular, { size: 16 }) },
|
|
652
|
-
t('done.restart'))
|
|
653
|
-
: null,
|
|
654
770
|
job.state === 'done' && refresh?.reloaded === true
|
|
655
771
|
? h(StatusNote, { tone: 'info', icon: h(UI.IconRefreshOutlineRegular, { size: 16 }) }, t('refresh.done'))
|
|
656
772
|
: null,
|
|
@@ -679,14 +795,30 @@ window.__ModuleLoader__.load({
|
|
|
679
795
|
)
|
|
680
796
|
}
|
|
681
797
|
|
|
682
|
-
function ListView({ state, updates, selected, toggle, busy, queueOffer, desktopBlocked, desktopPhase }) {
|
|
798
|
+
function ListView({ state, updates, selected, toggle, busy, queueOffer, desktopBlocked, desktopPhase, lastJob, onShowResults }) {
|
|
683
799
|
const snapshot = state.snapshot
|
|
800
|
+
const lastResults = lastJob?.results ?? []
|
|
801
|
+
const lastOk = lastResults.filter((entry) => entry.ok === true).length
|
|
802
|
+
const lastFailed = lastResults.filter((entry) => entry.ok !== true && entry.skipped !== true).length
|
|
684
803
|
const checking = state.checking || snapshot?.checking === true
|
|
685
804
|
const checkedAt = snapshot?.checkedAt
|
|
686
805
|
const risky = (item) => item.bootCritical === true || (item.dependents?.length ?? 0) > 0
|
|
687
|
-
const riskySelected = updates.filter((item) => selected.has(item.name) && risky(item))
|
|
688
|
-
const riskyUnselected = updates.filter((item) => !selected.has(item.name) && risky(item))
|
|
806
|
+
const riskySelected = updates.filter((item) => selected.has(item.name) && item.self !== true && risky(item))
|
|
807
|
+
const riskyUnselected = updates.filter((item) => !selected.has(item.name) && item.self !== true && risky(item))
|
|
808
|
+
const selfItems = updates.filter((item) => item.self === true)
|
|
809
|
+
const selfSelected = selfItems.some((item) => selected.has(item.name))
|
|
810
|
+
const selfMixed = selfSelected && selected.size > 1
|
|
689
811
|
return h('div', { className: 'dshpu-body' },
|
|
812
|
+
lastJob === null || lastJob === undefined
|
|
813
|
+
? null
|
|
814
|
+
: h('div', { className: 'dshpu-lastBatch' },
|
|
815
|
+
h('span', null,
|
|
816
|
+
lastOk === 0 && lastFailed === 0
|
|
817
|
+
? t('results.summaryEmpty')
|
|
818
|
+
: lastFailed > 0
|
|
819
|
+
? t('results.summary', { updated: lastOk, failed: lastFailed })
|
|
820
|
+
: t('results.summaryClean', { updated: lastOk })),
|
|
821
|
+
h('button', { type: 'button', className: 'dshpu-link', onClick: onShowResults }, t('results.show'))),
|
|
690
822
|
h('div', { className: 'dshpu-summary' },
|
|
691
823
|
h('div', { className: 'dshpu-summaryText' },
|
|
692
824
|
updates.length > 0 ? t('list.summary', { count: updates.length }) : t('list.empty'),
|
|
@@ -718,6 +850,10 @@ window.__ModuleLoader__.load({
|
|
|
718
850
|
? h(StatusNote, { tone: 'warn', icon: h(UI.IconWarningOutlineMedium, { size: 16 }) },
|
|
719
851
|
t('risk.warning'))
|
|
720
852
|
: null,
|
|
853
|
+
selfItems.length > 0
|
|
854
|
+
? h(StatusNote, { tone: selfMixed === true ? 'warn' : 'info', icon: selfMixed === true ? h(UI.IconWarningOutlineMedium, { size: 16 }) : h(UI.IconInfoOutlineRegular, { size: 16 }) },
|
|
855
|
+
selfMixed === true ? t('self.alone') : t('self.note', { name: selfItems[0].name }))
|
|
856
|
+
: null,
|
|
721
857
|
updates.length > 0
|
|
722
858
|
? h('ul', { className: 'dshpu-list' },
|
|
723
859
|
updates.map((item) => h(UpdateRow, {
|
|
@@ -734,6 +870,7 @@ window.__ModuleLoader__.load({
|
|
|
734
870
|
tone: 'idle',
|
|
735
871
|
bootCritical: item.bootCritical,
|
|
736
872
|
dependents: item.dependents,
|
|
873
|
+
self: item.self === true,
|
|
737
874
|
})),
|
|
738
875
|
)
|
|
739
876
|
: null,
|
|
@@ -770,21 +907,41 @@ window.__ModuleLoader__.load({
|
|
|
770
907
|
const state = useStoreValue()
|
|
771
908
|
const snapshot = state.snapshot
|
|
772
909
|
const job = snapshot?.job ?? null
|
|
773
|
-
const jobState = job?.state
|
|
774
|
-
const showJob = job !== null && (['queued', 'starting', 'running'].includes(jobState) || (job.results?.length ?? 0) > 0)
|
|
775
910
|
const checking = state.checking || snapshot?.checking === true
|
|
776
911
|
const updates = snapshot?.updates ?? []
|
|
777
912
|
const namesKey = updates.map((item) => item.name).join('|')
|
|
778
913
|
const desktopPhase = snapshot?.desktopUpdate?.phase
|
|
779
914
|
const desktopBlocked = typeof desktopPhase === 'string'
|
|
780
915
|
&& ['available', 'downloading', 'verifying', 'installing', 'ready'].includes(desktopPhase)
|
|
916
|
+
const restart = resolveRestart(snapshot)
|
|
781
917
|
const [selected, setSelected] = useState(() => new Set())
|
|
782
918
|
const [busy, setBusy] = useState(false)
|
|
783
919
|
const [actionError, setActionError] = useState(null)
|
|
784
920
|
const [queueOffer, setQueueOffer] = useState(false)
|
|
921
|
+
// A finished batch is reachable on demand; the dialog itself always
|
|
922
|
+
// opens on the newest state so a fresh update list is never hidden
|
|
923
|
+
// behind the previous batch's progress view.
|
|
924
|
+
const [resultsView, setResultsView] = useState(false)
|
|
925
|
+
const wasOpen = useRef(open === true)
|
|
926
|
+
const view = resolvePanelView(job, resultsView)
|
|
927
|
+
const activeJob = view.active
|
|
928
|
+
const showJob = view.showJob
|
|
929
|
+
const finishedJob = view.finished
|
|
930
|
+
const failedResults = (job?.results ?? []).filter((entry) => entry.ok !== true && entry.skipped !== true)
|
|
785
931
|
|
|
786
932
|
useLocaleTick()
|
|
787
933
|
|
|
934
|
+
useEffect(() => {
|
|
935
|
+
if (open === true && wasOpen.current !== true) setResultsView(activeJob === true)
|
|
936
|
+
wasOpen.current = open === true
|
|
937
|
+
}, [open])
|
|
938
|
+
|
|
939
|
+
// Starting a batch from this dialog keeps the progress view selected
|
|
940
|
+
// once it finishes, so the result is shown instead of snapping away.
|
|
941
|
+
useEffect(() => {
|
|
942
|
+
if (activeJob === true) setResultsView(true)
|
|
943
|
+
}, [activeJob, job?.id])
|
|
944
|
+
|
|
788
945
|
useEffect(() => {
|
|
789
946
|
if (showJob) return
|
|
790
947
|
// Boot-critical plugins and providers other plugins inject are left
|
|
@@ -801,15 +958,31 @@ window.__ModuleLoader__.load({
|
|
|
801
958
|
}, [open])
|
|
802
959
|
|
|
803
960
|
function toggle(name, checked) {
|
|
961
|
+
// The update center is exclusive by construction: checking it clears
|
|
962
|
+
// the batch, and picking any other plugin clears it again.
|
|
963
|
+
const selfRow = updates.find((item) => item.self === true)
|
|
964
|
+
const isSelf = selfRow !== undefined && selfRow.name === name
|
|
804
965
|
setSelected((current) => {
|
|
805
966
|
const next = new Set(current)
|
|
806
|
-
if (checked)
|
|
807
|
-
|
|
967
|
+
if (checked) {
|
|
968
|
+
if (isSelf) next.clear()
|
|
969
|
+
else if (selfRow !== undefined) next.delete(selfRow.name)
|
|
970
|
+
next.add(name)
|
|
971
|
+
} else {
|
|
972
|
+
next.delete(name)
|
|
973
|
+
}
|
|
808
974
|
return next
|
|
809
975
|
})
|
|
810
976
|
}
|
|
811
977
|
|
|
812
978
|
async function submit(waitForIdle) {
|
|
979
|
+
// The update center cannot ride along with a batch: refuse locally
|
|
980
|
+
// instead of letting the Host reject the whole selection.
|
|
981
|
+
const selfSelected = updates.some((item) => item.self === true && selected.has(item.name))
|
|
982
|
+
if (selfSelected && selected.size > 1) {
|
|
983
|
+
setActionError('self-update-alone')
|
|
984
|
+
return
|
|
985
|
+
}
|
|
813
986
|
const names = [...selected]
|
|
814
987
|
if (names.length === 0) return
|
|
815
988
|
setBusy(true)
|
|
@@ -830,23 +1003,44 @@ window.__ModuleLoader__.load({
|
|
|
830
1003
|
}
|
|
831
1004
|
}
|
|
832
1005
|
|
|
1006
|
+
// Closing the dialog only hides it: the finished job and the restart
|
|
1007
|
+
// notice stay on the Host, so the next open does not lose them.
|
|
833
1008
|
const handleClose = () => {
|
|
834
|
-
if (job !== null && !['running', 'queued', 'starting'].includes(job.state)) void dismissJob()
|
|
835
1009
|
onClose()
|
|
836
1010
|
}
|
|
837
1011
|
|
|
838
1012
|
const loading = snapshot === null || snapshot === undefined || (checking && updates.length === 0)
|
|
839
1013
|
let body
|
|
840
|
-
if (showJob)
|
|
841
|
-
|
|
842
|
-
|
|
1014
|
+
if (showJob) {
|
|
1015
|
+
body = h(ProgressView, {
|
|
1016
|
+
job,
|
|
1017
|
+
refresh,
|
|
1018
|
+
retryFailed,
|
|
1019
|
+
retryBusy,
|
|
1020
|
+
restartApp,
|
|
1021
|
+
restarting,
|
|
1022
|
+
restartError,
|
|
1023
|
+
onBack: finishedJob === true ? () => setResultsView(false) : undefined,
|
|
1024
|
+
})
|
|
1025
|
+
} else if (loading) {
|
|
1026
|
+
body = h(EmptyOrLoading, { state })
|
|
1027
|
+
} else {
|
|
1028
|
+
body = h(ListView, {
|
|
1029
|
+
state,
|
|
1030
|
+
updates,
|
|
1031
|
+
selected,
|
|
1032
|
+
toggle,
|
|
1033
|
+
busy,
|
|
1034
|
+
queueOffer,
|
|
1035
|
+
desktopBlocked,
|
|
1036
|
+
desktopPhase,
|
|
1037
|
+
lastJob: finishedJob === true ? job : null,
|
|
1038
|
+
onShowResults: () => setResultsView(true),
|
|
1039
|
+
})
|
|
1040
|
+
}
|
|
843
1041
|
|
|
844
1042
|
const queueWaiting = showJob && (job.state === 'queued' || job.state === 'starting')
|
|
845
|
-
const
|
|
846
|
-
const unreconciled = job?.unreconciled === true || failedResults.some((entry) => entry.reconciled !== true)
|
|
847
|
-
const canRetry = showJob && failedResults.length > 0 && !['queued', 'starting', 'running'].includes(job.state)
|
|
848
|
-
const canRestart = showJob && job.state === 'done' && job.restartRequired === true && unreconciled !== true
|
|
849
|
-
const partial = failedResults.length > 0
|
|
1043
|
+
const canRetry = showJob && activeJob !== true && failedResults.length > 0
|
|
850
1044
|
const restartErrorText = restartError === null || restartError === undefined
|
|
851
1045
|
? null
|
|
852
1046
|
: restartError === 'restart-timeout' ? t('done.restartTimeout') : t('done.restartUnavailable')
|
|
@@ -854,25 +1048,15 @@ window.__ModuleLoader__.load({
|
|
|
854
1048
|
actionError !== null
|
|
855
1049
|
? h('div', { className: 'dshpu-footerError' }, message(actionError))
|
|
856
1050
|
: null,
|
|
857
|
-
restartErrorText !== null
|
|
858
|
-
? h('div', { className: 'dshpu-footerError' }, restartErrorText)
|
|
859
|
-
: null,
|
|
860
1051
|
showJob && job.state === 'running'
|
|
861
1052
|
? h(UI.Button, { variant: 'outline', onClick: handleClose }, t('panel.background'))
|
|
862
1053
|
: null,
|
|
863
1054
|
queueWaiting
|
|
864
1055
|
? h(UI.Button, { variant: 'outline', onClick: () => { void cancelQueued() } }, t('queue.cancel'))
|
|
865
1056
|
: null,
|
|
866
|
-
showJob &&
|
|
1057
|
+
showJob && activeJob !== true
|
|
867
1058
|
? h(UI.Button, { variant: 'outline', onClick: handleClose }, t('panel.done'))
|
|
868
1059
|
: null,
|
|
869
|
-
canRestart
|
|
870
|
-
? h(UI.Button, {
|
|
871
|
-
variant: partial ? 'outline' : 'primary',
|
|
872
|
-
disabled: restarting === true,
|
|
873
|
-
onClick: () => { void restartApp() },
|
|
874
|
-
}, restarting === true ? t('done.restarting') : t('done.restartButton'))
|
|
875
|
-
: null,
|
|
876
1060
|
canRetry
|
|
877
1061
|
? h(UI.Button, {
|
|
878
1062
|
variant: 'primary',
|
|
@@ -880,13 +1064,10 @@ window.__ModuleLoader__.load({
|
|
|
880
1064
|
onClick: () => { void retryFailed() },
|
|
881
1065
|
}, retryBusy === true ? t('done.retryBusy') : t('done.retryFailed'))
|
|
882
1066
|
: null,
|
|
883
|
-
showJob
|
|
884
|
-
? h(UI.Button, { variant: '
|
|
885
|
-
: null,
|
|
886
|
-
!showJob
|
|
887
|
-
? h(UI.Button, { variant: 'outline', onClick: handleClose }, t('panel.cancel'))
|
|
1067
|
+
showJob !== true
|
|
1068
|
+
? h(UI.Button, { variant: 'outline', onClick: handleClose }, t('panel.close'))
|
|
888
1069
|
: null,
|
|
889
|
-
|
|
1070
|
+
showJob !== true && updates.length > 0
|
|
890
1071
|
? h(UI.Button, {
|
|
891
1072
|
variant: 'primary',
|
|
892
1073
|
disabled: busy || checking || selected.size === 0 || desktopBlocked,
|
|
@@ -895,8 +1076,19 @@ window.__ModuleLoader__.load({
|
|
|
895
1076
|
: null,
|
|
896
1077
|
)
|
|
897
1078
|
|
|
1079
|
+
const banner = h(RestartBanner, {
|
|
1080
|
+
visible: restart.pending === true && activeJob !== true,
|
|
1081
|
+
count: restart.count,
|
|
1082
|
+
blocked: restart.blocked,
|
|
1083
|
+
restarting,
|
|
1084
|
+
errorText: restartErrorText,
|
|
1085
|
+
onRestart: () => { void restartApp() },
|
|
1086
|
+
onRetryFailed: failedResults.length > 0 ? () => { void retryFailed() } : undefined,
|
|
1087
|
+
retryBusy,
|
|
1088
|
+
})
|
|
1089
|
+
|
|
898
1090
|
const title = showJob
|
|
899
|
-
? queueWaiting ? t('queue.title') : t('panel.progressTitle')
|
|
1091
|
+
? queueWaiting ? t('queue.title') : activeJob ? t('panel.progressTitle') : t('panel.resultsTitle')
|
|
900
1092
|
: t('panel.title')
|
|
901
1093
|
|
|
902
1094
|
return h(UI.Modal, {
|
|
@@ -909,6 +1101,7 @@ window.__ModuleLoader__.load({
|
|
|
909
1101
|
contentClassName: 'dshpu-modalContent',
|
|
910
1102
|
},
|
|
911
1103
|
h('style', null, STYLE),
|
|
1104
|
+
banner,
|
|
912
1105
|
body,
|
|
913
1106
|
)
|
|
914
1107
|
}
|
|
@@ -1080,6 +1273,10 @@ window.__ModuleLoader__.load({
|
|
|
1080
1273
|
const waiting = phase === 'queued' || phase === 'starting'
|
|
1081
1274
|
const count = updates.length
|
|
1082
1275
|
const updateVisible = open || running || waiting || count > 0
|
|
1276
|
+
const restart = resolveRestart(snapshot)
|
|
1277
|
+
// Driven by Host state, not by the dialog: the restart chip stays in the
|
|
1278
|
+
// account row after the dialog is closed, until DSH actually restarts.
|
|
1279
|
+
const restartVisible = restart.pending === true
|
|
1083
1280
|
const residue = state.residue
|
|
1084
1281
|
const residueCount = residue?.items?.length ?? 0
|
|
1085
1282
|
const residueVisible = openResidue || residueCount > 0
|
|
@@ -1190,10 +1387,29 @@ window.__ModuleLoader__.load({
|
|
|
1190
1387
|
? t('action.tooltip', { count })
|
|
1191
1388
|
: t('action.label')
|
|
1192
1389
|
const residueLabel = t('residue.tooltip', { count: residueCount })
|
|
1390
|
+
const restartLabel = t(restart.blocked === true ? 'restart.tooltipBlocked' : 'restart.tooltip')
|
|
1193
1391
|
|
|
1194
|
-
const chips = host !== null && (updateVisible || residueVisible)
|
|
1392
|
+
const chips = host !== null && (updateVisible || residueVisible || restartVisible)
|
|
1195
1393
|
? createPortal(
|
|
1196
1394
|
h(React.Fragment, null,
|
|
1395
|
+
restartVisible
|
|
1396
|
+
? h(UI.Tooltip, { label: restartLabel, side: 'top', align: 'end' },
|
|
1397
|
+
h('button', {
|
|
1398
|
+
type: 'button',
|
|
1399
|
+
className: 'dshpu-chip is-restart',
|
|
1400
|
+
'data-blocked': restart.blocked === true ? 'true' : undefined,
|
|
1401
|
+
'aria-label': restartLabel,
|
|
1402
|
+
onClick: () => {
|
|
1403
|
+
setOpen(true)
|
|
1404
|
+
void refresh()
|
|
1405
|
+
},
|
|
1406
|
+
},
|
|
1407
|
+
h('span', { className: 'dshpu-chipIcon' },
|
|
1408
|
+
restart.blocked === true
|
|
1409
|
+
? h(UI.IconWarningOutlineMedium, { size: 14 })
|
|
1410
|
+
: h(UI.IconRefreshOutlineRegular, { size: 14 })),
|
|
1411
|
+
))
|
|
1412
|
+
: null,
|
|
1197
1413
|
updateVisible
|
|
1198
1414
|
? h(UI.Tooltip, { label: updateLabel, side: 'top', align: 'end' },
|
|
1199
1415
|
h('button', {
|
|
@@ -1293,6 +1509,12 @@ window.__ModuleLoader__.load({
|
|
|
1293
1509
|
}, 'dsh-plugin-update-center: desktop update gate')
|
|
1294
1510
|
}
|
|
1295
1511
|
|
|
1296
|
-
return {
|
|
1512
|
+
return {
|
|
1513
|
+
inject: ['slots', 'locale'],
|
|
1514
|
+
apply,
|
|
1515
|
+
// Pure view decisions, exported so the Node test can verify them without
|
|
1516
|
+
// a browser renderer.
|
|
1517
|
+
__testing: { resolvePanelView, resolveRestart },
|
|
1518
|
+
}
|
|
1297
1519
|
},
|
|
1298
1520
|
})
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/lib/engine.js
CHANGED
|
@@ -71,7 +71,8 @@ export function selectCandidates(bundles) {
|
|
|
71
71
|
if (bundle.readOnlyReason !== undefined) continue
|
|
72
72
|
if (bundle.error !== undefined) continue
|
|
73
73
|
if (typeof bundle.name !== 'string' || typeof bundle.version !== 'string') continue
|
|
74
|
-
|
|
74
|
+
// This plugin can update itself: the row is kept and flagged, because a
|
|
75
|
+
// self-update must run alone and always ends in a full restart.
|
|
75
76
|
if (parseVersion(bundle.version) === null) continue
|
|
76
77
|
if (parseBundleSource(bundle) === null) continue
|
|
77
78
|
if (seen.has(bundle.name)) continue
|
|
@@ -82,6 +83,7 @@ export function selectCandidates(bundles) {
|
|
|
82
83
|
enabled: bundle.enabled !== false,
|
|
83
84
|
source: bundle.source,
|
|
84
85
|
description: typeof bundle.description === 'string' ? bundle.description : '',
|
|
86
|
+
self: bundle.name === OWN_NAME,
|
|
85
87
|
})
|
|
86
88
|
}
|
|
87
89
|
return candidates
|
|
@@ -183,7 +185,20 @@ export function createEngine({
|
|
|
183
185
|
if (!manager || typeof manager.removeBundle !== 'function') throw new TypeError('pluginManager.removeBundle is required')
|
|
184
186
|
if (!registry || typeof registry.release !== 'function') throw new TypeError('a registry client is required')
|
|
185
187
|
|
|
186
|
-
const state = {
|
|
188
|
+
const state = {
|
|
189
|
+
checkedAt: 0,
|
|
190
|
+
checking: false,
|
|
191
|
+
rows: [],
|
|
192
|
+
job: null,
|
|
193
|
+
desktopUpdate: null,
|
|
194
|
+
/**
|
|
195
|
+
* Installed builds that still need a full DSH restart live here instead of
|
|
196
|
+
* on the job. A job is dismissible and is replaced by the next batch; the
|
|
197
|
+
* need to restart survives both, so it is its own Host state and is only
|
|
198
|
+
* cleared when a new Host process starts (the restart itself).
|
|
199
|
+
*/
|
|
200
|
+
restart: { pending: false, names: [], blocked: false, at: 0 },
|
|
201
|
+
}
|
|
187
202
|
const abort = new AbortController()
|
|
188
203
|
const queueSettings = { ...QUEUE_DEFAULTS, ...queue }
|
|
189
204
|
let checkPromise = null
|
|
@@ -297,6 +312,7 @@ export function createEngine({
|
|
|
297
312
|
dependents: row.dependents ?? [],
|
|
298
313
|
clientDeps: row.clientDeps ?? [],
|
|
299
314
|
hasClient: row.hasClient === true,
|
|
315
|
+
self: row.self === true,
|
|
300
316
|
}))
|
|
301
317
|
return {
|
|
302
318
|
checkedAt: state.checkedAt,
|
|
@@ -306,6 +322,12 @@ export function createEngine({
|
|
|
306
322
|
checked: state.rows.length,
|
|
307
323
|
desktopUpdate: state.desktopUpdate === null ? null : { ...state.desktopUpdate },
|
|
308
324
|
job: state.job === null ? null : structuredClone(state.job),
|
|
325
|
+
restart: {
|
|
326
|
+
pending: state.restart.pending === true,
|
|
327
|
+
names: [...state.restart.names],
|
|
328
|
+
blocked: state.restart.blocked === true,
|
|
329
|
+
at: state.restart.at,
|
|
330
|
+
},
|
|
309
331
|
}
|
|
310
332
|
}
|
|
311
333
|
|
|
@@ -492,19 +514,36 @@ export function createEngine({
|
|
|
492
514
|
const previous = await registry.manifest(row.name, row.version, abort.signal, row.registry ?? undefined).catch(() => null)
|
|
493
515
|
if (previous === null || previous.manifest?.dsh?.bundle === undefined) throw coded('rollback-unavailable')
|
|
494
516
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
}
|
|
501
|
-
job.current = { ...job.current, phase: 'installing' }
|
|
502
|
-
const result = await retryResult(() => manager.installBundle(`${row.name}@${row.latest}`, {
|
|
517
|
+
// A self-update installs over the running package: removing it first would
|
|
518
|
+
// delete the very files the Host is executing. Any other plugin keeps the
|
|
519
|
+
// remove-then-install order.
|
|
520
|
+
const selfUpdate = row.self === true
|
|
521
|
+
const installOptions = {
|
|
503
522
|
enabled: row.enabled,
|
|
504
523
|
saveExact: true,
|
|
505
524
|
...row.registry === null || row.registry === undefined ? {} : { registry: row.registry },
|
|
506
525
|
requestId: `${job.id}:${row.name}`,
|
|
507
|
-
}
|
|
526
|
+
}
|
|
527
|
+
if (!selfUpdate) {
|
|
528
|
+
job.current = { ...job.current, phase: 'removing' }
|
|
529
|
+
const removal = await retryResult(() => manager.removeBundle(row.name))
|
|
530
|
+
if (removal?.error) {
|
|
531
|
+
failure = { error: removal.error.code ?? 'remove-failed', application: removal.application ?? null }
|
|
532
|
+
throw coded(failure.error)
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
job.current = { ...job.current, phase: 'installing' }
|
|
536
|
+
let result = await retryResult(() => manager.installBundle(`${row.name}@${row.latest}`, installOptions))
|
|
537
|
+
// The in-place install can be refused when the package already owns the
|
|
538
|
+
// row; the official remove-then-install path still recovers it.
|
|
539
|
+
if (selfUpdate && !successful(result)) {
|
|
540
|
+
const removal = await retryResult(() => manager.removeBundle(row.name))
|
|
541
|
+
if (removal?.error) {
|
|
542
|
+
failure = { error: removal.error.code ?? 'remove-failed', application: removal.application ?? null }
|
|
543
|
+
throw coded(failure.error)
|
|
544
|
+
}
|
|
545
|
+
result = await retryResult(() => manager.installBundle(`${row.name}@${row.latest}`, installOptions))
|
|
546
|
+
}
|
|
508
547
|
if (!successful(result)) {
|
|
509
548
|
failure = { error: result?.error?.code ?? 'install-failed', application: result?.application ?? null }
|
|
510
549
|
throw coded('install-failed')
|
|
@@ -518,7 +557,9 @@ export function createEngine({
|
|
|
518
557
|
failure = { error: 'verification-failed', verification }
|
|
519
558
|
throw coded('verification-failed')
|
|
520
559
|
}
|
|
521
|
-
|
|
560
|
+
// A self-update always needs the restart: the newly installed code only
|
|
561
|
+
// becomes active in a fresh Host process.
|
|
562
|
+
const restartRequired = result.application === 'restart-required' || row.self === true
|
|
522
563
|
if (restartRequired) job.restartRequired = true
|
|
523
564
|
await record(job, {
|
|
524
565
|
name: row.name,
|
|
@@ -574,6 +615,7 @@ export function createEngine({
|
|
|
574
615
|
bootCritical: row.bootCritical === true,
|
|
575
616
|
dependents: row.dependents ?? [],
|
|
576
617
|
hasClient: row.hasClient === true,
|
|
618
|
+
self: row.self === true,
|
|
577
619
|
})),
|
|
578
620
|
results: [],
|
|
579
621
|
failure: null,
|
|
@@ -623,6 +665,20 @@ export function createEngine({
|
|
|
623
665
|
const bootClient = successes.some((entry) => entry.bootCritical === true && entry.hasClient === true)
|
|
624
666
|
job.restartRequired = job.restartRequired === true || bootClient || clientSuccess
|
|
625
667
|
job.reloadRequired = false
|
|
668
|
+
// Promote the restart requirement to Host state so closing the dialog or
|
|
669
|
+
// starting the next batch cannot hide it. An unreconciled failure keeps the
|
|
670
|
+
// flag but blocks the restart button: restarting could boot a broken profile.
|
|
671
|
+
const restartEntries = successes.filter((entry) => entry.restartRequired === true || entry.hasClient === true)
|
|
672
|
+
if (restartEntries.length > 0) {
|
|
673
|
+
state.restart.pending = true
|
|
674
|
+
state.restart.at = now()
|
|
675
|
+
for (const entry of restartEntries) {
|
|
676
|
+
if (typeof entry.name === 'string' && !state.restart.names.includes(entry.name)) {
|
|
677
|
+
state.restart.names.push(entry.name)
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
state.restart.blocked = state.restart.pending === true && job.unreconciled === true
|
|
626
682
|
}
|
|
627
683
|
|
|
628
684
|
function orderByDependencies(selected) {
|
|
@@ -760,6 +816,10 @@ export function createEngine({
|
|
|
760
816
|
if (!selected.includes(row)) selected.push(row)
|
|
761
817
|
}
|
|
762
818
|
if (selected.length === 0) throw coded('invalid-request')
|
|
819
|
+
// Updating this plugin replaces the code the running Host is executing.
|
|
820
|
+
// Mixing it with other plugins would leave the batch half-applied behind a
|
|
821
|
+
// restart prompt that explains nothing, so it always runs alone.
|
|
822
|
+
if (selected.some((row) => row.self === true) && selected.length > 1) throw coded('self-update-alone')
|
|
763
823
|
if (desktopBlocked()) throw coded('dsh-update')
|
|
764
824
|
let guard
|
|
765
825
|
try {
|
package/lib/http.js
CHANGED
|
@@ -22,6 +22,7 @@ const EXPECTED = new Set([
|
|
|
22
22
|
'rollback-unavailable',
|
|
23
23
|
'verification-failed',
|
|
24
24
|
'dsh-update',
|
|
25
|
+
'self-update-alone',
|
|
25
26
|
])
|
|
26
27
|
|
|
27
28
|
function respond(payload, status = 200) {
|
|
@@ -70,7 +71,7 @@ function statusFor(code) {
|
|
|
70
71
|
if (code === 'method-not-allowed') return 405
|
|
71
72
|
if (code === 'registry-unavailable') return 502
|
|
72
73
|
if (code === 'snapshot-failed' || code === 'verification-failed') return 500
|
|
73
|
-
if (code === 'busy' || code === 'busy-session' || code === 'check-first' || code === 'rollback-unavailable' || code === 'dsh-update') return 409
|
|
74
|
+
if (code === 'busy' || code === 'busy-session' || code === 'check-first' || code === 'rollback-unavailable' || code === 'dsh-update' || code === 'self-update-alone') return 409
|
|
74
75
|
if (code === 'restart-unavailable') return 501
|
|
75
76
|
return EXPECTED.has(code) ? 400 : 500
|
|
76
77
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-update-center",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "尊重 DSH 原始风格的插件更新插件:在侧边栏检查、排队更新已安装插件,支持快照回滚、安装后校验、卸载残留清理与离线恢复。 A DSH-native plugin update center for the sidebar with snapshots, rollback, queued updates and leftover cleanup.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"icon.svg",
|
|
36
36
|
"repair.mjs",
|
|
37
37
|
"repair.cmd",
|
|
38
|
-
"README.md"
|
|
38
|
+
"README.md",
|
|
39
|
+
"docs/*.png"
|
|
39
40
|
],
|
|
40
41
|
"dsh": {
|
|
41
42
|
"bundle": {
|