dsh-plugin-update-center 1.0.6 → 1.1.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/README.md +15 -6
- package/client.js +285 -57
- package/index.js +6 -2
- package/lib/engine.js +72 -12
- package/lib/http.js +3 -2
- package/lib/restart.js +95 -32
- package/package.json +1 -1
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**:黄色描边的重启图标(警告色,和下载/垃圾桶明确区分);只要 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 本体更新
|
package/client.js
CHANGED
|
@@ -61,10 +61,15 @@ window.__ModuleLoader__.load({
|
|
|
61
61
|
'done.restartButton': '完整重启',
|
|
62
62
|
'done.restarting': '正在重启 DSH…',
|
|
63
63
|
'done.restartUnavailable': '自动重启不可用,请手动退出并重新打开 DSH。',
|
|
64
|
+
'done.restartTimeout': '自动重启未完成,请手动重启 DSH。',
|
|
64
65
|
'done.refresh': '更新已安装;如界面仍是旧版本,请刷新页面或重启 DSH。',
|
|
65
66
|
'done.snapshot': '更新前快照:{path}',
|
|
66
67
|
'risk.boot': '启动关键',
|
|
67
68
|
'risk.provider': '被 {count} 个插件依赖',
|
|
69
|
+
'risk.self': '本插件自身 · 单独更新',
|
|
70
|
+
'self.note': '{name} 是更新中心本体,只能单独更新;安装完成后必须完整重启 DSH。',
|
|
71
|
+
'self.alone': '本插件不能和其他插件一起更新。请只勾选它,或先取消勾选它。',
|
|
72
|
+
'error.self-update-alone': '本插件只能单独更新,请只勾选它。',
|
|
68
73
|
'risk.unselected': '{count} 个启动关键 / 被依赖插件未勾选。请单独更新它们,并在更新后立即重启验证。',
|
|
69
74
|
'risk.warning': '选中的插件包含启动关键项。更新后请立即重启验证;若 DSH 无法打开,在错误对话框点「禁用第三方插件、备份 profile patch 并重启」,或运行 repair.cmd 恢复快照。',
|
|
70
75
|
'done.summary': '已更新 {count} 个插件',
|
|
@@ -111,6 +116,16 @@ window.__ModuleLoader__.load({
|
|
|
111
116
|
'residue.cleaned': '已清理 {count} 项',
|
|
112
117
|
'residue.scan': '重新扫描',
|
|
113
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': '返回更新列表',
|
|
114
129
|
}
|
|
115
130
|
|
|
116
131
|
const en = {
|
|
@@ -156,10 +171,15 @@ window.__ModuleLoader__.load({
|
|
|
156
171
|
'done.restartButton': 'Restart DSH',
|
|
157
172
|
'done.restarting': 'Restarting DSH…',
|
|
158
173
|
'done.restartUnavailable': 'Automatic restart is unavailable. Quit and reopen DSH manually.',
|
|
174
|
+
'done.restartTimeout': 'The automatic restart did not finish. Restart DSH manually.',
|
|
159
175
|
'done.refresh': 'Updates are installed. Refresh the page or restart DSH if the UI still shows the old version.',
|
|
160
176
|
'done.snapshot': 'Pre-update snapshot: {path}',
|
|
161
177
|
'risk.boot': 'Boot-critical',
|
|
162
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.',
|
|
163
183
|
'risk.unselected': '{count} boot-critical / depended-on plugins are not selected. Update them one at a time and restart to verify.',
|
|
164
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.',
|
|
165
185
|
'done.summary': '{count} plugins updated',
|
|
@@ -206,6 +226,16 @@ window.__ModuleLoader__.load({
|
|
|
206
226
|
'residue.cleaned': 'Cleaned {count} items',
|
|
207
227
|
'residue.scan': 'Scan again',
|
|
208
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',
|
|
209
239
|
}
|
|
210
240
|
|
|
211
241
|
const STYLE = [
|
|
@@ -214,6 +244,10 @@ window.__ModuleLoader__.load({
|
|
|
214
244
|
'.dshpu-chip:hover{background:color-mix(in srgb, var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6) 14%, transparent)}',
|
|
215
245
|
'.dshpu-chip.is-residue{border-color:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#b26a00) 25%, transparent);color:var(--dsw-alias-state-warn-primary,#b26a00);background:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#b26a00) 8%, transparent)}',
|
|
216
246
|
'.dshpu-chip.is-residue:hover{background:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#b26a00) 14%, transparent)}',
|
|
247
|
+
'.dshpu-chip.is-restart{grid-template-columns:14px;width:28px;padding:0;justify-content:center;border-color:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#b26a00) 45%, transparent);color:var(--dsw-alias-state-warn-primary,#b26a00);background:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#b26a00) 10%, transparent)}',
|
|
248
|
+
'.dshpu-chip.is-restart:hover{background:color-mix(in srgb, var(--dsw-alias-state-warn-primary,#b26a00) 18%, transparent)}',
|
|
249
|
+
'.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)}',
|
|
250
|
+
'.dshpu-chip.is-restart[data-blocked="true"]:hover{background:color-mix(in srgb, var(--dsw-alias-state-error-primary,#d93025) 16%, transparent)}',
|
|
217
251
|
'.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}',
|
|
218
252
|
'.dshpu-chipIcon{display:grid;place-items:center;width:14px;height:14px}',
|
|
219
253
|
'.dshpu-chipText{font-variant-numeric:tabular-nums}',
|
|
@@ -263,6 +297,14 @@ window.__ModuleLoader__.load({
|
|
|
263
297
|
'.dshpu-actions{display:flex;justify-content:flex-end;align-items:center;gap:8px;width:100%}',
|
|
264
298
|
'.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}',
|
|
265
299
|
'.dshpu-modal.dshpu-modal{width:560px;max-width:calc(100vw - 48px)}',
|
|
300
|
+
'.dshpu-banner{margin-bottom:14px}',
|
|
301
|
+
'.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}',
|
|
302
|
+
'.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)}',
|
|
303
|
+
'.dshpu-restartBar svg{flex:none}',
|
|
304
|
+
'.dshpu-restartText{flex:1;min-width:0;word-break:break-word}',
|
|
305
|
+
'.dshpu-restartError{margin-top:2px;color:var(--dsw-alias-state-error-primary,#d93025)}',
|
|
306
|
+
'.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)}',
|
|
307
|
+
'.dshpu-back{display:flex;justify-content:flex-start}',
|
|
266
308
|
'@media (prefers-reduced-motion: reduce){.dshpu-spin{animation:none}.dshpu-barFill{transition:none}}',
|
|
267
309
|
].join('')
|
|
268
310
|
|
|
@@ -299,6 +341,39 @@ window.__ModuleLoader__.load({
|
|
|
299
341
|
return Math.max(0, Math.min(job.state === 'running' ? 99 : 100, value))
|
|
300
342
|
}
|
|
301
343
|
|
|
344
|
+
/**
|
|
345
|
+
* A finished batch must not own the dialog: opening the entry after an
|
|
346
|
+
* update has to show the newest available updates, with the previous
|
|
347
|
+
* batch reachable on demand instead of hiding them.
|
|
348
|
+
*/
|
|
349
|
+
function resolvePanelView(job, resultsView) {
|
|
350
|
+
const state = job === null || job === undefined ? null : job.state
|
|
351
|
+
const active = state === 'queued' || state === 'starting' || state === 'running'
|
|
352
|
+
const finished = job !== null && job !== undefined && active !== true
|
|
353
|
+
&& ((job.results?.length ?? 0) > 0 || job.state === 'failed')
|
|
354
|
+
return { active, finished, showJob: active === true || (finished === true && resultsView === true) }
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* The restart requirement is Host state, not job state: it survives closing
|
|
359
|
+
* the dialog and later batches. `blocked` means the last batch left an
|
|
360
|
+
* unreconciled failure, so restarting now could boot a broken profile.
|
|
361
|
+
*/
|
|
362
|
+
function resolveRestart(snapshot) {
|
|
363
|
+
const job = snapshot?.job ?? null
|
|
364
|
+
const restart = snapshot?.restart ?? null
|
|
365
|
+
const jobPending = job !== null && job.restartRequired === true && job.unreconciled !== true
|
|
366
|
+
const pending = restart?.pending === true || jobPending === true
|
|
367
|
+
const blocked = restart?.blocked === true
|
|
368
|
+
|| (job !== null && job.unreconciled === true && job.restartRequired === true)
|
|
369
|
+
const names = Array.isArray(restart?.names) && restart.names.length > 0
|
|
370
|
+
? restart.names.filter((name) => typeof name === 'string')
|
|
371
|
+
: (job?.results ?? [])
|
|
372
|
+
.filter((entry) => entry.ok === true && (entry.restartRequired === true || entry.hasClient === true))
|
|
373
|
+
.map((entry) => entry.name)
|
|
374
|
+
.filter((name) => typeof name === 'string')
|
|
375
|
+
return { pending, blocked: pending === true && blocked === true, count: names.length, names }
|
|
376
|
+
}
|
|
302
377
|
function apply(ctx) {
|
|
303
378
|
const store = createStore({ snapshot: null, residue: null, loading: true, checking: false, error: null })
|
|
304
379
|
let disposed = false
|
|
@@ -318,7 +393,7 @@ window.__ModuleLoader__.load({
|
|
|
318
393
|
}
|
|
319
394
|
|
|
320
395
|
function message(code) {
|
|
321
|
-
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)$/
|
|
396
|
+
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)$/
|
|
322
397
|
return t(known.test(code) ? 'error.' + code : 'error.operation-failed')
|
|
323
398
|
}
|
|
324
399
|
|
|
@@ -466,15 +541,6 @@ window.__ModuleLoader__.load({
|
|
|
466
541
|
}
|
|
467
542
|
}
|
|
468
543
|
|
|
469
|
-
async function dismissJob() {
|
|
470
|
-
try {
|
|
471
|
-
const snapshot = await api({ action: 'dismiss' })
|
|
472
|
-
publish({ snapshot })
|
|
473
|
-
} catch {
|
|
474
|
-
// A stale dismiss is harmless; the next state read reconciles it.
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
544
|
function schedule() {
|
|
479
545
|
if (disposed) return
|
|
480
546
|
if (timer !== null) clearTimeout(timer)
|
|
@@ -496,6 +562,7 @@ window.__ModuleLoader__.load({
|
|
|
496
562
|
return t('phase.' + (phase === 'verifying' || phase === 'removing' || phase === 'installing' || phase === 'finished' ? phase : 'finished'))
|
|
497
563
|
}
|
|
498
564
|
|
|
565
|
+
|
|
499
566
|
function StatusNote({ tone = 'info', icon, children }) {
|
|
500
567
|
return h('div', { className: 'dshpu-note', 'data-tone': tone },
|
|
501
568
|
icon,
|
|
@@ -503,9 +570,46 @@ window.__ModuleLoader__.load({
|
|
|
503
570
|
)
|
|
504
571
|
}
|
|
505
572
|
|
|
506
|
-
|
|
573
|
+
/**
|
|
574
|
+
* The one place a restart is offered. It stays visible for as long as the
|
|
575
|
+
* Host reports a pending restart, so `稍后` (closing the dialog) does not
|
|
576
|
+
* silently drop the requirement.
|
|
577
|
+
*/
|
|
578
|
+
function RestartBanner({ visible, count, blocked, restarting, errorText, retryBusy, onRestart, onRetryFailed }) {
|
|
579
|
+
if (visible !== true) return null
|
|
580
|
+
return h('div', { className: 'dshpu-banner' },
|
|
581
|
+
h('div', {
|
|
582
|
+
className: 'dshpu-restartBar',
|
|
583
|
+
role: 'status',
|
|
584
|
+
'data-blocked': blocked === true ? 'true' : undefined,
|
|
585
|
+
},
|
|
586
|
+
h(blocked === true ? UI.IconWarningOutlineMedium : UI.IconRefreshOutlineRegular, { size: 16 }),
|
|
587
|
+
h('div', { className: 'dshpu-restartText' },
|
|
588
|
+
blocked === true ? t('restart.bannerBlocked') : t('restart.banner', { count }),
|
|
589
|
+
errorText === null || errorText === undefined
|
|
590
|
+
? null
|
|
591
|
+
: h('div', { className: 'dshpu-restartError' }, errorText)),
|
|
592
|
+
blocked === true
|
|
593
|
+
? onRetryFailed === undefined
|
|
594
|
+
? null
|
|
595
|
+
: h(UI.Button, {
|
|
596
|
+
variant: 'outline',
|
|
597
|
+
disabled: retryBusy === true,
|
|
598
|
+
onClick: onRetryFailed,
|
|
599
|
+
}, retryBusy === true ? t('done.retryBusy') : t('done.retryFailed'))
|
|
600
|
+
: h(UI.Button, {
|
|
601
|
+
variant: 'primary',
|
|
602
|
+
disabled: restarting === true,
|
|
603
|
+
onClick: onRestart,
|
|
604
|
+
}, restarting === true ? t('done.restarting') : t('done.restartButton')),
|
|
605
|
+
),
|
|
606
|
+
)
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function UpdateRow({ name, description, from, to, disabled, status, tone, showCheckbox, checked, onToggle, bootCritical, dependents, self }) {
|
|
507
610
|
const risks = []
|
|
508
|
-
if (
|
|
611
|
+
if (self === true) risks.push(t('risk.self'))
|
|
612
|
+
else if (bootCritical === true) risks.push(t('risk.boot'))
|
|
509
613
|
if ((dependents?.length ?? 0) > 0) risks.push(t('risk.provider', { count: dependents.length }))
|
|
510
614
|
return h('li', { className: 'dshpu-row' },
|
|
511
615
|
showCheckbox
|
|
@@ -531,7 +635,7 @@ window.__ModuleLoader__.load({
|
|
|
531
635
|
)
|
|
532
636
|
}
|
|
533
637
|
|
|
534
|
-
function ProgressView({ job, refresh, retryFailed, retryBusy, restartApp, restarting, restartError }) {
|
|
638
|
+
function ProgressView({ job, refresh, retryFailed, retryBusy, restartApp, restarting, restartError, onBack }) {
|
|
535
639
|
const [, setTick] = useState(0)
|
|
536
640
|
const waiting = job.state === 'queued' || job.state === 'starting'
|
|
537
641
|
const needsReload = refresh?.needsReload === true
|
|
@@ -574,16 +678,12 @@ window.__ModuleLoader__.load({
|
|
|
574
678
|
const rollbackText = unreconciled?.rollback == null
|
|
575
679
|
? ''
|
|
576
680
|
: ' ' + (unreconciled.rollback.ok === true ? t('done.rollbackOk') : t('done.rollbackFailed'))
|
|
577
|
-
const retryButton = failures.length > 0
|
|
578
|
-
? h('button', {
|
|
579
|
-
type: 'button',
|
|
580
|
-
className: 'dshpu-link',
|
|
581
|
-
disabled: retryBusy === true,
|
|
582
|
-
onClick: () => { void retryFailed?.() },
|
|
583
|
-
}, retryBusy === true ? t('done.retryBusy') : t('done.retryFailed'))
|
|
584
|
-
: null
|
|
585
681
|
|
|
586
682
|
return h(React.Fragment, null,
|
|
683
|
+
onBack === undefined
|
|
684
|
+
? null
|
|
685
|
+
: h('div', { className: 'dshpu-back' },
|
|
686
|
+
h('button', { type: 'button', className: 'dshpu-link', onClick: onBack }, t('results.back'))),
|
|
587
687
|
waiting
|
|
588
688
|
? h(StatusNote, { tone: 'info', icon: h(UI.IconClockOutlineRegular, { size: 16 }) }, phaseText)
|
|
589
689
|
: h('div', { className: 'dshpu-progress' },
|
|
@@ -639,8 +739,7 @@ window.__ModuleLoader__.load({
|
|
|
639
739
|
),
|
|
640
740
|
job.state === 'failed' && failureText !== null
|
|
641
741
|
? h(StatusNote, { tone: 'error', icon: h(UI.IconWarningOutlineMedium, { size: 16 }) },
|
|
642
|
-
failureText + rollbackText + ' ' + t('done.unreconciled')
|
|
643
|
-
retryButton)
|
|
742
|
+
failureText + rollbackText + ' ' + t('done.unreconciled'))
|
|
644
743
|
: null,
|
|
645
744
|
job.state === 'done' && failures.length === 0
|
|
646
745
|
? h(StatusNote, { tone: 'success', icon: h(UI.IconCheckCircleOutlineRegular, { size: 16 }) },
|
|
@@ -648,26 +747,12 @@ window.__ModuleLoader__.load({
|
|
|
648
747
|
: null,
|
|
649
748
|
job.state === 'done' && failures.length > 0
|
|
650
749
|
? h(StatusNote, { tone: 'warn', icon: h(UI.IconWarningOutlineMedium, { size: 16 }) },
|
|
651
|
-
t('done.partial', { updated: successes.length, failed: failures.length }) + ' ' + t('done.retryHint')
|
|
652
|
-
retryButton)
|
|
750
|
+
t('done.partial', { updated: successes.length, failed: failures.length }) + ' ' + t('done.retryHint'))
|
|
653
751
|
: null,
|
|
654
752
|
skipped.length > 0
|
|
655
753
|
? h(StatusNote, { tone: 'info', icon: h(UI.IconInfoOutlineRegular, { size: 16 }) },
|
|
656
754
|
t('done.skipped', { count: skipped.length }))
|
|
657
755
|
: null,
|
|
658
|
-
job.state === 'done' && failures.length === 0 && job.restartRequired === true
|
|
659
|
-
? h(StatusNote, { tone: 'info', icon: h(UI.IconInfoOutlineRegular, { size: 16 }) },
|
|
660
|
-
t('done.restart'),
|
|
661
|
-
h('button', {
|
|
662
|
-
type: 'button',
|
|
663
|
-
className: 'dshpu-restart',
|
|
664
|
-
disabled: restarting === true,
|
|
665
|
-
onClick: () => { void restartApp?.() },
|
|
666
|
-
}, restarting === true ? t('done.restarting') : t('done.restartButton')),
|
|
667
|
-
restartError !== null && restartError !== undefined
|
|
668
|
-
? h('span', { className: 'dshpu-restartError' }, t('done.restartUnavailable'))
|
|
669
|
-
: null)
|
|
670
|
-
: null,
|
|
671
756
|
job.state === 'done' && refresh?.reloaded === true
|
|
672
757
|
? h(StatusNote, { tone: 'info', icon: h(UI.IconRefreshOutlineRegular, { size: 16 }) }, t('refresh.done'))
|
|
673
758
|
: null,
|
|
@@ -696,14 +781,30 @@ window.__ModuleLoader__.load({
|
|
|
696
781
|
)
|
|
697
782
|
}
|
|
698
783
|
|
|
699
|
-
function ListView({ state, updates, selected, toggle, busy, queueOffer, desktopBlocked, desktopPhase }) {
|
|
784
|
+
function ListView({ state, updates, selected, toggle, busy, queueOffer, desktopBlocked, desktopPhase, lastJob, onShowResults }) {
|
|
700
785
|
const snapshot = state.snapshot
|
|
786
|
+
const lastResults = lastJob?.results ?? []
|
|
787
|
+
const lastOk = lastResults.filter((entry) => entry.ok === true).length
|
|
788
|
+
const lastFailed = lastResults.filter((entry) => entry.ok !== true && entry.skipped !== true).length
|
|
701
789
|
const checking = state.checking || snapshot?.checking === true
|
|
702
790
|
const checkedAt = snapshot?.checkedAt
|
|
703
791
|
const risky = (item) => item.bootCritical === true || (item.dependents?.length ?? 0) > 0
|
|
704
|
-
const riskySelected = updates.filter((item) => selected.has(item.name) && risky(item))
|
|
705
|
-
const riskyUnselected = updates.filter((item) => !selected.has(item.name) && risky(item))
|
|
792
|
+
const riskySelected = updates.filter((item) => selected.has(item.name) && item.self !== true && risky(item))
|
|
793
|
+
const riskyUnselected = updates.filter((item) => !selected.has(item.name) && item.self !== true && risky(item))
|
|
794
|
+
const selfItems = updates.filter((item) => item.self === true)
|
|
795
|
+
const selfSelected = selfItems.some((item) => selected.has(item.name))
|
|
796
|
+
const selfMixed = selfSelected && selected.size > 1
|
|
706
797
|
return h('div', { className: 'dshpu-body' },
|
|
798
|
+
lastJob === null || lastJob === undefined
|
|
799
|
+
? null
|
|
800
|
+
: h('div', { className: 'dshpu-lastBatch' },
|
|
801
|
+
h('span', null,
|
|
802
|
+
lastOk === 0 && lastFailed === 0
|
|
803
|
+
? t('results.summaryEmpty')
|
|
804
|
+
: lastFailed > 0
|
|
805
|
+
? t('results.summary', { updated: lastOk, failed: lastFailed })
|
|
806
|
+
: t('results.summaryClean', { updated: lastOk })),
|
|
807
|
+
h('button', { type: 'button', className: 'dshpu-link', onClick: onShowResults }, t('results.show'))),
|
|
707
808
|
h('div', { className: 'dshpu-summary' },
|
|
708
809
|
h('div', { className: 'dshpu-summaryText' },
|
|
709
810
|
updates.length > 0 ? t('list.summary', { count: updates.length }) : t('list.empty'),
|
|
@@ -735,6 +836,10 @@ window.__ModuleLoader__.load({
|
|
|
735
836
|
? h(StatusNote, { tone: 'warn', icon: h(UI.IconWarningOutlineMedium, { size: 16 }) },
|
|
736
837
|
t('risk.warning'))
|
|
737
838
|
: null,
|
|
839
|
+
selfItems.length > 0
|
|
840
|
+
? h(StatusNote, { tone: selfMixed === true ? 'warn' : 'info', icon: selfMixed === true ? h(UI.IconWarningOutlineMedium, { size: 16 }) : h(UI.IconInfoOutlineRegular, { size: 16 }) },
|
|
841
|
+
selfMixed === true ? t('self.alone') : t('self.note', { name: selfItems[0].name }))
|
|
842
|
+
: null,
|
|
738
843
|
updates.length > 0
|
|
739
844
|
? h('ul', { className: 'dshpu-list' },
|
|
740
845
|
updates.map((item) => h(UpdateRow, {
|
|
@@ -751,6 +856,7 @@ window.__ModuleLoader__.load({
|
|
|
751
856
|
tone: 'idle',
|
|
752
857
|
bootCritical: item.bootCritical,
|
|
753
858
|
dependents: item.dependents,
|
|
859
|
+
self: item.self === true,
|
|
754
860
|
})),
|
|
755
861
|
)
|
|
756
862
|
: null,
|
|
@@ -787,21 +893,41 @@ window.__ModuleLoader__.load({
|
|
|
787
893
|
const state = useStoreValue()
|
|
788
894
|
const snapshot = state.snapshot
|
|
789
895
|
const job = snapshot?.job ?? null
|
|
790
|
-
const jobState = job?.state
|
|
791
|
-
const showJob = job !== null && (['queued', 'starting', 'running'].includes(jobState) || (job.results?.length ?? 0) > 0)
|
|
792
896
|
const checking = state.checking || snapshot?.checking === true
|
|
793
897
|
const updates = snapshot?.updates ?? []
|
|
794
898
|
const namesKey = updates.map((item) => item.name).join('|')
|
|
795
899
|
const desktopPhase = snapshot?.desktopUpdate?.phase
|
|
796
900
|
const desktopBlocked = typeof desktopPhase === 'string'
|
|
797
901
|
&& ['available', 'downloading', 'verifying', 'installing', 'ready'].includes(desktopPhase)
|
|
902
|
+
const restart = resolveRestart(snapshot)
|
|
798
903
|
const [selected, setSelected] = useState(() => new Set())
|
|
799
904
|
const [busy, setBusy] = useState(false)
|
|
800
905
|
const [actionError, setActionError] = useState(null)
|
|
801
906
|
const [queueOffer, setQueueOffer] = useState(false)
|
|
907
|
+
// A finished batch is reachable on demand; the dialog itself always
|
|
908
|
+
// opens on the newest state so a fresh update list is never hidden
|
|
909
|
+
// behind the previous batch's progress view.
|
|
910
|
+
const [resultsView, setResultsView] = useState(false)
|
|
911
|
+
const wasOpen = useRef(open === true)
|
|
912
|
+
const view = resolvePanelView(job, resultsView)
|
|
913
|
+
const activeJob = view.active
|
|
914
|
+
const showJob = view.showJob
|
|
915
|
+
const finishedJob = view.finished
|
|
916
|
+
const failedResults = (job?.results ?? []).filter((entry) => entry.ok !== true && entry.skipped !== true)
|
|
802
917
|
|
|
803
918
|
useLocaleTick()
|
|
804
919
|
|
|
920
|
+
useEffect(() => {
|
|
921
|
+
if (open === true && wasOpen.current !== true) setResultsView(activeJob === true)
|
|
922
|
+
wasOpen.current = open === true
|
|
923
|
+
}, [open])
|
|
924
|
+
|
|
925
|
+
// Starting a batch from this dialog keeps the progress view selected
|
|
926
|
+
// once it finishes, so the result is shown instead of snapping away.
|
|
927
|
+
useEffect(() => {
|
|
928
|
+
if (activeJob === true) setResultsView(true)
|
|
929
|
+
}, [activeJob, job?.id])
|
|
930
|
+
|
|
805
931
|
useEffect(() => {
|
|
806
932
|
if (showJob) return
|
|
807
933
|
// Boot-critical plugins and providers other plugins inject are left
|
|
@@ -818,15 +944,31 @@ window.__ModuleLoader__.load({
|
|
|
818
944
|
}, [open])
|
|
819
945
|
|
|
820
946
|
function toggle(name, checked) {
|
|
947
|
+
// The update center is exclusive by construction: checking it clears
|
|
948
|
+
// the batch, and picking any other plugin clears it again.
|
|
949
|
+
const selfRow = updates.find((item) => item.self === true)
|
|
950
|
+
const isSelf = selfRow !== undefined && selfRow.name === name
|
|
821
951
|
setSelected((current) => {
|
|
822
952
|
const next = new Set(current)
|
|
823
|
-
if (checked)
|
|
824
|
-
|
|
953
|
+
if (checked) {
|
|
954
|
+
if (isSelf) next.clear()
|
|
955
|
+
else if (selfRow !== undefined) next.delete(selfRow.name)
|
|
956
|
+
next.add(name)
|
|
957
|
+
} else {
|
|
958
|
+
next.delete(name)
|
|
959
|
+
}
|
|
825
960
|
return next
|
|
826
961
|
})
|
|
827
962
|
}
|
|
828
963
|
|
|
829
964
|
async function submit(waitForIdle) {
|
|
965
|
+
// The update center cannot ride along with a batch: refuse locally
|
|
966
|
+
// instead of letting the Host reject the whole selection.
|
|
967
|
+
const selfSelected = updates.some((item) => item.self === true && selected.has(item.name))
|
|
968
|
+
if (selfSelected && selected.size > 1) {
|
|
969
|
+
setActionError('self-update-alone')
|
|
970
|
+
return
|
|
971
|
+
}
|
|
830
972
|
const names = [...selected]
|
|
831
973
|
if (names.length === 0) return
|
|
832
974
|
setBusy(true)
|
|
@@ -847,18 +989,47 @@ window.__ModuleLoader__.load({
|
|
|
847
989
|
}
|
|
848
990
|
}
|
|
849
991
|
|
|
992
|
+
// Closing the dialog only hides it: the finished job and the restart
|
|
993
|
+
// notice stay on the Host, so the next open does not lose them.
|
|
850
994
|
const handleClose = () => {
|
|
851
|
-
if (job !== null && !['running', 'queued', 'starting'].includes(job.state)) void dismissJob()
|
|
852
995
|
onClose()
|
|
853
996
|
}
|
|
854
997
|
|
|
855
998
|
const loading = snapshot === null || snapshot === undefined || (checking && updates.length === 0)
|
|
856
999
|
let body
|
|
857
|
-
if (showJob)
|
|
858
|
-
|
|
859
|
-
|
|
1000
|
+
if (showJob) {
|
|
1001
|
+
body = h(ProgressView, {
|
|
1002
|
+
job,
|
|
1003
|
+
refresh,
|
|
1004
|
+
retryFailed,
|
|
1005
|
+
retryBusy,
|
|
1006
|
+
restartApp,
|
|
1007
|
+
restarting,
|
|
1008
|
+
restartError,
|
|
1009
|
+
onBack: finishedJob === true ? () => setResultsView(false) : undefined,
|
|
1010
|
+
})
|
|
1011
|
+
} else if (loading) {
|
|
1012
|
+
body = h(EmptyOrLoading, { state })
|
|
1013
|
+
} else {
|
|
1014
|
+
body = h(ListView, {
|
|
1015
|
+
state,
|
|
1016
|
+
updates,
|
|
1017
|
+
selected,
|
|
1018
|
+
toggle,
|
|
1019
|
+
busy,
|
|
1020
|
+
queueOffer,
|
|
1021
|
+
desktopBlocked,
|
|
1022
|
+
desktopPhase,
|
|
1023
|
+
lastJob: finishedJob === true ? job : null,
|
|
1024
|
+
onShowResults: () => setResultsView(true),
|
|
1025
|
+
})
|
|
1026
|
+
}
|
|
860
1027
|
|
|
861
1028
|
const queueWaiting = showJob && (job.state === 'queued' || job.state === 'starting')
|
|
1029
|
+
const canRetry = showJob && activeJob !== true && failedResults.length > 0
|
|
1030
|
+
const restartErrorText = restartError === null || restartError === undefined
|
|
1031
|
+
? null
|
|
1032
|
+
: restartError === 'restart-timeout' ? t('done.restartTimeout') : t('done.restartUnavailable')
|
|
862
1033
|
const footer = h('div', { className: 'dshpu-actions' },
|
|
863
1034
|
actionError !== null
|
|
864
1035
|
? h('div', { className: 'dshpu-footerError' }, message(actionError))
|
|
@@ -869,13 +1040,20 @@ window.__ModuleLoader__.load({
|
|
|
869
1040
|
queueWaiting
|
|
870
1041
|
? h(UI.Button, { variant: 'outline', onClick: () => { void cancelQueued() } }, t('queue.cancel'))
|
|
871
1042
|
: null,
|
|
872
|
-
showJob &&
|
|
873
|
-
? h(UI.Button, { variant: '
|
|
1043
|
+
showJob && activeJob !== true
|
|
1044
|
+
? h(UI.Button, { variant: 'outline', onClick: handleClose }, t('panel.done'))
|
|
874
1045
|
: null,
|
|
875
|
-
|
|
876
|
-
? h(UI.Button, {
|
|
1046
|
+
canRetry
|
|
1047
|
+
? h(UI.Button, {
|
|
1048
|
+
variant: 'primary',
|
|
1049
|
+
disabled: retryBusy === true,
|
|
1050
|
+
onClick: () => { void retryFailed() },
|
|
1051
|
+
}, retryBusy === true ? t('done.retryBusy') : t('done.retryFailed'))
|
|
1052
|
+
: null,
|
|
1053
|
+
showJob !== true
|
|
1054
|
+
? h(UI.Button, { variant: 'outline', onClick: handleClose }, t('panel.close'))
|
|
877
1055
|
: null,
|
|
878
|
-
|
|
1056
|
+
showJob !== true && updates.length > 0
|
|
879
1057
|
? h(UI.Button, {
|
|
880
1058
|
variant: 'primary',
|
|
881
1059
|
disabled: busy || checking || selected.size === 0 || desktopBlocked,
|
|
@@ -884,8 +1062,19 @@ window.__ModuleLoader__.load({
|
|
|
884
1062
|
: null,
|
|
885
1063
|
)
|
|
886
1064
|
|
|
1065
|
+
const banner = h(RestartBanner, {
|
|
1066
|
+
visible: restart.pending === true && activeJob !== true,
|
|
1067
|
+
count: restart.count,
|
|
1068
|
+
blocked: restart.blocked,
|
|
1069
|
+
restarting,
|
|
1070
|
+
errorText: restartErrorText,
|
|
1071
|
+
onRestart: () => { void restartApp() },
|
|
1072
|
+
onRetryFailed: failedResults.length > 0 ? () => { void retryFailed() } : undefined,
|
|
1073
|
+
retryBusy,
|
|
1074
|
+
})
|
|
1075
|
+
|
|
887
1076
|
const title = showJob
|
|
888
|
-
? queueWaiting ? t('queue.title') : t('panel.progressTitle')
|
|
1077
|
+
? queueWaiting ? t('queue.title') : activeJob ? t('panel.progressTitle') : t('panel.resultsTitle')
|
|
889
1078
|
: t('panel.title')
|
|
890
1079
|
|
|
891
1080
|
return h(UI.Modal, {
|
|
@@ -898,6 +1087,7 @@ window.__ModuleLoader__.load({
|
|
|
898
1087
|
contentClassName: 'dshpu-modalContent',
|
|
899
1088
|
},
|
|
900
1089
|
h('style', null, STYLE),
|
|
1090
|
+
banner,
|
|
901
1091
|
body,
|
|
902
1092
|
)
|
|
903
1093
|
}
|
|
@@ -1069,6 +1259,10 @@ window.__ModuleLoader__.load({
|
|
|
1069
1259
|
const waiting = phase === 'queued' || phase === 'starting'
|
|
1070
1260
|
const count = updates.length
|
|
1071
1261
|
const updateVisible = open || running || waiting || count > 0
|
|
1262
|
+
const restart = resolveRestart(snapshot)
|
|
1263
|
+
// Driven by Host state, not by the dialog: the restart chip stays in the
|
|
1264
|
+
// account row after the dialog is closed, until DSH actually restarts.
|
|
1265
|
+
const restartVisible = restart.pending === true
|
|
1072
1266
|
const residue = state.residue
|
|
1073
1267
|
const residueCount = residue?.items?.length ?? 0
|
|
1074
1268
|
const residueVisible = openResidue || residueCount > 0
|
|
@@ -1098,6 +1292,15 @@ window.__ModuleLoader__.load({
|
|
|
1098
1292
|
setRestartError(null)
|
|
1099
1293
|
}, [job?.id])
|
|
1100
1294
|
|
|
1295
|
+
useEffect(() => {
|
|
1296
|
+
if (restarting !== true) return
|
|
1297
|
+
const timer = setTimeout(() => {
|
|
1298
|
+
setRestarting(false)
|
|
1299
|
+
setRestartError('restart-timeout')
|
|
1300
|
+
}, 6000)
|
|
1301
|
+
return () => clearTimeout(timer)
|
|
1302
|
+
}, [restarting])
|
|
1303
|
+
|
|
1101
1304
|
const retryFailed = async () => {
|
|
1102
1305
|
if (retryBusy === true || job === null) return
|
|
1103
1306
|
const names = (job.results ?? [])
|
|
@@ -1170,10 +1373,29 @@ window.__ModuleLoader__.load({
|
|
|
1170
1373
|
? t('action.tooltip', { count })
|
|
1171
1374
|
: t('action.label')
|
|
1172
1375
|
const residueLabel = t('residue.tooltip', { count: residueCount })
|
|
1376
|
+
const restartLabel = t(restart.blocked === true ? 'restart.tooltipBlocked' : 'restart.tooltip')
|
|
1173
1377
|
|
|
1174
|
-
const chips = host !== null && (updateVisible || residueVisible)
|
|
1378
|
+
const chips = host !== null && (updateVisible || residueVisible || restartVisible)
|
|
1175
1379
|
? createPortal(
|
|
1176
1380
|
h(React.Fragment, null,
|
|
1381
|
+
restartVisible
|
|
1382
|
+
? h(UI.Tooltip, { label: restartLabel, side: 'top', align: 'end' },
|
|
1383
|
+
h('button', {
|
|
1384
|
+
type: 'button',
|
|
1385
|
+
className: 'dshpu-chip is-restart',
|
|
1386
|
+
'data-blocked': restart.blocked === true ? 'true' : undefined,
|
|
1387
|
+
'aria-label': restartLabel,
|
|
1388
|
+
onClick: () => {
|
|
1389
|
+
setOpen(true)
|
|
1390
|
+
void refresh()
|
|
1391
|
+
},
|
|
1392
|
+
},
|
|
1393
|
+
h('span', { className: 'dshpu-chipIcon' },
|
|
1394
|
+
restart.blocked === true
|
|
1395
|
+
? h(UI.IconWarningOutlineMedium, { size: 14 })
|
|
1396
|
+
: h(UI.IconRefreshOutlineRegular, { size: 14 })),
|
|
1397
|
+
))
|
|
1398
|
+
: null,
|
|
1177
1399
|
updateVisible
|
|
1178
1400
|
? h(UI.Tooltip, { label: updateLabel, side: 'top', align: 'end' },
|
|
1179
1401
|
h('button', {
|
|
@@ -1273,6 +1495,12 @@ window.__ModuleLoader__.load({
|
|
|
1273
1495
|
}, 'dsh-plugin-update-center: desktop update gate')
|
|
1274
1496
|
}
|
|
1275
1497
|
|
|
1276
|
-
return {
|
|
1498
|
+
return {
|
|
1499
|
+
inject: ['slots', 'locale'],
|
|
1500
|
+
apply,
|
|
1501
|
+
// Pure view decisions, exported so the Node test can verify them without
|
|
1502
|
+
// a browser renderer.
|
|
1503
|
+
__testing: { resolvePanelView, resolveRestart },
|
|
1504
|
+
}
|
|
1277
1505
|
},
|
|
1278
1506
|
})
|
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* delegated to the official `pluginManager`; nothing here writes the profile.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { dirname } from 'node:path'
|
|
9
|
+
import { dirname, join } from 'node:path'
|
|
10
10
|
import { createBackup } from './lib/backup.js'
|
|
11
11
|
import { createEngine } from './lib/engine.js'
|
|
12
12
|
import { createHandler, ROUTE } from './lib/http.js'
|
|
@@ -81,7 +81,11 @@ export function apply(ctx) {
|
|
|
81
81
|
const residue = profileDir !== undefined
|
|
82
82
|
? createResidueService({ profileDir, homeDir, manager, backup })
|
|
83
83
|
: null
|
|
84
|
-
const restart = createRestartService(
|
|
84
|
+
const restart = createRestartService({
|
|
85
|
+
logPath: homeDir === undefined
|
|
86
|
+
? join(process.env.TEMP ?? '.', 'dsh-plugin-update-center-restart.log')
|
|
87
|
+
: join(homeDir, 'plugin-updates', 'restart.log'),
|
|
88
|
+
})
|
|
85
89
|
|
|
86
90
|
const engine = createEngine({
|
|
87
91
|
manager,
|
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
|
}
|
|
@@ -121,7 +122,7 @@ export function createHandler(engine, residue = null, restart = null) {
|
|
|
121
122
|
if (restart === null || typeof restart.restart !== 'function') {
|
|
122
123
|
return respond({ ok: false, code: 'restart-unavailable' }, 501)
|
|
123
124
|
}
|
|
124
|
-
const result = restart.restart()
|
|
125
|
+
const result = await restart.restart()
|
|
125
126
|
if (result?.ok !== true) {
|
|
126
127
|
return respond({ ok: false, code: result?.code ?? 'restart-unavailable' }, 501)
|
|
127
128
|
}
|
package/lib/restart.js
CHANGED
|
@@ -3,45 +3,73 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A page reload only replaces the renderer; the DSH Host keeps running the old
|
|
5
5
|
* plugin code, which is exactly how the client/Host mismatch crash happens.
|
|
6
|
-
* The desktop app exposes no restart bridge to plugins,
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* The desktop app exposes no restart bridge to plugins, and a PowerShell child
|
|
7
|
+
* of the Host can be killed together with its process tree. Instead the Host
|
|
8
|
+
* writes a small batch file and opens its VBS launcher through Explorer: the
|
|
9
|
+
* launcher lives outside the DSH process tree, waits, kills the whole app,
|
|
10
|
+
* waits again, and starts the same executable.
|
|
9
11
|
*/
|
|
10
12
|
|
|
11
13
|
import { spawn } from 'node:child_process'
|
|
12
|
-
import { existsSync } from 'node:fs'
|
|
13
|
-
import { basename } from 'node:path'
|
|
14
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
15
|
+
import { basename, dirname, join } from 'node:path'
|
|
14
16
|
|
|
15
17
|
const APP_EXE = /^DeepSeek Harness\.exe$/i
|
|
16
18
|
|
|
17
|
-
/** Quote
|
|
18
|
-
function
|
|
19
|
-
return `
|
|
19
|
+
/** Quote a path for a cmd.exe line. */
|
|
20
|
+
function quoteCmd(value) {
|
|
21
|
+
return `"${String(value).replaceAll('"', '""')}"`
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
+
/** Quote a path as a VBScript string literal. */
|
|
25
|
+
function quoteVbs(value) {
|
|
26
|
+
return `"${String(value).replaceAll('"', '""')}"`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Build the batch that stops and relaunches the desktop app. */
|
|
30
|
+
export function buildRestartBatch(execPath, logPath = null) {
|
|
31
|
+
const log = logPath === null ? null : quoteCmd(logPath)
|
|
32
|
+
const logLine = (message) => log === null
|
|
33
|
+
? `echo %DATE% %TIME% ${message}`
|
|
34
|
+
: `echo %DATE% %TIME% ${message} >> ${log}`
|
|
35
|
+
return [
|
|
36
|
+
'@echo off',
|
|
37
|
+
'ping -n 2 127.0.0.1 >nul',
|
|
38
|
+
logLine('restart start'),
|
|
39
|
+
`taskkill /IM "DeepSeek Harness.exe" /T /F >> ${log ?? 'nul'} 2>&1`,
|
|
40
|
+
logLine('stopped'),
|
|
41
|
+
'ping -n 3 127.0.0.1 >nul',
|
|
42
|
+
`start "" ${quoteCmd(execPath)}`,
|
|
43
|
+
logLine('relaunched'),
|
|
44
|
+
'',
|
|
45
|
+
].join('\r\n')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Build a hidden VBS launcher for the batch. */
|
|
49
|
+
export function buildRestartLauncher(batchPath) {
|
|
24
50
|
return [
|
|
25
|
-
'
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
'Start-Sleep -Milliseconds 1200',
|
|
29
|
-
'Start-Process -FilePath $exe',
|
|
51
|
+
'Set sh = CreateObject("WScript.Shell")',
|
|
52
|
+
`sh.Run "cmd.exe /c " & Chr(34) & ${quoteVbs(batchPath)} & Chr(34), 0, False`,
|
|
53
|
+
'',
|
|
30
54
|
].join('\r\n')
|
|
31
55
|
}
|
|
32
56
|
|
|
33
57
|
/**
|
|
34
58
|
* @param {object} [options]
|
|
35
|
-
* @param {string} [options.execPath] desktop executable
|
|
59
|
+
* @param {string} [options.execPath] desktop executable
|
|
36
60
|
* @param {NodeJS.Platform} [options.platform]
|
|
37
61
|
* @param {Function} [options.spawn]
|
|
38
62
|
* @param {Function} [options.exists]
|
|
63
|
+
* @param {string | null} [options.logPath]
|
|
64
|
+
* @param {object} [options.environment]
|
|
39
65
|
*/
|
|
40
66
|
export function createRestartService({
|
|
41
67
|
execPath = process.execPath,
|
|
42
68
|
platform = process.platform,
|
|
43
69
|
spawn: spawnChild = spawn,
|
|
44
70
|
exists = existsSync,
|
|
71
|
+
logPath = null,
|
|
72
|
+
environment = process.env,
|
|
45
73
|
} = {}) {
|
|
46
74
|
function canRestart() {
|
|
47
75
|
if (platform !== 'win32') return false
|
|
@@ -53,24 +81,59 @@ export function createRestartService({
|
|
|
53
81
|
}
|
|
54
82
|
}
|
|
55
83
|
|
|
56
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Write the batch + launcher, then ask Explorer to run the launcher. Resolve
|
|
86
|
+
* only after Explorer spawned so a failure reaches the client instead of
|
|
87
|
+
* leaving the UI on "restarting" forever.
|
|
88
|
+
*/
|
|
89
|
+
async function restart() {
|
|
57
90
|
if (!canRestart()) return { ok: false, code: 'restart-unavailable' }
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
91
|
+
const root = environment.SystemRoot ?? environment.windir ?? 'C:\\Windows'
|
|
92
|
+
const explorer = join(root, 'explorer.exe')
|
|
93
|
+
if (!exists(explorer)) return { ok: false, code: 'restart-unavailable' }
|
|
94
|
+
const dir = join(environment.TEMP ?? environment.TMP ?? '.', 'dsh-plugin-update-center-restart')
|
|
95
|
+
const stamp = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
|
96
|
+
const batchPath = join(dir, `restart-${stamp}.cmd`)
|
|
97
|
+
const launcherPath = join(dir, `restart-${stamp}.vbs`)
|
|
98
|
+
const log = logPath === null ? join(dir, 'restart.log') : logPath
|
|
99
|
+
try {
|
|
100
|
+
mkdirSync(dir, { recursive: true })
|
|
101
|
+
mkdirSync(dirname(log), { recursive: true })
|
|
102
|
+
writeFileSync(batchPath, buildRestartBatch(execPath, log), 'utf8')
|
|
103
|
+
writeFileSync(launcherPath, buildRestartLauncher(batchPath), 'utf8')
|
|
104
|
+
} catch (error) {
|
|
105
|
+
return { ok: false, code: 'restart-unavailable', error: String(error?.message ?? error) }
|
|
106
|
+
}
|
|
107
|
+
return new Promise((resolve) => {
|
|
108
|
+
let settled = false
|
|
109
|
+
const finish = (value) => {
|
|
110
|
+
if (settled) return
|
|
111
|
+
settled = true
|
|
112
|
+
resolve(value)
|
|
113
|
+
}
|
|
114
|
+
let child
|
|
115
|
+
try {
|
|
116
|
+
child = spawnChild(explorer, [launcherPath], {
|
|
117
|
+
detached: true,
|
|
118
|
+
stdio: 'ignore',
|
|
119
|
+
windowsHide: true,
|
|
120
|
+
})
|
|
121
|
+
} catch (error) {
|
|
122
|
+
finish({ ok: false, code: 'restart-unavailable', error: String(error?.message ?? error) })
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
child.once?.('error', (error) => {
|
|
126
|
+
finish({ ok: false, code: 'restart-unavailable', error: String(error?.message ?? error) })
|
|
127
|
+
})
|
|
128
|
+
child.once?.('spawn', () => {
|
|
129
|
+
child.unref?.()
|
|
130
|
+
finish({ ok: true })
|
|
131
|
+
})
|
|
132
|
+
if (typeof child.once !== 'function') {
|
|
133
|
+
child.unref?.()
|
|
134
|
+
finish({ ok: true })
|
|
135
|
+
}
|
|
71
136
|
})
|
|
72
|
-
child.unref?.()
|
|
73
|
-
return { ok: true }
|
|
74
137
|
}
|
|
75
138
|
|
|
76
139
|
return { canRestart, restart }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-update-center",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
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",
|