dsh-plugin-update-all 0.0.0-stage → 1.0.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/client.js ADDED
@@ -0,0 +1,786 @@
1
+ /**
2
+ * Update all — the Plugins page tab that checks every installed plugin for a
3
+ * compatible newer release and updates the outdated ones in one run.
4
+ *
5
+ * The tab registers into `plugins.tab`, so it takes a seat beside the page's own
6
+ * Installed tab and any other contributed tab. Everything it needs is already on
7
+ * the Host's `pluginManager` Remote: `listBundles` names the profile's
8
+ * dependencies, `listVersions` answers for one registry package, and
9
+ * `updateBundle` replaces one installed version. Updates run one after another
10
+ * because the Host serializes profile changes on its profile lock; each one
11
+ * names its own request id and follows the Host's
12
+ * `plugin-manager/update-state` steps.
13
+ *
14
+ * The factory stays free of side effects: everything it registers is created
15
+ * inside `apply` and disposed with the plugin's context.
16
+ */
17
+
18
+ window.__ModuleLoader__.load({
19
+ id: 'dsh-plugin-update-all',
20
+ factory(require) {
21
+ const React = require('react')
22
+ const h = React.createElement
23
+ const { useEffect, useSyncExternalStore } = React
24
+
25
+ /** This bundle's package name: updating itself would stop the tab running the update. */
26
+ const SELF = 'dsh-plugin-update-all'
27
+ /** The Client locale namespace this tab's copy is registered under. */
28
+ const NS = 'updateAll'
29
+ /** The tab's id inside `plugins.tab`; its place before the tabs others contribute. */
30
+ const TAB_ID = 'update-all'
31
+ const TAB_ORDER = -1
32
+
33
+ /** A snapshot's empty list, shared so an unchanged list keeps its identity. */
34
+ const EMPTY = Object.freeze([])
35
+
36
+ // ---------------------------------------------------------------------
37
+ // Copy
38
+ // ---------------------------------------------------------------------
39
+
40
+ /**
41
+ * Simplified Chinese copy, matching DSH's own `zh` dictionary so the tab reads like the page around it: 插件, 已安装,
42
+ * 发现, 刷新, 添加插件, 安装源, 检查于, 视图.
43
+ */
44
+ const ZH = {
45
+ tab: '更新',
46
+ intro: '检查所有已安装插件的可用新版本,并一次更新需要更新的插件。只处理从安装源安装的第三方插件。',
47
+ checkForUpdates: '检查更新',
48
+ recheck: '重新检查',
49
+ updateAll: '全部更新({count})',
50
+ readingInstalled: '正在读取插件…',
51
+ checking: '正在检查 {done}/{total}:{name}',
52
+ checkedAt: '检查于 {time}',
53
+ summaryLine: '{candidates} 个可更新 · {latest} 个已是最新 · {skipped} 个已跳过',
54
+ allLatest: '所有插件均为最新版本',
55
+ blockedCount: '{count} 个有新版本但无法更新',
56
+ blockedIncompatible: '需要 {peers}(当前 DSH {runtime})',
57
+ blockedNotInstallable: '新版本不是插件包、已弃用,或只有测试版',
58
+ skippedTitle: '{count} 个已跳过',
59
+ skippedGit: '以 Git 安装,请在「已安装」视图打开该插件页面更新',
60
+ skippedLocal: '以本地目录或压缩包安装,不从安装源更新',
61
+ skippedShipped: '由 DSH 安装提供,随 DSH 一并更新',
62
+ skippedOfficial: '官方插件,不从安装源更新',
63
+ skippedManaged: '由 DSH 管理,无法从这里更新',
64
+ skippedMissing: '找不到包文件',
65
+ skippedNoVersion: '读不到已安装版本',
66
+ skippedCheck: '查不到版本信息',
67
+ confirmTitle: '更新这 {count} 个插件?',
68
+ confirmBody: '更新会以新版本替换当前版本,期间插件可能短暂停止;安装失败时会保留或重新安装当前版本。',
69
+ confirmRun: '开始更新 {count} 个',
70
+ cancel: '取消',
71
+ stop: '停止后续',
72
+ stopping: '当前这项完成后停止…',
73
+ running: '正在更新 {index}/{total}:{name}',
74
+ stepChecking: '检查 {version}',
75
+ stepRemoving: '停止并移除 {version}',
76
+ stepInstalling: '安装 {version}',
77
+ stepRestoring: '重新安装 {version}',
78
+ waiting: '等待中',
79
+ outcomeApplied: '已更新',
80
+ outcomeRestart: '已更新到 {version},重启后生效',
81
+ outcomeFailed: '更新失败',
82
+ outcomeRestored: '更新失败,已恢复到 {version}',
83
+ outcomeBroken: '更新失败,插件当前未安装',
84
+ outcomeCheckRefused: '无法更新到 {version}',
85
+ outcomeRemoveFailed: '无法移除 {version}',
86
+ outcomeSkipped: '已跳过',
87
+ reloadHint: '有插件已更新:重新加载页面才会加载新版界面;标示「需重启」的项目要重启 DSH 才生效。',
88
+ errorTitle: '无法读取插件列表',
89
+ }
90
+
91
+ /** English copy, the fallback the locale service serves for other languages. */
92
+ const EN = {
93
+ tab: 'Updates',
94
+ intro: 'Check every installed plugin for a newer compatible release, then update the outdated ones in one run. Only third-party plugins installed from an install registry are updated.',
95
+ checkForUpdates: 'Check for updates',
96
+ recheck: 'Check again',
97
+ updateAll: 'Update all ({count})',
98
+ readingInstalled: 'Reading plugins…',
99
+ checking: 'Checking {done}/{total}: {name}',
100
+ checkedAt: 'Last checked at {time}',
101
+ summaryLine: '{candidates} to update · {latest} up to date · {skipped} skipped',
102
+ allLatest: 'All plugins are up to date',
103
+ blockedCount: '{count} with a newer release that cannot be installed',
104
+ blockedIncompatible: 'needs {peers} (running DSH {runtime})',
105
+ blockedNotInstallable: 'the newer release is not a bundle, is deprecated, or is a prerelease',
106
+ skippedTitle: '{count} skipped',
107
+ skippedGit: 'Installed from Git: open its page on the Installed tab to update it',
108
+ skippedLocal: 'Installed from a local folder or tarball: never updated from an install registry',
109
+ skippedShipped: 'Shipped by the DSH installation: updated with DSH',
110
+ skippedOfficial: 'An official plugin: not updated from an install registry',
111
+ skippedManaged: 'Managed by DSH: cannot be updated from here',
112
+ skippedMissing: 'Package files are missing',
113
+ skippedNoVersion: 'No installed version could be read',
114
+ skippedCheck: 'Version information is unavailable',
115
+ confirmTitle: 'Update {count} plugins?',
116
+ confirmBody: 'The update replaces the installed version with the new one, and the plugin may stop briefly. If the installation fails, the current version is kept or installed again.',
117
+ confirmRun: 'Update {count} plugins',
118
+ cancel: 'Cancel',
119
+ stop: 'Stop after this one',
120
+ stopping: 'Stopping after the current plugin…',
121
+ running: 'Updating {index}/{total}: {name}',
122
+ stepChecking: 'Check {version}',
123
+ stepRemoving: 'Stop and remove {version}',
124
+ stepInstalling: 'Install {version}',
125
+ stepRestoring: 'Install {version} again',
126
+ waiting: 'Waiting',
127
+ outcomeApplied: 'Updated',
128
+ outcomeRestart: 'Updated to {version}; takes effect after a restart',
129
+ outcomeFailed: 'Update failed',
130
+ outcomeRestored: 'Update failed; restored {version}',
131
+ outcomeBroken: 'Update failed; the plugin is not installed',
132
+ outcomeCheckRefused: 'Cannot update to {version}',
133
+ outcomeRemoveFailed: 'Could not remove {version}',
134
+ outcomeSkipped: 'Skipped',
135
+ reloadHint: 'Plugins were updated: reload this page to load their new interface. Rows that say restart need a DSH restart.',
136
+ errorTitle: 'The plugin list could not be read',
137
+ }
138
+
139
+ /** Why a profile dependency is left alone, as a locale key. */
140
+ const SKIP_KEYS = {
141
+ git: 'skippedGit',
142
+ local: 'skippedLocal',
143
+ shipped: 'skippedShipped',
144
+ official: 'skippedOfficial',
145
+ managed: 'skippedManaged',
146
+ missing: 'skippedMissing',
147
+ noVersion: 'skippedNoVersion',
148
+ check: 'skippedCheck',
149
+ }
150
+
151
+ // ---------------------------------------------------------------------
152
+ // Host facts
153
+ // ---------------------------------------------------------------------
154
+
155
+ /**
156
+ * Whether the running DSH version accepts a published version.
157
+ * @param version one published version.
158
+ * @returns true when it declares a bundle and needs no newer DSH.
159
+ */
160
+ function installable(version) {
161
+ return version.bundle === true && version.incompatible === undefined
162
+ }
163
+
164
+ /**
165
+ * The version an update would install: the newest listed version that declares a bundle, accepts the running DSH
166
+ * version, and is neither deprecated nor a prerelease.
167
+ * @param list the Host's answer for one package.
168
+ * @returns the target version, or undefined when none qualifies.
169
+ */
170
+ function updateCandidate(list) {
171
+ if (list === undefined || list.status !== 'listed') return undefined
172
+ return list.versions.find(version => installable(version) && version.deprecated === undefined && !version.prerelease)
173
+ }
174
+
175
+ /**
176
+ * Why a profile dependency cannot be updated from a registry.
177
+ * @param bundle one profile dependency as the Host lists it.
178
+ * @returns the reason, or undefined when `updateBundle` can replace it.
179
+ */
180
+ function skipReason(bundle) {
181
+ // `update` is absent for everything the Host will not replace here, so the specific fields decide the reason.
182
+ if (bundle.readOnlyReason !== undefined) return 'managed'
183
+ if (bundle.availability === 'missing') return 'missing'
184
+ if (bundle.update === 'git') return 'git'
185
+ if (bundle.update === 'registry') {
186
+ return bundle.version === undefined || bundle.version === '' ? 'noVersion' : undefined
187
+ }
188
+ if (bundle.availability === 'installation') return 'shipped'
189
+ if (bundle.official === true) return 'official'
190
+ return 'local'
191
+ }
192
+
193
+ /**
194
+ * A package's local display title, falling back to its technical name.
195
+ * @param bundle one bundle as the Host lists it.
196
+ * @param resolveText the Client locale service's localized-text resolver.
197
+ * @returns the title to show.
198
+ */
199
+ function titleOf(bundle, resolveText) {
200
+ const meta = bundle.meta
201
+ if (meta === undefined || meta.title === undefined) return bundle.name
202
+ try {
203
+ return resolveText(meta.title) || bundle.name
204
+ } catch {
205
+ return bundle.name
206
+ }
207
+ }
208
+
209
+ /** The DSH requirements an incompatible version states, as one phrase. */
210
+ function peersText(incompatible) {
211
+ const requirements = incompatible === undefined ? undefined : incompatible.requirements
212
+ if (requirements === undefined) return ''
213
+ return Object.entries(requirements).map(([name, range]) => `${name} ${range}`).join(', ')
214
+ }
215
+
216
+ /** A request id the Host names this update's progress by. */
217
+ function nextRequestId() {
218
+ const crypto = globalThis.crypto
219
+ if (crypto !== undefined && typeof crypto.randomUUID === 'function') return crypto.randomUUID()
220
+ return `update-all-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`
221
+ }
222
+
223
+ /** An unknown thrown value as a sentence. */
224
+ function messageOf(error) {
225
+ if (error instanceof Error) return error.message
226
+ return String(error)
227
+ }
228
+
229
+ /** A change's own words: what the Host reported, else its error code. */
230
+ function failureText(change) {
231
+ if (change === undefined || change.error === undefined) return ''
232
+ const { diagnostic, code } = change.error
233
+ return typeof diagnostic === 'string' && diagnostic !== '' ? diagnostic : String(code)
234
+ }
235
+
236
+ /**
237
+ * How one update ended, as a tone, a copy key, its parameters, a detail line, and whether the new version runs.
238
+ * @param result the Host's answer for one `updateBundle` call.
239
+ * @returns the row's presentation.
240
+ */
241
+ function describeUpdate(result) {
242
+ const undone = change => change !== undefined && (change.application === 'failed' || change.application === 'cancelled')
243
+ if (result.step === 'check') {
244
+ return { tone: 'error', key: 'outcomeCheckRefused', params: { version: result.to }, detail: failureText(result.result), updated: false }
245
+ }
246
+ if (result.step === 'remove') {
247
+ return { tone: 'error', key: 'outcomeRemoveFailed', params: { version: result.from }, detail: failureText(result.result), updated: false }
248
+ }
249
+ if (!undone(result.result)) {
250
+ return result.result.application === 'restart-required'
251
+ ? { tone: 'warn', key: 'outcomeRestart', params: { version: result.to }, detail: result.result.restartReason === undefined ? '' : String(result.result.restartReason), updated: true }
252
+ : { tone: 'success', key: 'outcomeApplied', params: {}, detail: '', updated: true }
253
+ }
254
+ // Without a reinstallation nothing was removed: the target was rolled back over the running version.
255
+ if (result.restore === undefined) {
256
+ return { tone: 'error', key: 'outcomeFailed', params: {}, detail: failureText(result.result), updated: false }
257
+ }
258
+ return undone(result.restore)
259
+ ? { tone: 'error', key: 'outcomeBroken', params: {}, detail: failureText(result.result), updated: false }
260
+ : { tone: 'error', key: 'outcomeRestored', params: { version: result.from }, detail: failureText(result.result), updated: false }
261
+ }
262
+
263
+ // ---------------------------------------------------------------------
264
+ // Controller
265
+ // ---------------------------------------------------------------------
266
+
267
+ /** The state before the tab's first read. */
268
+ function initialState() {
269
+ return Object.freeze({
270
+ phase: 'idle',
271
+ refreshing: false,
272
+ checked: 0,
273
+ total: 0,
274
+ current: null,
275
+ checkedAt: null,
276
+ error: null,
277
+ candidates: EMPTY,
278
+ latest: EMPTY,
279
+ blocked: EMPTY,
280
+ skipped: EMPTY,
281
+ run: null,
282
+ results: EMPTY,
283
+ stopping: false,
284
+ })
285
+ }
286
+
287
+ /**
288
+ * Create the tab's state, its check pass, and its serial update pass.
289
+ * @param remote the Client's Remote face, carrying `pluginManager`.
290
+ * @param resolveText the Client locale service's localized-text resolver.
291
+ * @returns the controller the tab renders from.
292
+ */
293
+ function createController(remote, resolveText) {
294
+ let snapshot = initialState()
295
+ const listeners = new Set()
296
+ let running = false
297
+ let requestId = null
298
+ let stopRequested = false
299
+ let disposed = false
300
+
301
+ function publish(next) {
302
+ if (disposed) return
303
+ snapshot = Object.freeze({ ...snapshot, ...next })
304
+ for (const listener of [...listeners]) listener()
305
+ }
306
+
307
+ /** Read every profile dependency and its newer versions. */
308
+ async function load(options) {
309
+ const quiet = options !== undefined && options.quiet === true
310
+ if (running || disposed) return
311
+ if (quiet) publish({ refreshing: true, error: null })
312
+ else publish({ ...initialState(), phase: 'checking' })
313
+
314
+ let bundles
315
+ try {
316
+ const answer = await remote.pluginManager.listBundles()
317
+ if (disposed) return
318
+ if (!answer.ok) {
319
+ publish({ phase: quiet ? snapshot.phase : 'error', refreshing: false, error: answer.error.message })
320
+ return
321
+ }
322
+ bundles = answer.value
323
+ } catch (error) {
324
+ if (disposed) return
325
+ publish({ phase: quiet ? snapshot.phase : 'error', refreshing: false, error: messageOf(error) })
326
+ return
327
+ }
328
+
329
+ const skipped = []
330
+ const subjects = []
331
+ for (const bundle of bundles) {
332
+ // Bundles the installation ships are not the profile's to reinstall.
333
+ if (bundle.name === SELF || bundle.installed !== true) continue
334
+ const title = titleOf(bundle, resolveText)
335
+ const reason = skipReason(bundle)
336
+ if (reason === undefined) subjects.push({ bundle, title })
337
+ else skipped.push({ name: bundle.name, title, reason })
338
+ }
339
+ publish({ total: subjects.length, skipped: [...skipped] })
340
+
341
+ const candidates = []
342
+ const latest = []
343
+ const blocked = []
344
+ for (let index = 0; index < subjects.length; index += 1) {
345
+ const { bundle, title } = subjects[index]
346
+ publish({ current: title, checked: index })
347
+ let list
348
+ try {
349
+ const answer = await remote.pluginManager.listVersions(bundle.name, {})
350
+ if (answer.ok) {
351
+ list = answer.value
352
+ if (list.status === 'refused') skipped.push({ name: bundle.name, title, reason: 'check', detail: list.reason })
353
+ } else {
354
+ skipped.push({ name: bundle.name, title, reason: 'check', detail: answer.error.message })
355
+ }
356
+ } catch (error) {
357
+ skipped.push({ name: bundle.name, title, reason: 'check', detail: messageOf(error) })
358
+ }
359
+ if (disposed) return
360
+ if (list === undefined || list.status !== 'listed') {
361
+ publish({ skipped: [...skipped] })
362
+ continue
363
+ }
364
+ const target = updateCandidate(list)
365
+ if (target !== undefined) {
366
+ candidates.push({ name: bundle.name, title, from: list.installed, to: target.version, registry: list.registry })
367
+ continue
368
+ }
369
+ if (list.versions.length === 0) {
370
+ latest.push(bundle.name)
371
+ continue
372
+ }
373
+ // Newer releases exist that this run must not install; say which and why instead of calling the package current.
374
+ const incompatible = list.versions.find(version => !version.prerelease && version.incompatible !== undefined)
375
+ blocked.push(incompatible === undefined
376
+ ? { name: bundle.name, title, reason: 'notInstallable', version: list.versions[0].version }
377
+ : {
378
+ name: bundle.name,
379
+ title,
380
+ reason: 'incompatible',
381
+ version: incompatible.version,
382
+ peers: peersText(incompatible.incompatible),
383
+ runtime: incompatible.incompatible === undefined ? '' : String(incompatible.incompatible.runtimeVersion),
384
+ })
385
+ }
386
+
387
+ const settled = {
388
+ refreshing: false,
389
+ checked: subjects.length,
390
+ current: null,
391
+ checkedAt: Date.now(),
392
+ candidates,
393
+ latest,
394
+ blocked,
395
+ skipped,
396
+ }
397
+ publish(quiet ? settled : { ...settled, phase: 'ready' })
398
+ }
399
+
400
+ /** Replace each candidate with its target version, one at a time. */
401
+ async function updateAll() {
402
+ const items = snapshot.candidates
403
+ if (running || disposed || items.length === 0) return
404
+ running = true
405
+ stopRequested = false
406
+ const results = []
407
+ publish({
408
+ phase: 'running',
409
+ error: null,
410
+ results: EMPTY,
411
+ stopping: false,
412
+ run: { total: items.length, index: 1, name: items[0].name, title: items[0].title, from: items[0].from, to: items[0].to, step: 'checking' },
413
+ })
414
+ let handled = 0
415
+ for (let index = 0; index < items.length; index += 1) {
416
+ if (stopRequested) break
417
+ const item = items[index]
418
+ requestId = nextRequestId()
419
+ publish({ run: { total: items.length, index: index + 1, name: item.name, title: item.title, from: item.from, to: item.to, step: 'checking' } })
420
+ let outcome
421
+ try {
422
+ const answer = await remote.pluginManager.updateBundle(item.name, item.to, { registry: item.registry, requestId })
423
+ outcome = answer.ok
424
+ ? describeUpdate(answer.value)
425
+ : { tone: 'error', key: 'outcomeFailed', params: {}, detail: answer.error.message, updated: false }
426
+ } catch (error) {
427
+ outcome = { tone: 'error', key: 'outcomeFailed', params: {}, detail: messageOf(error), updated: false }
428
+ }
429
+ requestId = null
430
+ if (disposed) return
431
+ handled = index + 1
432
+ results.push({ ...item, ...outcome })
433
+ publish({ results: [...results] })
434
+ }
435
+ // Whatever the run did not reach stays visible as its own row, so the report adds up to the candidate list.
436
+ for (let index = handled; index < items.length; index += 1) {
437
+ const item = items[index]
438
+ results.push({ ...item, tone: 'muted', key: 'outcomeSkipped', params: {}, detail: '', updated: false })
439
+ }
440
+ running = false
441
+ stopRequested = false
442
+ publish({ phase: 'done', run: null, stopping: false, results: [...results] })
443
+ // The list the page shows is stale once a package moved: read it again without losing the results.
444
+ await load({ quiet: true })
445
+ }
446
+
447
+ return {
448
+ subscribe: (listener) => {
449
+ listeners.add(listener)
450
+ return () => { listeners.delete(listener) }
451
+ },
452
+ getSnapshot: () => snapshot,
453
+ /** Read once, when the tab first opens. */
454
+ ensureChecked: () => {
455
+ if (snapshot.phase === 'idle') void load()
456
+ },
457
+ check: () => { void load() },
458
+ askConfirm: () => {
459
+ if (snapshot.candidates.length === 0 || snapshot.phase === 'running') return
460
+ publish({ phase: 'confirm' })
461
+ },
462
+ cancelConfirm: () => {
463
+ if (snapshot.phase === 'confirm') publish({ phase: 'ready' })
464
+ },
465
+ runUpdate: () => { void updateAll() },
466
+ /** Finish the plugin that is updating, then stop before the next one. */
467
+ requestStop: () => {
468
+ if (snapshot.phase !== 'running' || stopRequested) return
469
+ stopRequested = true
470
+ publish({ stopping: true })
471
+ },
472
+ /**
473
+ * Follow the Host's steps of this run.
474
+ * @param progress a request id and step received from the Host.
475
+ */
476
+ followStep: (progress) => {
477
+ const run = snapshot.run
478
+ if (run === null || progress.requestId !== requestId || run.step === progress.step) return
479
+ publish({ run: { ...run, step: progress.step } })
480
+ },
481
+ dispose: () => {
482
+ disposed = true
483
+ listeners.clear()
484
+ },
485
+ }
486
+ }
487
+
488
+ // ---------------------------------------------------------------------
489
+ // Rendering
490
+ // ---------------------------------------------------------------------
491
+
492
+ /**
493
+ * The tab's stylesheet, rendered with the tab so unmounting removes it.
494
+ *
495
+ * Every color is a `--dsw-alias-*` design token: `brand-primary` is the primary control *fill* (near-black in light,
496
+ * near-white in dark), so its label is `label-primary-foreground`; `bg-layer-1` equals the page background in the
497
+ * light theme, so raised surfaces and hovers use `card-fill` and `interactive-bg-hover`.
498
+ */
499
+ const STYLE = `
500
+ .dshua-root { display: flex; flex-direction: column; gap: 20px; color: var(--dsw-alias-label-primary); font-size: 13px; }
501
+ .dshua-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
502
+ .dshua-headText { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1 1 280px; }
503
+ .dshua-intro { margin: 0; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-secondary); }
504
+ .dshua-status { margin: 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); display: flex; align-items: center; gap: 6px; }
505
+ .dshua-status[data-tone="error"] { color: var(--dsw-alias-state-error-primary, var(--dsw-alias-label-secondary)); }
506
+ .dshua-status[data-tone="success"] { color: var(--dsw-alias-state-success-primary, var(--dsw-alias-label-secondary)); }
507
+ .dshua-actions { display: flex; align-items: center; gap: 8px; flex: none; }
508
+ .dshua-btn { height: 32px; padding: 0 14px; border-radius: 8px; border: 0.5px solid var(--dsw-alias-border-l3, var(--dsw-alias-border-l1)); background: transparent; color: var(--dsw-alias-label-primary); font: inherit; font-size: 13px; line-height: 1; white-space: nowrap; cursor: pointer; }
509
+ .dshua-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-1)); }
510
+ .dshua-btn:focus-visible { outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); outline-offset: 1px; }
511
+ .dshua-btn:disabled { opacity: 0.45; cursor: default; }
512
+ .dshua-btn--primary { background: var(--dsw-alias-button-primary-fill, var(--dsw-alias-brand-primary)); border-color: transparent; color: var(--dsw-alias-label-primary-foreground); }
513
+ .dshua-btn--primary:hover:not(:disabled) { background: var(--dsw-alias-button-primary-hover, var(--dsw-alias-brand-primary)); }
514
+ .dshua-spinner { width: 6px; height: 6px; border-radius: 50%; background: var(--dsw-alias-state-business-primary, var(--dsw-alias-label-primary)); animation: dshua-pulse 1.2s ease-in-out infinite; flex: none; }
515
+ @keyframes dshua-pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
516
+ .dshua-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
517
+ .dshua-row { display: flex; align-items: center; gap: 12px; margin: 0 -8px; padding: 7px 8px; border-radius: 8px; min-width: 0; }
518
+ .dshua-row:hover { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-2)); }
519
+ .dshua-rowMain { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
520
+ .dshua-rowHead { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
521
+ .dshua-rowTitle { font-size: 14px; line-height: 20px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
522
+ .dshua-rowName { font-size: 11px; color: var(--dsw-alias-label-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
523
+ .dshua-rowDetail { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); overflow-wrap: anywhere; }
524
+ .dshua-versions { display: flex; align-items: center; gap: 6px; font-size: 12px; font-family: var(--ds-font-family-code, ui-monospace, SFMono-Regular, Menlo, monospace); font-variant-numeric: tabular-nums; color: var(--dsw-alias-label-tertiary); flex: none; }
525
+ .dshua-arrow { color: var(--dsw-alias-label-tertiary); }
526
+ .dshua-to { color: var(--dsw-alias-label-primary); }
527
+ .dshua-rowState { font-size: 12px; flex: none; color: var(--dsw-alias-label-secondary); display: flex; align-items: center; gap: 6px; max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
528
+ .dshua-row[data-tone="success"] .dshua-rowState { color: var(--dsw-alias-state-success-primary, var(--dsw-alias-label-secondary)); }
529
+ .dshua-row[data-tone="warn"] .dshua-rowState { color: var(--dsw-alias-state-warn-primary, var(--dsw-alias-label-secondary)); }
530
+ .dshua-row[data-tone="error"] .dshua-rowState { color: var(--dsw-alias-state-error-primary, var(--dsw-alias-label-secondary)); }
531
+ .dshua-row[data-tone="active"] .dshua-rowState { color: var(--dsw-alias-state-business-primary, var(--dsw-alias-label-primary)); }
532
+ .dshua-confirm { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--dsw-alias-border-l3, var(--dsw-alias-border-l2)); background: var(--dsw-alias-card-fill, var(--dsw-alias-bg-layer-1)); }
533
+ .dshua-confirmTitle { margin: 0; font-size: 14px; line-height: 20px; font-weight: 600; }
534
+ .dshua-confirmBody { margin: 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
535
+ .dshua-confirmActions { display: flex; gap: 8px; padding-top: 2px; }
536
+ .dshua-hint { margin: 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-state-warn-primary, var(--dsw-alias-label-secondary)); }
537
+ .dshua-error { margin: 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); overflow-wrap: anywhere; }
538
+ .dshua-details { border-top: 1px solid var(--dsw-alias-border-l1); padding-top: 10px; }
539
+ .dshua-summary { cursor: pointer; font-size: 12px; color: var(--dsw-alias-label-secondary); }
540
+ .dshua-summary:focus-visible { outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); outline-offset: 2px; border-radius: 4px; }
541
+ .dshua-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
542
+ `
543
+
544
+ /**
545
+ * One package row: its display title, its technical name when they differ, a detail line, the version pair, and a
546
+ * state.
547
+ * @param props the row's content; `from`/`to` are absent for a package with no version pair.
548
+ * @returns the row element.
549
+ */
550
+ function PackageRow(props) {
551
+ const { title, name, from, to, state, tone, detail } = props
552
+ return h('li', { className: 'dshua-row', 'data-tone': tone },
553
+ h('span', { className: 'dshua-rowMain' },
554
+ h('span', { className: 'dshua-rowHead' },
555
+ h('span', { className: 'dshua-rowTitle', title }, title),
556
+ title === name ? null : h('span', { className: 'dshua-rowName' }, name)),
557
+ typeof detail === 'string' && detail !== '' ? h('span', { className: 'dshua-rowDetail' }, detail) : null),
558
+ from === undefined
559
+ ? null
560
+ : h('span', { className: 'dshua-versions' },
561
+ h('span', null, from),
562
+ h('span', { className: 'dshua-arrow', 'aria-hidden': 'true' }, '→'),
563
+ h('span', { className: 'dshua-to' }, to)),
564
+ state === undefined
565
+ ? null
566
+ : h('span', { className: 'dshua-rowState' },
567
+ tone === 'active' ? h('span', { className: 'dshua-spinner', 'aria-hidden': 'true' }) : null,
568
+ state))
569
+ }
570
+
571
+ /** The step a running update is on, as copy. */
572
+ function stepText(t, run) {
573
+ switch (run.step) {
574
+ case 'removing': return t('stepRemoving', { version: run.from })
575
+ case 'installing': return t('stepInstalling', { version: run.to })
576
+ case 'restoring': return t('stepRestoring', { version: run.from })
577
+ default: return t('stepChecking', { version: run.to })
578
+ }
579
+ }
580
+
581
+ /** The time of day a check arrived, as 24-hour `HH:MM`. */
582
+ function clockOf(milliseconds) {
583
+ const time = new Date(milliseconds)
584
+ return `${String(time.getHours()).padStart(2, '0')}:${String(time.getMinutes()).padStart(2, '0')}`
585
+ }
586
+
587
+ /** Whether a phase is still working. */
588
+ function busyPhase(phase) {
589
+ return phase === 'checking' || phase === 'running'
590
+ }
591
+
592
+ /** The status line's sentence, or null before the first check. */
593
+ function statusOf(state, t) {
594
+ if (state.phase === 'checking') {
595
+ if (state.total === 0) return { tone: 'info', text: t('readingInstalled') }
596
+ return {
597
+ tone: 'info',
598
+ text: t('checking', {
599
+ done: String(Math.min(state.checked + 1, state.total)),
600
+ total: String(state.total),
601
+ name: state.current === null ? '' : state.current,
602
+ }),
603
+ }
604
+ }
605
+ if (state.phase === 'running' && state.run !== null) {
606
+ return {
607
+ tone: 'info',
608
+ text: t('running', { index: String(state.run.index), total: String(state.run.total), name: state.run.title }),
609
+ }
610
+ }
611
+ if (busyPhase(state.phase)) return null
612
+ if (state.error !== null || state.phase === 'error') return { tone: 'error', text: t('errorTitle') }
613
+ if (state.checkedAt === null) return null
614
+ const time = clockOf(state.checkedAt)
615
+ if (state.candidates.length === 0 && state.blocked.length === 0) {
616
+ return { tone: 'success', text: `${t('allLatest')} · ${t('checkedAt', { time })}` }
617
+ }
618
+ const parts = [t('summaryLine', {
619
+ candidates: String(state.candidates.length),
620
+ latest: String(state.latest.length),
621
+ skipped: String(state.skipped.length),
622
+ })]
623
+ if (state.blocked.length > 0) parts.push(t('blockedCount', { count: String(state.blocked.length) }))
624
+ return { tone: 'info', text: `${parts.join(' · ')} · ${t('checkedAt', { time })}` }
625
+ }
626
+
627
+ /**
628
+ * The Updates tab: the page's own header copy, the run controls, the candidate or result rows, and the packages each
629
+ * run leaves alone.
630
+ * @param props the slot renderer's props, carrying the copy and this tab's controller.
631
+ * @returns the tab body.
632
+ */
633
+ function UpdateAllTab(props) {
634
+ const t = props.t
635
+ const controller = props.controller
636
+ const state = useSyncExternalStore(controller.subscribe, controller.getSnapshot)
637
+ useEffect(() => { controller.ensureChecked() }, [controller])
638
+
639
+ const phase = state.phase
640
+ const running = phase === 'running'
641
+ const busy = busyPhase(phase) || state.refreshing
642
+ const count = state.candidates.length
643
+ const status = statusOf(state, t)
644
+
645
+ let body = null
646
+ if (phase === 'confirm') {
647
+ body = h('div', { className: 'dshua-confirm', role: 'group', 'aria-label': t('confirmTitle', { count: String(count) }) },
648
+ h('p', { className: 'dshua-confirmTitle', 'aria-live': 'polite' }, t('confirmTitle', { count: String(count) })),
649
+ h('p', { className: 'dshua-confirmBody' }, t('confirmBody')),
650
+ h('div', { className: 'dshua-confirmActions' },
651
+ h('button', { type: 'button', className: 'dshua-btn', onClick: () => { controller.cancelConfirm() } }, t('cancel')),
652
+ h('button', {
653
+ type: 'button',
654
+ className: 'dshua-btn dshua-btn--primary',
655
+ autoFocus: true,
656
+ onClick: () => { controller.runUpdate() },
657
+ }, t('confirmRun', { count: String(count) }))))
658
+ }
659
+
660
+ let list = null
661
+ if (running) {
662
+ list = h('ul', { className: 'dshua-list' }, state.candidates.map((item, index) => {
663
+ const settled = state.results[index]
664
+ if (settled !== undefined) {
665
+ return h(PackageRow, {
666
+ key: item.name, title: item.title, name: item.name, from: item.from, to: item.to,
667
+ state: t(settled.key, settled.params), tone: settled.tone, detail: settled.detail,
668
+ })
669
+ }
670
+ const current = index === state.results.length
671
+ return h(PackageRow, {
672
+ key: item.name, title: item.title, name: item.name, from: item.from, to: item.to,
673
+ state: current && state.run !== null ? stepText(t, state.run) : t('waiting'),
674
+ tone: current ? 'active' : 'muted',
675
+ })
676
+ }))
677
+ } else if (phase === 'done') {
678
+ list = h('ul', { className: 'dshua-list' }, state.results.map(item => h(PackageRow, {
679
+ key: item.name, title: item.title, name: item.name, from: item.from, to: item.to,
680
+ state: t(item.key, item.params), tone: item.tone, detail: item.detail,
681
+ })))
682
+ } else if (count > 0) {
683
+ list = h('ul', { className: 'dshua-list' }, state.candidates.map(item => h(PackageRow, {
684
+ key: item.name, title: item.title, name: item.name, from: item.from, to: item.to,
685
+ })))
686
+ }
687
+
688
+ const updated = phase === 'done' && state.results.some(item => item.updated === true)
689
+
690
+ const blockedList = state.blocked.length === 0 ? null : h('details', { className: 'dshua-details' },
691
+ h('summary', { className: 'dshua-summary' }, t('blockedCount', { count: String(state.blocked.length) })),
692
+ h('ul', { className: 'dshua-list' },
693
+ state.blocked.map(item => h(PackageRow, {
694
+ key: item.name,
695
+ title: item.title,
696
+ name: item.name,
697
+ state: t(item.reason === 'incompatible' ? 'blockedIncompatible' : 'blockedNotInstallable', { peers: item.peers === undefined ? '' : item.peers, runtime: item.runtime === undefined ? '' : item.runtime }),
698
+ tone: 'warn',
699
+ }))))
700
+
701
+ const skippedList = state.skipped.length === 0 ? null : h('details', { className: 'dshua-details' },
702
+ h('summary', { className: 'dshua-summary' }, t('skippedTitle', { count: String(state.skipped.length) })),
703
+ h('ul', { className: 'dshua-list' },
704
+ state.skipped.map(item => h(PackageRow, {
705
+ key: item.name,
706
+ title: item.title,
707
+ name: item.name,
708
+ state: t(SKIP_KEYS[item.reason]),
709
+ tone: 'muted',
710
+ detail: item.detail,
711
+ }))))
712
+
713
+ const runControl = running
714
+ ? h('button', {
715
+ type: 'button',
716
+ className: 'dshua-btn',
717
+ disabled: state.stopping,
718
+ onClick: () => { controller.requestStop() },
719
+ }, state.stopping ? t('stopping') : t('stop'))
720
+ : phase === 'confirm' || count === 0
721
+ ? null
722
+ : h('button', {
723
+ type: 'button',
724
+ className: 'dshua-btn dshua-btn--primary',
725
+ disabled: busy,
726
+ onClick: () => { controller.askConfirm() },
727
+ }, t('updateAll', { count: String(count) }))
728
+
729
+ return h('section', { className: 'dshua-root', 'aria-busy': busy },
730
+ h('style', null, STYLE),
731
+ h('div', { className: 'dshua-head' },
732
+ h('div', { className: 'dshua-headText' },
733
+ h('p', { className: 'dshua-intro' }, t('intro')),
734
+ status === null ? null : h('p', { className: 'dshua-status', 'data-tone': status.tone },
735
+ busyPhase(phase) ? h('span', { className: 'dshua-spinner', 'aria-hidden': 'true' }) : null,
736
+ h('span', null, status.text))),
737
+ h('div', { className: 'dshua-actions' },
738
+ h('button', {
739
+ type: 'button',
740
+ className: 'dshua-btn',
741
+ disabled: busy || phase === 'confirm',
742
+ onClick: () => { controller.check() },
743
+ }, state.checkedAt === null ? t('checkForUpdates') : t('recheck')),
744
+ runControl)),
745
+ // One polite region for the settled outcome: the per-package progress line above stays out of it.
746
+ h('p', { className: 'dshua-sr', role: 'status' }, busy ? '' : status === null ? '' : status.text),
747
+ body,
748
+ phase === 'error' && state.error !== null ? h('p', { className: 'dshua-error' }, state.error) : null,
749
+ list,
750
+ updated ? h('p', { className: 'dshua-hint' }, t('reloadHint')) : null,
751
+ blockedList,
752
+ skippedList)
753
+ }
754
+
755
+ // ---------------------------------------------------------------------
756
+ // Plugin
757
+ // ---------------------------------------------------------------------
758
+
759
+ return {
760
+ /** Services the tab's registration and its Remote calls need. */
761
+ inject: ['slots', 'locale', 'remote', 'remote.pluginManager'],
762
+ /**
763
+ * Register the Updates tab and follow the Host's update steps.
764
+ * @param ctx the browser plugin context.
765
+ */
766
+ apply(ctx) {
767
+ ctx.effect(() => ctx.locale.register(NS, { zh: ZH, en: EN }), 'update-all: dictionaries')
768
+ const t = ctx.locale.bind(NS)
769
+ const controller = createController(ctx.remote, text => ctx.locale.resolveText(text))
770
+ ctx.effect(() => () => { controller.dispose() }, 'update-all: controller')
771
+ ctx.effect(
772
+ () => ctx.remote.$on('plugin-manager/update-state', progress => { controller.followStep(progress) }),
773
+ 'update-all: update progress',
774
+ )
775
+ ctx.slots.inject('plugins.tab', () => ctx.slots.register({
776
+ name: 'plugins.tab',
777
+ id: TAB_ID,
778
+ order: TAB_ORDER,
779
+ label: () => t('tab'),
780
+ locale: NS,
781
+ inject: () => ({ controller }),
782
+ }, UpdateAllTab))
783
+ },
784
+ }
785
+ },
786
+ })