dsh-pluginmarket-plus 0.1.0 → 0.2.1
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 +100 -18
- package/client.js +1960 -52
- package/icon.svg +1 -1
- package/lib/index.js +532 -1
- package/lib/store.js +99 -1
- package/lib/updates.js +769 -0
- package/locale/en.json +2 -2
- package/locale/zh.json +2 -2
- package/package.json +5 -2
package/client.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* dsh-pluginmarket-plus —— 客户端半边(无构建步骤,直接由 __ModuleLoader__ 装载)。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 插件页两个标签:`pluginmarket-plus-cache`(插件源缓存)与 `pluginmarket-plus-updates`
|
|
5
|
+
* (可更新)。缓存标签展示每个索引源的缓存状态,提供「刷新」「改刷新间隔」
|
|
6
|
+
* 「让发现页使用本地缓存」等操作;「可更新」标签集中列出有更新的 bundle。
|
|
7
|
+
* 所有数据都来自 Host 的 `/api/pluginmarket-plus/*`(经 connection 精确路由,
|
|
8
|
+
* 只有 owner 浏览器能访问)。
|
|
7
9
|
*
|
|
8
10
|
* 约束:工厂函数无副作用;样式/字典/席位注册全部放进 apply 并用 ctx.effect 清理;
|
|
9
11
|
* 只 require('react'),不 import 任何 @deepseek-ai Client 包。
|
|
@@ -19,11 +21,22 @@ window.__ModuleLoader__.load({
|
|
|
19
21
|
const NS = 'pluginmarket-plus'
|
|
20
22
|
/** 设置页 API 前缀。 */
|
|
21
23
|
const API = '/api/pluginmarket-plus'
|
|
24
|
+
/** 「可更新」页使用的桥接前缀(同源,仅 owner 浏览器可读)。 */
|
|
25
|
+
const UPDATES_API = `${API}/updates`
|
|
26
|
+
/** 注册进插件页的席位名。 */
|
|
27
|
+
const UPDATES_SLOT = 'plugins.tab'
|
|
28
|
+
/** 席位 id 与顺序(排在自带的 Installed / Discover 之后)。 */
|
|
29
|
+
const UPDATES_ID = 'pluginmarket-plus-updates'
|
|
30
|
+
const UPDATES_ORDER = 20
|
|
31
|
+
/** 「插件源缓存」tab:排在 discover 之后、「可更新」之前。 */
|
|
32
|
+
const CACHE_ID = 'pluginmarket-plus-cache'
|
|
33
|
+
const CACHE_ORDER = 10
|
|
34
|
+
/** 进度轮询间隔(毫秒)。 */
|
|
35
|
+
const POLL_MS = 700
|
|
22
36
|
|
|
23
37
|
const I18N = {
|
|
24
38
|
zh: {
|
|
25
|
-
|
|
26
|
-
title: '插件市场缓存',
|
|
39
|
+
cacheTab: '插件源缓存',
|
|
27
40
|
intro: '把「插件 → 发现」读取的索引 JSON 缓存到本地磁盘,定时或手动刷新。在「发现 → 索引源」或本页增删索引源都会自动同步;开启下方开关后,发现页会改用本地镜像,搜索不再因上游索引超时而失败。',
|
|
28
41
|
loading: '读取中…',
|
|
29
42
|
failed: '读取失败:{error}',
|
|
@@ -69,10 +82,111 @@ window.__ModuleLoader__.load({
|
|
|
69
82
|
refreshDone: '刷新完成',
|
|
70
83
|
refreshFailed: '刷新失败:{error}',
|
|
71
84
|
removal: '已移除',
|
|
85
|
+
|
|
86
|
+
// ——「可更新」标签页 ——
|
|
87
|
+
updatesTab: '可更新',
|
|
88
|
+
updatesCheck: '检查更新',
|
|
89
|
+
updatesChecking: '检查中…',
|
|
90
|
+
updatesLastChecked: '上次检查 {time}',
|
|
91
|
+
updatesNeverChecked: '尚未检查',
|
|
92
|
+
updatesSummary: '可更新 {updates} 项 · 已选 {selected}',
|
|
93
|
+
updatesSearchPlaceholder: '搜索包名…',
|
|
94
|
+
updatesSettingsMenu: '设置',
|
|
95
|
+
updatesShowFailed: '显示检查失败的项',
|
|
96
|
+
updatesIncludePrerelease: '包含预发布/已废弃',
|
|
97
|
+
updatesIncludeDisabled: '包含已禁用的插件',
|
|
98
|
+
updatesUpdateAll: '更新全部',
|
|
99
|
+
updatesUpdateSelected: '更新已选',
|
|
100
|
+
updatesSelectAll: '全选',
|
|
101
|
+
updatesCancel: '取消',
|
|
102
|
+
updatesRowUpdate: '更新',
|
|
103
|
+
updatesStateUpdatable: '可更新',
|
|
104
|
+
updatesStateIncompatible: '不兼容',
|
|
105
|
+
updatesStatePrerelease: '预发布',
|
|
106
|
+
updatesStateDeprecated: '已废弃',
|
|
107
|
+
updatesStateDisabled: '已禁用',
|
|
108
|
+
updatesStateFailed: '检查失败',
|
|
109
|
+
updatesStateExempted: '已豁免',
|
|
110
|
+
updatesStateSkipped: '跳过',
|
|
111
|
+
updatesStateCurrent: '无更新',
|
|
112
|
+
updatesStateUncheckable: '无法检查',
|
|
113
|
+
updatesUncheckableReasonIndexMiss: '本地索引中找不到该 Git 包可用的提交记录',
|
|
114
|
+
updatesUncheckableReasonUnpinned: 'Git 包未固定 commit,无法检查更新',
|
|
115
|
+
updatesUncheckableReasonOther: '暂时无法检查更新(原因未知)',
|
|
116
|
+
updatesStateUnknown: '未检查',
|
|
117
|
+
updatesSetsLocalOnly: '当前部署无法写回配置:开关只对本次运行生效。',
|
|
118
|
+
updatesNeedCheck: '还没有检查过,请先点「检查更新」。',
|
|
119
|
+
updatesRunningElsewhere: '另一个更新正在进行,请稍后再试。',
|
|
120
|
+
updatesKindNpm: 'npm',
|
|
121
|
+
updatesKindGit: 'git',
|
|
122
|
+
updatesEmpty: '没有可更新的插件。点「检查更新」只看已安装且能自动更新的包(官方自带、link:/file:/别名、未固定 commit 的 git 都不显示)。',
|
|
123
|
+
updatesEmptyFilter: '没有匹配当前搜索的条目。',
|
|
124
|
+
updatesEmptyNoUpdate: '没有可更新的插件。',
|
|
125
|
+
updatesEmptyShowFailed: '没有可更新的插件。可在设置里打开「显示检查失败的项」查看检查失败/无法检查的条目。',
|
|
126
|
+
updatesUnknown: '未知',
|
|
127
|
+
updatesLoading: '读取中…',
|
|
128
|
+
updatesLoadFailed: '读取失败:{error}',
|
|
129
|
+
updatesCheckFailed: '检查失败:{error}',
|
|
130
|
+
updatesCheckDone: '检查完成:可更新 {n} 项',
|
|
131
|
+
updatesSettingsFailed: '保存设置失败:{error}',
|
|
132
|
+
updatesUnknownVersion: '—',
|
|
133
|
+
updatesExemptEntry: '版本豁免',
|
|
134
|
+
updatesExemptFlow: '豁免此版本并更新',
|
|
135
|
+
updatesExemptAck: '我知道风险:可能崩溃、数据丢失',
|
|
136
|
+
updatesExemptIntro: '豁免只对本机生效,且精确到「包@版本 × DSH 版本」,插件或 DSH 升级后失效。',
|
|
137
|
+
updatesExemptSubmit: '继续',
|
|
138
|
+
updatesExemptConfirmTitle: '再次确认:豁免风险版本',
|
|
139
|
+
updatesExemptConfirmBody: '将把 {pkg} 与运行中的 DSH {runtime} 标记为允许组合,然后立即更新到 {target}。不兼容的插件可能导致崩溃或数据丢失。',
|
|
140
|
+
updatesExemptConfirmYes: '豁免并更新',
|
|
141
|
+
updatesExemptDoing: '正在豁免…',
|
|
142
|
+
updatesExemptFailed: '豁免失败:{error}',
|
|
143
|
+
updatesConfirmTitle: '确认更新',
|
|
144
|
+
updatesConfirmTitleBulk: '确认更新 {n} 项',
|
|
145
|
+
updatesConfirmLeadSingle: '将更新下列插件:',
|
|
146
|
+
updatesConfirmLeadBulk: '将按顺序依次更新下列 {n} 项(某项失败会继续下一项):',
|
|
147
|
+
updatesConfirmFrom: '当前版本',
|
|
148
|
+
updatesConfirmTo: '目标版本',
|
|
149
|
+
updatesConfirmSource: '安装来源',
|
|
150
|
+
updatesConfirmRollback: '失败时会尝试装回当前版本;装回也失败则该包会处于未安装状态。',
|
|
151
|
+
updatesConfirmQueue: '一次只跑一个更新;批量中可取消。',
|
|
152
|
+
updatesConfirmNow: '开始更新',
|
|
153
|
+
updatesConfirmClose: '关闭',
|
|
154
|
+
updatesProgressTitle: '更新进度',
|
|
155
|
+
updatesProgressOf: '第 {index}/{total} 项',
|
|
156
|
+
updatesStage: '阶段',
|
|
157
|
+
updatesLogToggle: 'pnpm 日志',
|
|
158
|
+
updatesLogEmpty: '暂无日志',
|
|
159
|
+
updatesCancelQueue: '取消当前',
|
|
160
|
+
updatesCancelling: '正在取消…',
|
|
161
|
+
updatesCancelHint: '取消只作用于当前这一项,后续项会跳过。',
|
|
162
|
+
updatesSummaryTitle: '更新结果',
|
|
163
|
+
updatesSuccessItems: '成功 {n} 项',
|
|
164
|
+
updatesFailedItems: '失败 {n} 项',
|
|
165
|
+
updatesRestartItems: '需重启 {n} 项',
|
|
166
|
+
updatesSkippedItems: '已跳过 {n} 项',
|
|
167
|
+
updatesStages: '阶段记录:',
|
|
168
|
+
updatesRestored: '已装回原版本',
|
|
169
|
+
updatesRestoreIdle: '未发生回滚',
|
|
170
|
+
updatesRestoreFailed: '回滚也失败了',
|
|
171
|
+
updatesRestartRequired: '需要重启 DSH',
|
|
172
|
+
updatesClose: '完成',
|
|
173
|
+
updatesStartFailed: '更新未能开始:{error}',
|
|
174
|
+
updatesAnotherRunning: '另一个更新正在进行,请稍后再试。',
|
|
175
|
+
updatesStateLost: '进度状态读取失败(可重试)。',
|
|
176
|
+
updatesRecheck: '重新检查',
|
|
177
|
+
stagePending: '等待',
|
|
178
|
+
stageChecking: '检查',
|
|
179
|
+
stageRemoving: '移除',
|
|
180
|
+
stageInstalling: '安装',
|
|
181
|
+
stageRestoring: '回滚',
|
|
182
|
+
stageDone: '完成',
|
|
183
|
+
stageFailed: '失败',
|
|
184
|
+
stageRestart: '需重启',
|
|
185
|
+
stageCancelled: '已取消',
|
|
186
|
+
stageSkipped: '已跳过',
|
|
72
187
|
},
|
|
73
188
|
en: {
|
|
74
|
-
|
|
75
|
-
title: 'Plugin market cache',
|
|
189
|
+
cacheTab: 'Plugin source cache',
|
|
76
190
|
intro: 'Caches the index JSON that Plugins → Discover reads, on local disk, refreshed on a schedule or on demand. Adding or removing a source in Discover → Index sources or on this page stays in sync; turn on the switch below to point Discover at the local mirror, so searches no longer fail on an upstream index timeout.',
|
|
77
191
|
loading: 'Loading…',
|
|
78
192
|
failed: 'Failed to load: {error}',
|
|
@@ -118,12 +232,115 @@ window.__ModuleLoader__.load({
|
|
|
118
232
|
refreshDone: 'Refresh complete',
|
|
119
233
|
refreshFailed: 'Refresh failed: {error}',
|
|
120
234
|
removal: 'Removed',
|
|
235
|
+
|
|
236
|
+
// —— Updates tab ——
|
|
237
|
+
updatesTab: 'Updates',
|
|
238
|
+
updatesCheck: 'Check for updates',
|
|
239
|
+
updatesChecking: 'Checking…',
|
|
240
|
+
updatesLastChecked: 'Checked {time}',
|
|
241
|
+
updatesNeverChecked: 'Not checked yet',
|
|
242
|
+
updatesSummary: '{updates} updatable · {selected} selected',
|
|
243
|
+
updatesSearchPlaceholder: 'Search package name…',
|
|
244
|
+
updatesSettingsMenu: 'Settings',
|
|
245
|
+
updatesShowFailed: 'Show failed checks',
|
|
246
|
+
updatesIncludePrerelease: 'Include prerelease/deprecated',
|
|
247
|
+
updatesIncludeDisabled: 'Include disabled plugins',
|
|
248
|
+
updatesUpdateAll: 'Update all',
|
|
249
|
+
updatesUpdateSelected: 'Update selected',
|
|
250
|
+
updatesSelectAll: 'Select all',
|
|
251
|
+
updatesCancel: 'Cancel',
|
|
252
|
+
updatesRowUpdate: 'Update',
|
|
253
|
+
updatesStateUpdatable: 'Updatable',
|
|
254
|
+
updatesStateIncompatible: 'Incompatible',
|
|
255
|
+
updatesStatePrerelease: 'Prerelease',
|
|
256
|
+
updatesStateDeprecated: 'Deprecated',
|
|
257
|
+
updatesStateDisabled: 'Disabled',
|
|
258
|
+
updatesStateFailed: 'Check failed',
|
|
259
|
+
updatesStateExempted: 'Exempted',
|
|
260
|
+
updatesStateSkipped: 'Skipped',
|
|
261
|
+
updatesStateCurrent: 'No update',
|
|
262
|
+
updatesStateUncheckable: 'Cannot check',
|
|
263
|
+
updatesUncheckableReasonIndexMiss: 'No usable commit for this Git bundle was found in the local index',
|
|
264
|
+
updatesUncheckableReasonUnpinned: 'This Git bundle is not pinned to a commit, so updates cannot be checked',
|
|
265
|
+
updatesUncheckableReasonOther: 'Cannot check for updates right now (reason unknown)',
|
|
266
|
+
updatesStateUnknown: 'Not checked',
|
|
267
|
+
updatesSetsLocalOnly: 'This deployment cannot persist configuration: the switches last for this run only.',
|
|
268
|
+
updatesNeedCheck: 'Not checked yet — run "Check for updates" first.',
|
|
269
|
+
updatesRunningElsewhere: 'Another update is already running; try again shortly.',
|
|
270
|
+
updatesKindNpm: 'npm',
|
|
271
|
+
updatesKindGit: 'git',
|
|
272
|
+
updatesEmpty: 'Nothing to update. "Check for updates" only looks at installed bundles that can update automatically (official bundles, link:/file:/aliases, and git specs without a pinned commit are never listed).',
|
|
273
|
+
updatesEmptyFilter: 'No entry matches the search.',
|
|
274
|
+
updatesEmptyNoUpdate: 'Nothing to update.',
|
|
275
|
+
updatesEmptyShowFailed: 'Nothing to update. Turn on "Show failed checks" in Settings to include failed or uncheckable entries.',
|
|
276
|
+
updatesUnknown: 'unknown',
|
|
277
|
+
updatesLoading: 'Loading…',
|
|
278
|
+
updatesLoadFailed: 'Failed to load: {error}',
|
|
279
|
+
updatesCheckFailed: 'Check failed: {error}',
|
|
280
|
+
updatesCheckDone: 'Check finished: {n} updatable',
|
|
281
|
+
updatesSettingsFailed: 'Could not save settings: {error}',
|
|
282
|
+
updatesUnknownVersion: '—',
|
|
283
|
+
updatesExemptEntry: 'Version exemption',
|
|
284
|
+
updatesExemptFlow: 'Exempt this version and update',
|
|
285
|
+
updatesExemptAck: 'I accept the risk: crashes and data loss are possible',
|
|
286
|
+
updatesExemptIntro: 'An exemption is local and exact — one package version on one DSH version; it does not survive upgrading either side.',
|
|
287
|
+
updatesExemptSubmit: 'Continue',
|
|
288
|
+
updatesExemptConfirmTitle: 'Confirm again: exempt a risky version',
|
|
289
|
+
updatesExemptConfirmBody: 'This allows {pkg} on the running DSH {runtime} and then updates to {target} immediately. An incompatible plugin can crash the app or lose data.',
|
|
290
|
+
updatesExemptConfirmYes: 'Exempt and update',
|
|
291
|
+
updatesExemptDoing: 'Exempting…',
|
|
292
|
+
updatesExemptFailed: 'Exemption failed: {error}',
|
|
293
|
+
updatesConfirmTitle: 'Confirm update',
|
|
294
|
+
updatesConfirmTitleBulk: 'Confirm {n} updates',
|
|
295
|
+
updatesConfirmLeadSingle: 'The following plugin will be updated:',
|
|
296
|
+
updatesConfirmLeadBulk: 'These {n} items run one after another (a failure continues with the next):',
|
|
297
|
+
updatesConfirmFrom: 'Current',
|
|
298
|
+
updatesConfirmTo: 'Target',
|
|
299
|
+
updatesConfirmSource: 'Source',
|
|
300
|
+
updatesConfirmRollback: 'A failure tries to reinstall the current version; if that also fails the package stays uninstalled.',
|
|
301
|
+
updatesConfirmQueue: 'One update runs at a time; a batch can be cancelled.',
|
|
302
|
+
updatesConfirmNow: 'Start update',
|
|
303
|
+
updatesConfirmClose: 'Close',
|
|
304
|
+
updatesProgressTitle: 'Update progress',
|
|
305
|
+
updatesProgressOf: 'Item {index}/{total}',
|
|
306
|
+
updatesStage: 'Stage',
|
|
307
|
+
updatesLogToggle: 'pnpm log',
|
|
308
|
+
updatesLogEmpty: 'No log yet',
|
|
309
|
+
updatesCancelQueue: 'Cancel current',
|
|
310
|
+
updatesCancelling: 'Cancelling…',
|
|
311
|
+
updatesCancelHint: 'Cancel affects only the current item; the remaining items are skipped.',
|
|
312
|
+
updatesSummaryTitle: 'Result',
|
|
313
|
+
updatesSuccessItems: '{n} succeeded',
|
|
314
|
+
updatesFailedItems: '{n} failed',
|
|
315
|
+
updatesRestartItems: '{n} need a restart',
|
|
316
|
+
updatesSkippedItems: '{n} skipped',
|
|
317
|
+
updatesStages: 'Stages:',
|
|
318
|
+
updatesRestored: 'Current version reinstalled',
|
|
319
|
+
updatesRestoreIdle: 'No rollback happened',
|
|
320
|
+
updatesRestoreFailed: 'Rollback failed too',
|
|
321
|
+
updatesRestartRequired: 'DSH restart required',
|
|
322
|
+
updatesClose: 'Done',
|
|
323
|
+
updatesStartFailed: 'The update did not start: {error}',
|
|
324
|
+
updatesAnotherRunning: 'Another update is already running; try again shortly.',
|
|
325
|
+
updatesStateLost: 'Could not read progress state (retryable).',
|
|
326
|
+
updatesRecheck: 'Check again',
|
|
327
|
+
stagePending: 'Queued',
|
|
328
|
+
stageChecking: 'Checking',
|
|
329
|
+
stageRemoving: 'Removing',
|
|
330
|
+
stageInstalling: 'Installing',
|
|
331
|
+
stageRestoring: 'Rolling back',
|
|
332
|
+
stageDone: 'Done',
|
|
333
|
+
stageFailed: 'Failed',
|
|
334
|
+
stageRestart: 'Restart needed',
|
|
335
|
+
stageCancelled: 'Cancelled',
|
|
336
|
+
stageSkipped: 'Skipped',
|
|
121
337
|
},
|
|
122
338
|
}
|
|
123
339
|
|
|
124
340
|
const CSS = [
|
|
125
341
|
'.pmp-page{display:flex;flex-direction:column;gap:14px;width:100%;max-width:760px;color:var(--dsw-alias-label-primary);font:inherit}',
|
|
126
|
-
|
|
342
|
+
// 插件页 tab 内:不设额外内边距/最大宽度(避免与设置页样式冲突)。
|
|
343
|
+
'.pmp-tabPage{max-width:none;min-width:0;padding:0}',
|
|
127
344
|
'.pmp-intro{margin:0;font-size:13px;line-height:20px;color:var(--dsw-alias-label-secondary)}',
|
|
128
345
|
'.pmp-notice{display:flex;align-items:center;gap:8px;border-radius:var(--dsw-radius-md);padding:8px 10px;font-size:12px;line-height:18px;overflow-wrap:anywhere}',
|
|
129
346
|
'.pmp-notice[data-tone="ok"]{background:color-mix(in srgb, var(--dsw-alias-state-success-primary) 10%, transparent);color:var(--dsw-alias-state-success-primary)}',
|
|
@@ -133,7 +350,7 @@ window.__ModuleLoader__.load({
|
|
|
133
350
|
'.pmp-btn{font:inherit;font-size:12px;line-height:18px;padding:4px 10px;border-radius:var(--dsw-radius-sm);border:0.5px solid var(--dsw-alias-border-l3);background:transparent;color:var(--dsw-alias-label-primary);cursor:pointer}',
|
|
134
351
|
'.pmp-btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}',
|
|
135
352
|
'.pmp-btn:disabled{opacity:.45;cursor:default}',
|
|
136
|
-
'.pmp-btnPrimary{border-color:transparent;background:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-label-on-color
|
|
353
|
+
'.pmp-btnPrimary{border-color:transparent;background:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-label-on-color)}',
|
|
137
354
|
'.pmp-btnPrimary:hover:not(:disabled){filter:brightness(1.06)}',
|
|
138
355
|
'.pmp-btnDanger{color:var(--dsw-alias-state-error-primary)}',
|
|
139
356
|
'.pmp-select{font:inherit;font-size:12px;height:26px;border-radius:var(--dsw-radius-sm);border:0.5px solid var(--dsw-alias-border-l3);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);padding:0 6px}',
|
|
@@ -152,7 +369,7 @@ window.__ModuleLoader__.load({
|
|
|
152
369
|
'.pmp-switch{position:relative;width:34px;height:20px;flex:none;padding:0;border-radius:999px;border:0.5px solid var(--dsw-alias-border-l3);background:var(--dsw-alias-bg-module-platform);cursor:pointer;transition:background .15s}',
|
|
153
370
|
'.pmp-switch[aria-checked="true"]{background:var(--dsw-alias-state-business-primary);border-color:transparent}',
|
|
154
371
|
'.pmp-switch:disabled{opacity:.45;cursor:default}',
|
|
155
|
-
'.pmp-switchKnob{position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;background
|
|
372
|
+
'.pmp-switchKnob{position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-switch-thumb);box-shadow:0 1px 2px var(--dsw-alias-bg-mask-2);transition:transform .15s}',
|
|
156
373
|
'.pmp-switch[aria-checked="true"] .pmp-switchKnob{transform:translateX(14px)}',
|
|
157
374
|
'.pmp-switchRow{display:flex;align-items:center;gap:10px;flex-wrap:wrap}',
|
|
158
375
|
'.pmp-hint{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary)}',
|
|
@@ -161,8 +378,113 @@ window.__ModuleLoader__.load({
|
|
|
161
378
|
'.pmp-input:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:0}',
|
|
162
379
|
'.pmp-sectionLabel{margin:0;font-size:12px;font-weight:600;color:var(--dsw-alias-label-secondary)}',
|
|
163
380
|
'.pmp-codes{margin:0;font-family:var(--ds-font-family-code,monospace);font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary);overflow-wrap:anywhere}',
|
|
381
|
+
|
|
382
|
+
// ——「可更新」标签页(.pmu-*) ——
|
|
383
|
+
'.pmu-root{display:flex;flex-direction:column;gap:12px;width:100%;min-width:0;color:var(--dsw-alias-label-primary);font:inherit}',
|
|
384
|
+
'.pmu-sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}',
|
|
385
|
+
'.pmu-title{margin:0;font-size:16px;font-weight:600;line-height:24px}',
|
|
386
|
+
'.pmu-toolbar{display:flex;align-items:center;gap:10px;flex-wrap:wrap}',
|
|
387
|
+
'.pmu-search{flex:1 1 200px;min-width:140px;height:30px;border-radius:var(--dsw-radius-md);border:0.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;padding:0 10px}',
|
|
388
|
+
'.pmu-search:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:0}',
|
|
389
|
+
'.pmu-checkBtn{flex:none}',
|
|
390
|
+
'.pmu-gearBtn{position:relative;z-index:31;display:inline-flex;align-items:center;justify-content:center;width:30px;height:30px;padding:0;flex:none}',
|
|
391
|
+
'.pmu-gear{display:block}',
|
|
392
|
+
'.pmu-settingsWrap{flex:none}',
|
|
393
|
+
'.pmu-switchLabel{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:transparent;border:0;padding:0}',
|
|
394
|
+
'.pmu-filterWrap{position:relative;display:inline-flex}',
|
|
395
|
+
// 遮罩与菜单是 filterWrap 下的兄弟节点:菜单以 filterWrap(position:relative)为包含块,
|
|
396
|
+
// 不会再像挂在全屏 fixed 遮罩下那样被定位到视口下方。
|
|
397
|
+
'.pmu-menuLayer{position:fixed;inset:0;z-index:30}',
|
|
398
|
+
'.pmu-menu{position:absolute;top:calc(100% + 6px);left:0;z-index:41;display:flex;flex-direction:column;gap:8px;min-width:220px;max-width:min(320px,92vw);max-height:min(70vh,360px);overflow:auto;padding:10px 12px;border:0.5px solid var(--dsw-alias-border-l3);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-overlay);box-shadow:0 8px 24px var(--dsw-alias-bg-mask-3)}',
|
|
399
|
+
'.pmu-menu[data-placement="top"][data-anchored="css"]{top:auto;bottom:calc(100% + 6px)}',
|
|
400
|
+
'.pmu-menuRow{display:flex;align-items:center;gap:8px}',
|
|
401
|
+
'.pmu-notice{margin:0;font-size:12px;line-height:18px;border-radius:var(--dsw-radius-md);padding:8px 10px;overflow-wrap:anywhere}',
|
|
402
|
+
'.pmu-notice[data-tone="ok"]{background:color-mix(in srgb, var(--dsw-alias-state-success-primary) 10%, transparent);color:var(--dsw-alias-state-success-primary)}',
|
|
403
|
+
'.pmu-notice[data-tone="error"]{background:color-mix(in srgb, var(--dsw-alias-state-error-primary) 10%, transparent);color:var(--dsw-alias-state-error-primary)}',
|
|
404
|
+
'.pmu-notice[data-tone="warn"]{background:color-mix(in srgb, var(--dsw-alias-state-warn-primary) 12%, transparent);color:var(--dsw-alias-state-warn-primary)}',
|
|
405
|
+
'.pmu-error{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-state-error-primary);overflow-wrap:anywhere;white-space:pre-wrap}',
|
|
406
|
+
'.pmu-hint{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary)}',
|
|
407
|
+
'.pmu-summary{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding:8px 12px;border:0.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-module-platform)}',
|
|
408
|
+
'.pmu-summaryText{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}',
|
|
409
|
+
'.pmu-summaryActions{margin-left:auto;display:flex;align-items:center;gap:8px}',
|
|
410
|
+
'.pmu-summaryTime{margin-left:auto;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary);white-space:nowrap}',
|
|
411
|
+
'.pmu-list{display:flex;flex-direction:column;gap:6px}',
|
|
412
|
+
'.pmu-row{display:flex;flex-direction:column;gap:6px;padding:10px 12px;border:0.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-layer-1)}',
|
|
413
|
+
'.pmu-row[data-tone="bad"]{border-color:color-mix(in srgb, var(--dsw-alias-state-error-primary) 40%, transparent)}',
|
|
414
|
+
'.pmu-row[data-busy="true"]{border-color:var(--dsw-alias-border-selected)}',
|
|
415
|
+
// 行主区:共享列宽的 CSS Grid(所有行共用同一模板 → 来源/版本/状态/操作列垂直对齐)。
|
|
416
|
+
// 列顺序:复选框 | 插件名(吃剩余空间) | 更新来源 | 版本变动 | 弹性空隙 | 已禁用 | 主状态 | 操作
|
|
417
|
+
'.pmu-rowMain{display:grid;grid-template-columns:auto minmax(0,1fr) 56px 148px minmax(8px,0.4fr) 56px 92px minmax(112px,auto);column-gap:10px;row-gap:6px;align-items:center;min-width:0}',
|
|
418
|
+
'.pmu-check{grid-column:1;width:14px;height:14px;accent-color:var(--dsw-alias-state-business-primary);cursor:pointer}',
|
|
419
|
+
'.pmu-check:disabled{opacity:.45;cursor:default}',
|
|
420
|
+
'.pmu-nameCell{grid-column:2;min-width:0;max-width:100%;overflow:hidden}',
|
|
421
|
+
'.pmu-name{display:block;max-width:100%;min-width:0;font-size:13px;line-height:20px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
422
|
+
'.pmu-nameLink{display:block;max-width:100%;min-width:0;appearance:none;font:inherit;font-size:13px;line-height:20px;font-weight:600;text-align:left;padding:0;border:0;background:transparent;color:var(--dsw-alias-label-primary);cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
423
|
+
'.pmu-nameLink:hover{text-decoration:underline}',
|
|
424
|
+
'.pmu-nameLink:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px;border-radius:var(--dsw-radius-xs)}',
|
|
425
|
+
'.pmu-kindBadge{grid-column:3;justify-self:start}',
|
|
426
|
+
'.pmu-versions{grid-column:4;justify-self:start;font-family:var(--ds-font-family-code,monospace);font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary);white-space:nowrap}',
|
|
427
|
+
'.pmu-arrow{color:var(--dsw-alias-label-tertiary);padding:0 4px}',
|
|
428
|
+
'.pmu-spacer{grid-column:5;min-width:0}',
|
|
429
|
+
'.pmu-disabledBadge{grid-column:6;justify-self:start;white-space:nowrap}',
|
|
430
|
+
'.pmu-statusBadge{grid-column:7;justify-self:start;min-width:0;white-space:nowrap}',
|
|
431
|
+
'.pmu-rowActions{grid-column:8;display:flex;flex-wrap:wrap;align-items:center;justify-content:flex-end;gap:6px;min-width:0;max-width:100%;justify-self:end}',
|
|
432
|
+
// 窄屏收紧固定轨道并隐藏弹性空隙,避免整行横向滚动/重叠。
|
|
433
|
+
'@media (max-width:720px){.pmu-rowMain{grid-template-columns:auto minmax(0,1fr) 48px 120px minmax(6px,0.2fr) 48px 84px minmax(96px,auto);column-gap:6px}}',
|
|
434
|
+
'@media (max-width:560px){.pmu-rowMain{grid-template-columns:auto minmax(0,1fr) 44px 104px 0 44px 76px minmax(84px,auto);column-gap:4px}.pmu-spacer{display:none}}',
|
|
435
|
+
'@media (max-width:420px){.pmu-rowMain{grid-template-columns:auto minmax(0,1fr) 40px 84px 0 40px 64px minmax(64px,auto);column-gap:3px}}',
|
|
436
|
+
'.pmu-detail{display:flex;flex-direction:column;gap:6px;padding:8px 10px;border-radius:var(--dsw-radius-sm);background:var(--dsw-alias-bg-layer-2);font-size:12px;line-height:18px}',
|
|
437
|
+
'.pmu-log{max-height:180px;overflow:auto;margin:0;padding:8px 10px;border-radius:var(--dsw-radius-sm);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);font-family:var(--ds-font-family-code,monospace);font-size:11px;line-height:16px;white-space:pre-wrap;overflow-wrap:anywhere}',
|
|
438
|
+
'.pmu-selectAll{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--dsw-alias-label-secondary)}',
|
|
439
|
+
'.pmu-link{font:inherit;font-size:12px;line-height:18px;padding:0;border:0;background:transparent;color:var(--dsw-alias-link);cursor:pointer;text-decoration:underline}',
|
|
440
|
+
'.pmu-modalLayer{position:fixed;inset:0;z-index:60;display:flex;align-items:center;justify-content:center;padding:24px;background:var(--dsw-alias-bg-mask-1)}',
|
|
441
|
+
'.pmu-modal{display:flex;flex-direction:column;gap:10px;width:100%;max-width:520px;max-height:80vh;overflow:auto;padding:16px 18px;border:0.5px solid var(--dsw-alias-border-l3);border-radius:var(--dsw-radius-xl);background:var(--dsw-alias-bg-overlay);color:var(--dsw-alias-label-primary);box-shadow:0 8px 24px var(--dsw-alias-bg-mask-3)}',
|
|
442
|
+
'.pmu-modalTitle{margin:0;font-size:14px;font-weight:600;line-height:22px}',
|
|
443
|
+
'.pmu-modalBody{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere}',
|
|
444
|
+
'.pmu-modalActions{display:flex;align-items:center;gap:8px;justify-content:flex-end;flex-wrap:wrap;margin-top:4px}',
|
|
445
|
+
'.pmu-confirmRow{display:grid;grid-template-columns:minmax(90px,auto) 1fr;gap:4px 10px;font-size:12px;line-height:18px;padding:8px 10px;border-radius:var(--dsw-radius-sm);background:var(--dsw-alias-bg-layer-1)}',
|
|
446
|
+
'.pmu-confirmKey{color:var(--dsw-alias-label-tertiary)}',
|
|
447
|
+
'.pmu-confirmValue{overflow-wrap:anywhere}',
|
|
448
|
+
'.pmu-ack{display:flex;align-items:flex-start;gap:8px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-primary);cursor:pointer}',
|
|
449
|
+
'.pmu-progressHead{display:flex;align-items:center;gap:10px;flex-wrap:wrap}',
|
|
450
|
+
'.pmu-progressItem{display:flex;flex-direction:column;gap:5px;padding:8px 10px;border:0.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-1)}',
|
|
451
|
+
'.pmu-progressItem[data-current="true"]{border-color:var(--dsw-alias-border-selected)}',
|
|
452
|
+
'.pmu-progressTop{display:flex;align-items:center;gap:8px;flex-wrap:wrap}',
|
|
453
|
+
'.pmu-progressName{font-size:12px;line-height:18px;font-weight:600;overflow-wrap:anywhere}',
|
|
454
|
+
'.pmu-progressText{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}',
|
|
455
|
+
'.pmu-progressActions{margin-left:auto}',
|
|
456
|
+
'.pmu-summaryList{margin:0;padding-left:18px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}',
|
|
457
|
+
'.pmu-textarea{width:100%;min-height:56px;border-radius:var(--dsw-radius-md);border:0.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;line-height:18px;padding:6px 8px;resize:vertical}',
|
|
458
|
+
'.pmu-textarea:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:0}',
|
|
164
459
|
].join('\n')
|
|
165
460
|
|
|
461
|
+
/**
|
|
462
|
+
* 工厂级兜底翻译(宿主未注入 `t` 时用;语言切换仍由宿主重渲染驱动)。
|
|
463
|
+
* @param {string} key - 文案键。
|
|
464
|
+
* @param {object} [params] - 插值参数。
|
|
465
|
+
* @returns {string} 文案。
|
|
466
|
+
*/
|
|
467
|
+
function fallbackT(key, params) {
|
|
468
|
+
const dict = I18N.zh ?? {}
|
|
469
|
+
let out = typeof dict[key] === 'string' ? dict[key] : key
|
|
470
|
+
if (params !== null && typeof params === 'object') {
|
|
471
|
+
for (const name of Object.keys(params)) out = out.split(`{${name}}`).join(String(params[name]))
|
|
472
|
+
}
|
|
473
|
+
return out
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* 拼出本插件 API 的同源地址。
|
|
478
|
+
* @param {string} path - 以 `/` 开头的子路径,例如 `/updates`。
|
|
479
|
+
* @returns {string} 绝对路径。
|
|
480
|
+
*/
|
|
481
|
+
function api(path) {
|
|
482
|
+
const suffix = typeof path === 'string' && path.startsWith('/') ? path : `/${String(path ?? '')}`
|
|
483
|
+
if (suffix === API || suffix.startsWith(`${API}/`)) return suffix
|
|
484
|
+
if (suffix.startsWith('/api/')) return `${API}/status`
|
|
485
|
+
return `${API}${suffix}`
|
|
486
|
+
}
|
|
487
|
+
|
|
166
488
|
/**
|
|
167
489
|
* 字节数展示。
|
|
168
490
|
* @param {number|null|undefined} value - 字节数。
|
|
@@ -212,11 +534,70 @@ window.__ModuleLoader__.load({
|
|
|
212
534
|
}
|
|
213
535
|
|
|
214
536
|
/**
|
|
215
|
-
*
|
|
537
|
+
* 计算「筛选」菜单落点:默认贴按钮下方,下方放不下就向上换向;水平方向贴边不出视口。
|
|
538
|
+
* @param {{left?: number, right?: number, top?: number, bottom?: number}} anchor - 按钮矩形。
|
|
539
|
+
* @param {{width?: number, height?: number}} viewport - 视口尺寸。
|
|
540
|
+
* @param {{width?: number, height?: number}} menu - 菜单尺寸。
|
|
541
|
+
* @param {number} [gap] - 与按钮的间距。
|
|
542
|
+
* @returns {{left: number, top: number, placement: 'bottom'|'top'}} 落点。
|
|
543
|
+
*/
|
|
544
|
+
function menuPlacement(anchor, viewport, menu, gap = 6) {
|
|
545
|
+
const margin = 8
|
|
546
|
+
const viewportWidth = num(viewport?.width, 0)
|
|
547
|
+
const viewportHeight = num(viewport?.height, 0)
|
|
548
|
+
const menuWidth = num(menu?.width, 0)
|
|
549
|
+
const menuHeight = num(menu?.height, 0)
|
|
550
|
+
const maxLeft = Math.max(margin, viewportWidth - menuWidth - margin)
|
|
551
|
+
const left = Math.max(margin, Math.min(num(anchor?.left, 0), maxLeft))
|
|
552
|
+
const below = num(anchor?.bottom, 0) + gap
|
|
553
|
+
const above = num(anchor?.top, 0) - gap - menuHeight
|
|
554
|
+
const fitsBelow = viewportHeight === 0 || below + menuHeight <= viewportHeight - margin
|
|
555
|
+
const placement = fitsBelow || above < margin ? 'bottom' : 'top'
|
|
556
|
+
return { left, top: placement === 'bottom' ? below : above, placement }
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* 量出「筛选」菜单的落点(真实浏览器);拿不到布局信息时返回 null,退化为纯 CSS 定位。
|
|
561
|
+
* @param {object} node - filterWrap 元素。
|
|
562
|
+
* @returns {{left: number, top: number, placement: 'bottom'|'top'}|null} 落点。
|
|
563
|
+
*/
|
|
564
|
+
function measureMenuPlacement(node) {
|
|
565
|
+
try {
|
|
566
|
+
if (typeof node?.getBoundingClientRect !== 'function') return null
|
|
567
|
+
const rect = node.getBoundingClientRect()
|
|
568
|
+
if (!(rect.width > 0)) return null
|
|
569
|
+
const viewport = {
|
|
570
|
+
width: typeof window === 'undefined' ? 0 : num(window.innerWidth, 0),
|
|
571
|
+
height: typeof window === 'undefined' ? 0 : num(window.innerHeight, 0),
|
|
572
|
+
}
|
|
573
|
+
// 菜单尺寸用声明的上下限估算(min-width 220 / max-width min(320px,92vw)、两行 + 内边距)。
|
|
574
|
+
const menu = { width: 240, height: 108 }
|
|
575
|
+
return menuPlacement(rect, viewport, menu)
|
|
576
|
+
} catch {
|
|
577
|
+
return null
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* 只显示时分的本地时间(头部「上次检查 HH:MM」)。
|
|
583
|
+
* @param {number|null|undefined} timestamp - Unix 毫秒。
|
|
584
|
+
* @returns {string} 展示文本。
|
|
585
|
+
*/
|
|
586
|
+
function formatTimeOnly(timestamp) {
|
|
587
|
+
if (typeof timestamp !== 'number' || !Number.isFinite(timestamp)) return '—'
|
|
588
|
+
try {
|
|
589
|
+
return new Date(timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
|
590
|
+
} catch {
|
|
591
|
+
return new Date(timestamp).toISOString().slice(11, 16)
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* 索引源缓存状态徽标(与「可更新」的行状态徽标同名会互相覆盖,故加 Source 前缀)。
|
|
216
597
|
* @param {{state: string, t: Function}} props - 源状态与翻译函数。
|
|
217
598
|
* @returns {object} React 元素。
|
|
218
599
|
*/
|
|
219
|
-
function
|
|
600
|
+
function SourceStatusBadge({ state, t }) {
|
|
220
601
|
const tone = state === 'ok' ? 'ok' : state === 'stale' ? 'warn' : state === 'error' ? 'bad' : 'idle'
|
|
221
602
|
const label = state === 'ok' ? t('statusOk') : state === 'stale' ? t('statusStale') : state === 'error' ? t('statusError') : t('statusEmpty')
|
|
222
603
|
return h('span', { className: 'pmp-badge', 'data-tone': tone },
|
|
@@ -254,7 +635,7 @@ window.__ModuleLoader__.load({
|
|
|
254
635
|
const [draft, setDraft] = React.useState('')
|
|
255
636
|
const alive = React.useRef(true)
|
|
256
637
|
|
|
257
|
-
const load = React.useCallback(async () => {
|
|
638
|
+
const load = React.useCallback(async (skipResume) => {
|
|
258
639
|
try {
|
|
259
640
|
const response = await fetch(`${API}/status`, { headers: { accept: 'application/json' } })
|
|
260
641
|
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
@@ -372,8 +753,8 @@ window.__ModuleLoader__.load({
|
|
|
372
753
|
}
|
|
373
754
|
}
|
|
374
755
|
|
|
375
|
-
|
|
376
|
-
|
|
756
|
+
// 作为 plugins.tab 的内容:tab 标签已是「插件源缓存」,这里不再重复标题。
|
|
757
|
+
return h('div', { className: 'pmp-page pmp-tabPage' },
|
|
377
758
|
h('p', { className: 'pmp-intro' }, t('intro')),
|
|
378
759
|
|
|
379
760
|
notice !== null && h('p', { className: 'pmp-notice', 'data-tone': notice.tone }, notice.text),
|
|
@@ -423,7 +804,7 @@ window.__ModuleLoader__.load({
|
|
|
423
804
|
sources.map((source) => h('div', { className: 'pmp-card', key: source.id },
|
|
424
805
|
h('div', { className: 'pmp-cardHead' },
|
|
425
806
|
h('h3', { className: 'pmp-cardTitle' }, source.title || t('unknownTitle')),
|
|
426
|
-
h(
|
|
807
|
+
h(SourceStatusBadge, { state: source.state, t }),
|
|
427
808
|
source.refreshing === true && h('span', { className: 'pmp-badge' }, t('refreshing')),
|
|
428
809
|
),
|
|
429
810
|
h('p', { className: 'pmp-url' }, source.url),
|
|
@@ -455,31 +836,1562 @@ window.__ModuleLoader__.load({
|
|
|
455
836
|
)
|
|
456
837
|
}
|
|
457
838
|
|
|
839
|
+
/** 进度阶段(Host 桥的 stage 取值)→ 文案键。自检脚本会读它校验覆盖。 */
|
|
840
|
+
const PROGRESS_STAGES = {
|
|
841
|
+
pending: 'stagePending',
|
|
842
|
+
waiting: 'stagePending',
|
|
843
|
+
queued: 'stagePending',
|
|
844
|
+
checking: 'stageChecking',
|
|
845
|
+
checking_compatibility: 'stageChecking',
|
|
846
|
+
removing: 'stageRemoving',
|
|
847
|
+
installing: 'stageInstalling',
|
|
848
|
+
restoring: 'stageRestoring',
|
|
849
|
+
restore: 'stageRestoring',
|
|
850
|
+
restoring_previous: 'stageRestoring',
|
|
851
|
+
done: 'stageDone',
|
|
852
|
+
finished: 'stageDone',
|
|
853
|
+
success: 'stageDone',
|
|
854
|
+
failed: 'stageFailed',
|
|
855
|
+
error: 'stageFailed',
|
|
856
|
+
restart: 'stageRestart',
|
|
857
|
+
restart_required: 'stageRestart',
|
|
858
|
+
cancelled: 'stageCancelled',
|
|
859
|
+
canceled: 'stageCancelled',
|
|
860
|
+
skipped: 'stageSkipped',
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/** 状态徽标文案键(按优先级从高到低)。 */
|
|
864
|
+
const STATUS_LABEL_KEYS = {
|
|
865
|
+
incompatible: 'updatesStateIncompatible',
|
|
866
|
+
failed: 'updatesStateFailed',
|
|
867
|
+
skipped: 'updatesStateSkipped',
|
|
868
|
+
current: 'updatesStateCurrent',
|
|
869
|
+
uncheckable: 'updatesStateUncheckable',
|
|
870
|
+
unknown: 'updatesStateUnknown',
|
|
871
|
+
deprecated: 'updatesStateDeprecated',
|
|
872
|
+
prerelease: 'updatesStatePrerelease',
|
|
873
|
+
updatable: 'updatesStateUpdatable',
|
|
874
|
+
exempted: 'updatesStateExempted',
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/** 状态徽标配色。 */
|
|
878
|
+
const STATUS_TONES = {
|
|
879
|
+
updatable: 'ok',
|
|
880
|
+
exempted: 'ok',
|
|
881
|
+
incompatible: 'bad',
|
|
882
|
+
failed: 'bad',
|
|
883
|
+
skipped: 'warn',
|
|
884
|
+
uncheckable: 'warn',
|
|
885
|
+
current: 'idle',
|
|
886
|
+
unknown: 'idle',
|
|
887
|
+
deprecated: 'warn',
|
|
888
|
+
prerelease: 'warn',
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/** 过滤键 → 文案键。 */
|
|
892
|
+
/** 齿轮(设置)图标 path(Feather settings,24×24 视框)。 */
|
|
893
|
+
const GEAR_PATH = 'M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z'
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* 自检脚本读取的纯逻辑/常量出口(不参与运行时行为)。
|
|
897
|
+
* @returns {object} 常量集合。
|
|
898
|
+
*/
|
|
899
|
+
function inspectable() {
|
|
900
|
+
return {
|
|
901
|
+
namespace: NS,
|
|
902
|
+
updatesApi: UPDATES_API,
|
|
903
|
+
slot: UPDATES_SLOT,
|
|
904
|
+
id: UPDATES_ID,
|
|
905
|
+
order: UPDATES_ORDER,
|
|
906
|
+
stages: PROGRESS_STAGES,
|
|
907
|
+
statusLabels: STATUS_LABEL_KEYS,
|
|
908
|
+
statusTones: STATUS_TONES,
|
|
909
|
+
scopeStates: SCOPE_STATES,
|
|
910
|
+
failedScopeStates: FAILED_SCOPE_STATES,
|
|
911
|
+
inScope,
|
|
912
|
+
dict: I18N,
|
|
913
|
+
css: CSS,
|
|
914
|
+
requirementLines,
|
|
915
|
+
incompatibilityOf,
|
|
916
|
+
readProgress,
|
|
917
|
+
progressTerminal,
|
|
918
|
+
restoreText,
|
|
919
|
+
statusOf,
|
|
920
|
+
uncheckableReasonText,
|
|
921
|
+
menuPlacement,
|
|
922
|
+
readSettings,
|
|
923
|
+
mergeSettings,
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* 安全取字符串。
|
|
929
|
+
* @param {unknown} value - 原始值。
|
|
930
|
+
* @param {string} [fallback] - 兜底。
|
|
931
|
+
* @returns {string} 字符串。
|
|
932
|
+
*/
|
|
933
|
+
function text(value, fallback = '') {
|
|
934
|
+
if (typeof value === 'string') return value
|
|
935
|
+
if (typeof value === 'number' && Number.isFinite(value)) return String(value)
|
|
936
|
+
return fallback
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* 安全取数字。
|
|
941
|
+
* @param {unknown} value - 原始值。
|
|
942
|
+
* @param {number} [fallback] - 兜底。
|
|
943
|
+
* @returns {number} 数字。
|
|
944
|
+
*/
|
|
945
|
+
function num(value, fallback = 0) {
|
|
946
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value
|
|
947
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
948
|
+
const parsed = Number(value)
|
|
949
|
+
if (Number.isFinite(parsed)) return parsed
|
|
950
|
+
}
|
|
951
|
+
return fallback
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* 安全取布尔。
|
|
956
|
+
* @param {unknown} value - 原始值。
|
|
957
|
+
* @returns {boolean} 布尔。
|
|
958
|
+
*/
|
|
959
|
+
function bool(value) {
|
|
960
|
+
return value === true || value === 'true'
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* 安全取数组。
|
|
965
|
+
* @param {unknown} value - 原始值。
|
|
966
|
+
* @returns {Array} 数组。
|
|
967
|
+
*/
|
|
968
|
+
function list(value) {
|
|
969
|
+
return Array.isArray(value) ? value : []
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
/**
|
|
973
|
+
* 安全取对象。
|
|
974
|
+
* @param {unknown} value - 原始值。
|
|
975
|
+
* @returns {object} 对象。
|
|
976
|
+
*/
|
|
977
|
+
function rec(value) {
|
|
978
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : {}
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* 行/豁免的稳定键:包名 + 目标版本。
|
|
983
|
+
* @param {string} name - 包名。
|
|
984
|
+
* @param {string} latest - 目标版本。
|
|
985
|
+
* @returns {string} 键。
|
|
986
|
+
*/
|
|
987
|
+
function cellKey(name, latest) {
|
|
988
|
+
return `${name}@${latest === '' ? '?' : latest}`
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* 判断目标版本是否预发布(SemVer 的 `-` 段)。
|
|
993
|
+
* @param {string} version - 版本号。
|
|
994
|
+
* @returns {boolean} 是否预发布。
|
|
995
|
+
*/
|
|
996
|
+
function isPrereleaseVersion(version) {
|
|
997
|
+
if (typeof version !== 'string' || version === '') return false
|
|
998
|
+
return version.split('+')[0].includes('-')
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* 从 package.json 风格的 peer 依赖里摘出 DSH 条目。
|
|
1003
|
+
* @param {object} manifest - manifest 片段。
|
|
1004
|
+
* @returns {Array<{name: string, range: string}>} DSH 相关依赖。
|
|
1005
|
+
*/
|
|
1006
|
+
function dshPeers(manifest) {
|
|
1007
|
+
const merged = Object.assign({}, rec(manifest.peerDependencies), rec(manifest.peerDependenciesMeta))
|
|
1008
|
+
const out = []
|
|
1009
|
+
for (const name of Object.keys(merged)) {
|
|
1010
|
+
if (!name.startsWith('@deepseek-ai/dsh')) continue
|
|
1011
|
+
const value = merged[name]
|
|
1012
|
+
const range = typeof value === 'string' ? value : text(rec(value).range)
|
|
1013
|
+
out.push({ name, range: range === '' ? '—' : range })
|
|
1014
|
+
}
|
|
1015
|
+
return out
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/** 旧结构里由专门分支处理的键(不当成「要求名 → 范围」)。 */
|
|
1019
|
+
const REQUIREMENT_STRUCTURED_KEYS = new Set(['dsh', 'enginesDsh', 'required', 'manifest', 'missing'])
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* 把 Host 的 `incompatible` 归一成 `{runtimeVersion, requirements}`。
|
|
1023
|
+
*
|
|
1024
|
+
* 真实契约(DSH `evaluatePluginCompatibility` → `incompatiblePlugin`)给的是对象:
|
|
1025
|
+
* `{name, version, runtimeVersion, requirements: {'engines.dsh': '>=x'}}`,不是布尔。
|
|
1026
|
+
* 优先认显式归一字段 `incompatibility` / `incompatibleInfo`,其余形态(布尔、字符串)兜底。
|
|
1027
|
+
* @param {object} info - 一条候选信息。
|
|
1028
|
+
* @returns {{runtimeVersion: string, requirements: object, version: string}|null} 归一结果。
|
|
1029
|
+
*/
|
|
1030
|
+
function incompatibilityOf(info) {
|
|
1031
|
+
const source = rec(info)
|
|
1032
|
+
const explicit = rec(source.incompatibility ?? source.incompatibleInfo)
|
|
1033
|
+
if (Object.keys(explicit).length > 0) {
|
|
1034
|
+
return {
|
|
1035
|
+
runtimeVersion: text(explicit.runtimeVersion) || text(source.runtimeVersion),
|
|
1036
|
+
requirements: rec(explicit.requirements),
|
|
1037
|
+
version: text(explicit.version),
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
const raw = source.incompatible
|
|
1041
|
+
if (raw === true) return { runtimeVersion: text(source.runtimeVersion), requirements: {}, version: '' }
|
|
1042
|
+
if (raw !== null && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
1043
|
+
const payload = rec(raw)
|
|
1044
|
+
if (Object.keys(payload).length === 0) return null
|
|
1045
|
+
return {
|
|
1046
|
+
runtimeVersion: text(payload.runtimeVersion) || text(source.runtimeVersion),
|
|
1047
|
+
requirements: rec(payload.requirements),
|
|
1048
|
+
version: text(payload.version),
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
if (text(raw) === 'true') return { runtimeVersion: text(source.runtimeVersion), requirements: {}, version: '' }
|
|
1052
|
+
return null
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* 目标版本不满足项展示文本(逐行)。
|
|
1057
|
+
*
|
|
1058
|
+
* 真实契约的 `requirements` 是「要求名 → 范围」的扁平记录
|
|
1059
|
+
* (如 `{'engines.dsh': '>=0.4.0 <0.5.0'}`),这里逐项输出 `key range`;
|
|
1060
|
+
* 同时兼容早期结构的 `{dsh, required, manifest, missing}`。空/缺省时不产出任何行。
|
|
1061
|
+
* @param {object} incompatibility - 目标版本的不兼容信息。
|
|
1062
|
+
* @returns {string[]} 逐行文本。
|
|
1063
|
+
*/
|
|
1064
|
+
function requirementLines(incompatibility) {
|
|
1065
|
+
const lines = []
|
|
1066
|
+
const requirement = rec(rec(incompatibility).requirements)
|
|
1067
|
+
for (const [key, value] of Object.entries(requirement)) {
|
|
1068
|
+
if (REQUIREMENT_STRUCTURED_KEYS.has(key)) continue
|
|
1069
|
+
const raw = typeof value === 'string' ? value : (typeof value === 'number' ? String(value) : text(rec(value).range))
|
|
1070
|
+
const range = text(raw)
|
|
1071
|
+
lines.push(range === '' ? key : `${key} ${range}`)
|
|
1072
|
+
}
|
|
1073
|
+
const engine = text(requirement.dsh) || text(requirement.enginesDsh)
|
|
1074
|
+
if (engine !== '') lines.push(`engines.dsh ${engine}`)
|
|
1075
|
+
const required = requirement.required
|
|
1076
|
+
if (typeof required === 'string' && required !== '') lines.push(required)
|
|
1077
|
+
if (Array.isArray(required)) {
|
|
1078
|
+
for (const entry of required) {
|
|
1079
|
+
const item = rec(entry)
|
|
1080
|
+
const name = text(item.name) || text(entry)
|
|
1081
|
+
if (name === '') continue
|
|
1082
|
+
const range = text(item.range)
|
|
1083
|
+
lines.push(range === '' ? name : `${name} ${range}`)
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
for (const peer of dshPeers(rec(requirement.manifest))) lines.push(`${peer.name} ${peer.range}`)
|
|
1087
|
+
for (const item of list(requirement.missing)) {
|
|
1088
|
+
const value = text(item)
|
|
1089
|
+
if (value !== '') lines.push(value)
|
|
1090
|
+
}
|
|
1091
|
+
return [...new Set(lines)]
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/**
|
|
1095
|
+
* 阶段文案。
|
|
1096
|
+
* @param {string} stage - 阶段值。
|
|
1097
|
+
* @param {(key: string, params?: object) => string} t - 翻译函数。
|
|
1098
|
+
* @returns {string} 文案。
|
|
1099
|
+
*/
|
|
1100
|
+
function stageLabel(stage, t) {
|
|
1101
|
+
const key = PROGRESS_STAGES[text(stage)]
|
|
1102
|
+
return typeof key === 'string' ? t(key) : text(stage, t('updatesUnknown'))
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/**
|
|
1106
|
+
* 从桥接信息里推断展示状态。
|
|
1107
|
+
* @param {object} info - 一条候选信息。
|
|
1108
|
+
* @returns {string} 状态键。
|
|
1109
|
+
*/
|
|
1110
|
+
function rowState(info) {
|
|
1111
|
+
const raw = text(info.state)
|
|
1112
|
+
// Host 桥的权威取值:available|skipped|current|uncheckable|unknown|error
|
|
1113
|
+
if (raw === 'available') return 'updatable'
|
|
1114
|
+
if (raw === 'skipped' || raw === 'current' || raw === 'unknown') return raw
|
|
1115
|
+
if (raw === 'uncheckable') return 'uncheckable'
|
|
1116
|
+
if (raw === 'error' || raw === 'check-failed' || raw === 'check_failed' || raw === 'failed') return 'failed'
|
|
1117
|
+
if (raw === 'incompatible' || raw === 'updatable' || raw === 'prerelease' || raw === 'deprecated' || raw === 'disabled') return raw
|
|
1118
|
+
if (info.checkable === false || text(info.checkError) !== '' || text(info.error) !== '') return info.checkable === false ? 'uncheckable' : 'failed'
|
|
1119
|
+
if (incompatibilityOf(info) !== null) return 'incompatible'
|
|
1120
|
+
if (info.deprecated === true || text(info.deprecated) !== '') return 'deprecated'
|
|
1121
|
+
if (info.prerelease === true || isPrereleaseVersion(text(info.latest))) return 'prerelease'
|
|
1122
|
+
if (info.enabled === false) return 'disabled'
|
|
1123
|
+
return 'updatable'
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
/**
|
|
1127
|
+
* 把 Host 桥返回的一条候选归一成渲染用的行。
|
|
1128
|
+
* @param {object} raw - 原始条目。
|
|
1129
|
+
* @param {number} index - 下标(兜底 key)。
|
|
1130
|
+
* @returns {object|null} 行;缺少包名时返回 null。
|
|
1131
|
+
*/
|
|
1132
|
+
function toRow(raw, index) {
|
|
1133
|
+
const info = rec(raw)
|
|
1134
|
+
const name = text(info.name) || text(info.packageName) || text(info.package)
|
|
1135
|
+
if (name === '') return null
|
|
1136
|
+
// 真实契约:listVersions().incompatible 是 {name,version,runtimeVersion,requirements}。
|
|
1137
|
+
const incompatibility = incompatibilityOf(info)
|
|
1138
|
+
const latest = text(info.latest) || text(info.targetVersion) || text(info.latestVersion) || text(info.to)
|
|
1139
|
+
|| text(incompatibility?.version)
|
|
1140
|
+
const current = text(info.current) || text(info.currentVersion) || text(info.version) || text(info.from)
|
|
1141
|
+
const deprecatedReason = text(info.deprecated)
|
|
1142
|
+
// 来源内部统一用 'npm':Host 新契约给 'npm',旧数据可能仍是 'registry',都归一为 'npm'。
|
|
1143
|
+
const rawKind = text(info.kind)
|
|
1144
|
+
const kind = rawKind === 'git' ? 'git' : (rawKind === 'npm' || rawKind === 'registry' ? 'npm' : '')
|
|
1145
|
+
return {
|
|
1146
|
+
key: cellKey(name, latest),
|
|
1147
|
+
name,
|
|
1148
|
+
current,
|
|
1149
|
+
latest,
|
|
1150
|
+
kind,
|
|
1151
|
+
state: rowState(info),
|
|
1152
|
+
enabled: info.enabled !== false,
|
|
1153
|
+
spec: text(info.spec),
|
|
1154
|
+
registry: text(info.registry),
|
|
1155
|
+
repository: text(info.repository),
|
|
1156
|
+
location: text(info.location) || text(info.origin),
|
|
1157
|
+
directory: text(info.directory),
|
|
1158
|
+
commit: text(info.commit),
|
|
1159
|
+
incompatible: incompatibility !== null || text(info.state) === 'incompatible',
|
|
1160
|
+
incompatibility,
|
|
1161
|
+
prerelease: info.prerelease === true || isPrereleaseVersion(latest),
|
|
1162
|
+
deprecated: info.deprecated === true || deprecatedReason !== '',
|
|
1163
|
+
deprecatedReason,
|
|
1164
|
+
reason: text(info.reason),
|
|
1165
|
+
checkError: text(info.checkError) || text(info.error),
|
|
1166
|
+
restore: null,
|
|
1167
|
+
restartRequired: false,
|
|
1168
|
+
log: '',
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* 行是否可在「更新全部 / 全选」里被自动勾选(严格按当前两个开关)。
|
|
1174
|
+
* skipped(目标预发布/已废弃而开关关着)默认不勾选;incompatible / uncheckable /
|
|
1175
|
+
* current / unknown / error 一律不自动勾选。
|
|
1176
|
+
* @param {object} row - 行。
|
|
1177
|
+
* @param {{includeDisabled: boolean, includePrerelease: boolean}} settings - 当前开关。
|
|
1178
|
+
* @returns {boolean} 是否可自动勾选。
|
|
1179
|
+
*/
|
|
1180
|
+
function autoSelectable(row, settings) {
|
|
1181
|
+
if (row.latest === '') return false
|
|
1182
|
+
if (row.incompatible === true) return false
|
|
1183
|
+
switch (row.state) {
|
|
1184
|
+
case 'updatable': return true
|
|
1185
|
+
case 'skipped': return settings.includePrerelease === true
|
|
1186
|
+
case 'prerelease':
|
|
1187
|
+
case 'deprecated': return settings.includePrerelease === true
|
|
1188
|
+
case 'disabled': return settings.includeDisabled === true
|
|
1189
|
+
default: return false
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
/**
|
|
1194
|
+
* 不兼容行是否可以先豁免再更新(无法检查/无更新/检查失败的不行)。
|
|
1195
|
+
* @param {object} row - 行。
|
|
1196
|
+
* @returns {boolean} 是否可走豁免流程。
|
|
1197
|
+
*/
|
|
1198
|
+
function canExempt(row) {
|
|
1199
|
+
if (row.incompatible !== true || row.latest === '') return false
|
|
1200
|
+
return !['uncheckable', 'current', 'unknown', 'failed'].includes(row.state)
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
* 行是否允许手动勾选/单独更新(不兼容需先豁免,无法检查/无更新/检查失败不允许)。
|
|
1205
|
+
* @param {object} row - 行。
|
|
1206
|
+
* @returns {boolean} 是否可选。
|
|
1207
|
+
*/
|
|
1208
|
+
function selectableRow(row) {
|
|
1209
|
+
if (row.latest === '') return false
|
|
1210
|
+
if (row.incompatible === true) return false
|
|
1211
|
+
return ![
|
|
1212
|
+
'failed', 'uncheckable', 'current', 'unknown', 'incompatible',
|
|
1213
|
+
].includes(row.state)
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* 「更新全部」可安装集合:目标存在、不是不兼容/无法检查/无更新,且按开关过滤。
|
|
1218
|
+
* @param {object[]} rows - 可见行。
|
|
1219
|
+
* @param {{includeDisabled: boolean, includePrerelease: boolean}} settings - 当前开关。
|
|
1220
|
+
* @returns {object[]} 可安装行。
|
|
1221
|
+
*/
|
|
1222
|
+
/** 基础范围:有更新的项(默认显示)。 */
|
|
1223
|
+
const SCOPE_STATES = ['updatable', 'skipped', 'incompatible']
|
|
1224
|
+
/** 需要「显示检查失败的项」开关才纳入的项。 */
|
|
1225
|
+
const FAILED_SCOPE_STATES = ['failed', 'uncheckable', 'unknown']
|
|
1226
|
+
|
|
1227
|
+
/**
|
|
1228
|
+
* 列表基础范围:默认只显示有更新的项;打开「显示检查失败的项」后追加失败/无法检查/未检查的项。
|
|
1229
|
+
* @param {object} row - 行。
|
|
1230
|
+
* @param {boolean} showFailed - 是否显示检查失败的项。
|
|
1231
|
+
* @returns {boolean} 是否纳入。
|
|
1232
|
+
*/
|
|
1233
|
+
function inScope(row, showFailed) {
|
|
1234
|
+
const state = text(row?.state)
|
|
1235
|
+
if (SCOPE_STATES.includes(state)) return true
|
|
1236
|
+
return showFailed === true && FAILED_SCOPE_STATES.includes(state)
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
/**
|
|
1240
|
+
* 「更新全部 / 全选」的可安装集合(按当前两个开关)。
|
|
1241
|
+
* @param {object[]} rows - 可见行。
|
|
1242
|
+
* @param {{includeDisabled: boolean, includePrerelease: boolean}} settings - 当前开关。
|
|
1243
|
+
* @returns {object[]} 可安装行。
|
|
1244
|
+
*/
|
|
1245
|
+
function installableRows(rows, settings) {
|
|
1246
|
+
return rows.filter(row => autoSelectable(row, settings))
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
/**
|
|
1250
|
+
* 行是否落在当前两个开关的显示范围内。
|
|
1251
|
+
* @param {object} row - 行。
|
|
1252
|
+
* @param {{includeDisabled: boolean, includePrerelease: boolean}} settings - 当前开关。
|
|
1253
|
+
* @returns {boolean} 是否显示。
|
|
1254
|
+
*/
|
|
1255
|
+
function visibleBySettings(row, settings) {
|
|
1256
|
+
if (row.enabled === false && settings.includeDisabled !== true) return false
|
|
1257
|
+
if (row.state === 'prerelease' || row.state === 'deprecated' || row.state === 'skipped') {
|
|
1258
|
+
// skipped 由 Host 明确给出「显示但不勾选」,即使开关关着也显示。
|
|
1259
|
+
return row.state === 'skipped' ? true : settings.includePrerelease === true
|
|
1260
|
+
}
|
|
1261
|
+
if (row.state === 'disabled') return settings.includeDisabled === true
|
|
1262
|
+
return true
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* 合并 /updates 的 settings 与 /settings 的返回,兼容两套字段名。
|
|
1267
|
+
* @param {object} payload - 响应体。
|
|
1268
|
+
* @returns {{includeDisabled: boolean, includePrerelease: boolean, settable: boolean}} 设置。
|
|
1269
|
+
*/
|
|
1270
|
+
function readSettings(payload) {
|
|
1271
|
+
const source = rec(payload)
|
|
1272
|
+
const status = rec(source.status)
|
|
1273
|
+
// 两个开关可能出现在顶层 config(GET /updates)或一层嵌套的 status.config(POST /settings)。
|
|
1274
|
+
const nested = Object.assign({},
|
|
1275
|
+
rec(status.config), rec(status.settings), rec(status.updates),
|
|
1276
|
+
rec(source.config), rec(source.settings), rec(source.updates))
|
|
1277
|
+
const flat = Object.assign({}, nested, source)
|
|
1278
|
+
/**
|
|
1279
|
+
* 取第一个出现的值;全部缺席时返回 undefined(表示「响应里没说」,调用方不得据此覆盖本地状态)。
|
|
1280
|
+
* @param {...string} keys - 候选键。
|
|
1281
|
+
* @returns {boolean|undefined} 值。
|
|
1282
|
+
*/
|
|
1283
|
+
const pick = (...keys) => {
|
|
1284
|
+
for (const key of keys) {
|
|
1285
|
+
if (flat[key] !== undefined) return bool(flat[key])
|
|
1286
|
+
}
|
|
1287
|
+
return undefined
|
|
1288
|
+
}
|
|
1289
|
+
const includeDisabled = pick('updatesIncludeDisabled', 'includeDisabled')
|
|
1290
|
+
const includePrerelease = pick('updatesIncludePrerelease', 'includePrerelease')
|
|
1291
|
+
// Host:GET /updates 的 config.showFailed;POST /settings 的 status.config.updatesShowFailed。
|
|
1292
|
+
const showFailed = pick('updatesShowFailed', 'showFailed')
|
|
1293
|
+
const settable = source.settable === false || status.settable === false || nested.settable === false
|
|
1294
|
+
|| source.writable === false || source.saved === false ? false : true
|
|
1295
|
+
return {
|
|
1296
|
+
includeDisabled,
|
|
1297
|
+
includePrerelease,
|
|
1298
|
+
showFailed,
|
|
1299
|
+
settable,
|
|
1300
|
+
// 是否真的从响应里解析到了开关值(false 时调用方保持乐观值,等 GET /updates 校准)。
|
|
1301
|
+
known: includeDisabled !== undefined || includePrerelease !== undefined || showFailed !== undefined,
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
/**
|
|
1306
|
+
* 只把响应里确实提供的开关并入本地状态(避免缺席字段被当成 false 覆盖)。
|
|
1307
|
+
* @param {object} previous - 当前状态。
|
|
1308
|
+
* @param {{includeDisabled?: boolean, includePrerelease?: boolean, settable?: boolean}} incoming - 解析结果。
|
|
1309
|
+
* @returns {object} 新状态。
|
|
1310
|
+
*/
|
|
1311
|
+
function mergeSettings(previous, incoming) {
|
|
1312
|
+
const next = Object.assign({}, previous)
|
|
1313
|
+
if (incoming?.includeDisabled !== undefined) next.includeDisabled = incoming.includeDisabled
|
|
1314
|
+
if (incoming?.includePrerelease !== undefined) next.includePrerelease = incoming.includePrerelease
|
|
1315
|
+
if (incoming?.showFailed !== undefined) next.showFailed = incoming.showFailed
|
|
1316
|
+
if (incoming?.settable !== undefined) next.settable = incoming.settable
|
|
1317
|
+
return next
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
/**
|
|
1321
|
+
* 归一 /updates/apply 的返回(Host 契约:`{ok,started,requestIds[],items[]}`)。
|
|
1322
|
+
* @param {object} payload - 响应体。
|
|
1323
|
+
* @returns {{ok: boolean, requestId: string, message: string}} 入队结果。
|
|
1324
|
+
*/
|
|
1325
|
+
function applyAck(payload) {
|
|
1326
|
+
const source = rec(payload)
|
|
1327
|
+
const state = rec(source.state)
|
|
1328
|
+
const requestIds = list(source.requestIds).map(item => text(item)).filter(item => item !== '')
|
|
1329
|
+
const requestId = requestIds[0] ?? (text(source.requestId) || text(state.requestId) || text(source.id))
|
|
1330
|
+
return {
|
|
1331
|
+
ok: source.ok !== false && source.started !== false,
|
|
1332
|
+
requestId,
|
|
1333
|
+
message: text(source.message) || text(source.error),
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
|
|
458
1337
|
/**
|
|
459
|
-
*
|
|
460
|
-
*
|
|
1338
|
+
* 取进度项的错误正文(Host 的 `error` 是字符串;对象时取 diagnostic/message/code)。
|
|
1339
|
+
* 取消项被 Host 写入的 `error:'cancelled'` 不是错误正文,返回空串。
|
|
1340
|
+
* @param {object} raw - 队列项。
|
|
1341
|
+
* @returns {string} 错误文本。
|
|
1342
|
+
*/
|
|
1343
|
+
function progressError(raw) {
|
|
1344
|
+
const value = raw.error
|
|
1345
|
+
if (value !== null && typeof value === 'object') {
|
|
1346
|
+
const nested = rec(value)
|
|
1347
|
+
return text(nested.diagnostic) || text(nested.message) || text(nested.code)
|
|
1348
|
+
}
|
|
1349
|
+
const message = text(value) || text(raw.message)
|
|
1350
|
+
const lower = message.toLowerCase()
|
|
1351
|
+
// Host 的 markCancelled 会把 error 写成 'cancelled',那不是错误正文。
|
|
1352
|
+
if (lower === 'cancelled' || lower === 'canceled') return ''
|
|
1353
|
+
return message
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
/**
|
|
1357
|
+
* 归一 `/updates/state`(Host 契约:顶层 `{running,starting,stopped,finished,summary,active,activeRequestId,items,logs,lastRun,checkedAt}`)。
|
|
1358
|
+
*
|
|
1359
|
+
* 关键点:Host 的队列项初始就是 `success:false / failed:false / cancelled:false`,
|
|
1360
|
+
* 所以「失败」只能看 `failed===true`(或 stage/error),「终态」看 `success/failed/cancelled/
|
|
1361
|
+
* restartRequired` 或终态 stage;`queued`/`checking`/`installing` 等都不是终态。
|
|
1362
|
+
* pnpm 日志在**顶层** `logs`(当前 active 项的尾巴),按 `activeRequestId`/`active` 归到该项。
|
|
1363
|
+
* @param {object} payload - 响应体。
|
|
1364
|
+
* @returns {{requestId: string, status: string, items: Array, summary: object, running: boolean}} 进度。
|
|
1365
|
+
*/
|
|
1366
|
+
function readProgress(payload) {
|
|
1367
|
+
const source = rec(payload)
|
|
1368
|
+
const state = Object.keys(rec(source.state)).length > 0 ? rec(source.state) : source
|
|
1369
|
+
const rawItems = list(state.items ?? source.items)
|
|
1370
|
+
const running = state.running === true
|
|
1371
|
+
const activeName = text(state.active) || text(source.active)
|
|
1372
|
+
const activeRequestId = text(state.activeRequestId) || text(source.activeRequestId)
|
|
1373
|
+
const topLogs = list(state.logs ?? source.logs).map(entry => text(entry)).filter(entry => entry !== '')
|
|
1374
|
+
const normalized = rawItems.map((item, index) => {
|
|
1375
|
+
const raw = rec(item)
|
|
1376
|
+
const name = text(raw.name) || text(raw.packageName) || `#${index + 1}`
|
|
1377
|
+
const requestId = text(raw.requestId) || text(raw.id)
|
|
1378
|
+
const stage = text(raw.stage) || text(raw.status)
|
|
1379
|
+
const isActive = (activeRequestId !== '' && requestId === activeRequestId)
|
|
1380
|
+
|| ((activeRequestId === '' || requestId === '') && activeName !== '' && name === activeName)
|
|
1381
|
+
const ownLogs = list(raw.logs).map(entry => text(entry)).filter(entry => entry !== '')
|
|
1382
|
+
const log = ownLogs.length > 0 ? ownLogs.join('\n') : (isActive ? topLogs.join('\n') : text(raw.log))
|
|
1383
|
+
const result = text(raw.result)
|
|
1384
|
+
const restartRequired = raw.restartRequired === true || result === 'restart-required'
|
|
1385
|
+
const cancelled = raw.cancelled === true || stage === 'cancelled' || stage === 'canceled'
|
|
1386
|
+
const success = raw.success === true || raw.ok === true || result === 'success' || restartRequired
|
|
1387
|
+
const error = progressError(raw)
|
|
1388
|
+
return {
|
|
1389
|
+
key: `${name}@${index}`,
|
|
1390
|
+
name,
|
|
1391
|
+
requestId,
|
|
1392
|
+
from: text(raw.from) || text(raw.currentVersion) || text(raw.current),
|
|
1393
|
+
to: text(raw.to) || text(raw.targetVersion) || text(raw.version),
|
|
1394
|
+
stage,
|
|
1395
|
+
cancelled,
|
|
1396
|
+
success,
|
|
1397
|
+
failed: raw.failed === true || stage === 'failed' || (error !== '' && !cancelled && !success),
|
|
1398
|
+
error,
|
|
1399
|
+
restore: Object.keys(rec(raw.restore)).length > 0 ? rec(raw.restore) : null,
|
|
1400
|
+
restartRequired,
|
|
1401
|
+
log,
|
|
1402
|
+
}
|
|
1403
|
+
})
|
|
1404
|
+
const allTerminal = normalized.length > 0 && normalized.every(progressTerminal)
|
|
1405
|
+
const done = state.finished === true || (running === false && allTerminal)
|
|
1406
|
+
return {
|
|
1407
|
+
requestId: activeRequestId || text(state.requestId) || text(source.requestId),
|
|
1408
|
+
status: done ? 'done' : running ? 'running' : '',
|
|
1409
|
+
running,
|
|
1410
|
+
summary: rec(state.summary ?? source.summary),
|
|
1411
|
+
items: normalized,
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
/**
|
|
1416
|
+
* 把 Host 的 summary 归一成计数。
|
|
1417
|
+
* @param {object} summary - `{success,failed,restartRequired,skipped}` 或数组。
|
|
1418
|
+
* @returns {{success: number, failed: number, restart: number, skipped: number}|null} 计数。
|
|
1419
|
+
*/
|
|
1420
|
+
function readSummary(summary) {
|
|
1421
|
+
if (Array.isArray(summary)) {
|
|
1422
|
+
const counted = { success: 0, failed: 0, restart: 0, skipped: 0 }
|
|
1423
|
+
for (const entry of summary) {
|
|
1424
|
+
const raw = rec(entry)
|
|
1425
|
+
const result = text(raw.result) || text(raw.status)
|
|
1426
|
+
if (result === 'success' || raw.success === true) counted.success += 1
|
|
1427
|
+
else if (result === 'failed' || raw.failed === true) counted.failed += 1
|
|
1428
|
+
else if (result === 'restart-required' || raw.restartRequired === true) counted.restart += 1
|
|
1429
|
+
else if (result === 'skipped' || result === 'cancelled') counted.skipped += 1
|
|
1430
|
+
}
|
|
1431
|
+
return counted
|
|
1432
|
+
}
|
|
1433
|
+
const raw = rec(summary)
|
|
1434
|
+
if (Object.keys(raw).length === 0) return null
|
|
1435
|
+
return {
|
|
1436
|
+
success: num(raw.success ?? raw.succeeded ?? raw.ok, 0),
|
|
1437
|
+
failed: num(raw.failed, 0),
|
|
1438
|
+
restart: num(raw.restartRequired ?? raw.restart ?? raw.restartRequiredCount, 0),
|
|
1439
|
+
skipped: num(raw.skipped ?? raw.cancelled, 0),
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
/**
|
|
1444
|
+
* 进度是否已经结束(成功 / 失败 / 取消 / 跳过都算)。
|
|
1445
|
+
* @param {object} item - 进度项。
|
|
1446
|
+
* @returns {boolean} 是否终态。
|
|
1447
|
+
*/
|
|
1448
|
+
function progressTerminal(item) {
|
|
1449
|
+
if (item.success === true || item.failed === true || item.cancelled === true || item.restartRequired === true) return true
|
|
1450
|
+
const stage = text(item.stage).toLowerCase()
|
|
1451
|
+
return ['done', 'finished', 'success', 'failed', 'error', 'restart', 'restart-required', 'restart_required', 'cancelled', 'canceled', 'skipped'].includes(stage)
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
/**
|
|
1455
|
+
* 「筛选」下拉里的一行开关(文案也可点)。
|
|
1456
|
+
* @param {object} props - 组件属性。
|
|
461
1457
|
* @returns {object} React 元素。
|
|
462
1458
|
*/
|
|
463
|
-
function
|
|
464
|
-
return h('
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
h('
|
|
477
|
-
|
|
478
|
-
|
|
1459
|
+
function FilterMenuRow({ checked, disabled, label, onChange }) {
|
|
1460
|
+
return h('div', { className: 'pmu-menuRow' },
|
|
1461
|
+
h(Switch, { checked, disabled, label, onChange }),
|
|
1462
|
+
h('button', { type: 'button', className: 'pmu-switchLabel', disabled: disabled === true, onClick: () => { onChange(!checked) } }, label))
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
/**
|
|
1466
|
+
* 来源徽标(npm / git),位于插件名之后、版本变动之前。
|
|
1467
|
+
* @param {object} props - 组件属性。
|
|
1468
|
+
* @returns {object|null} React 元素。
|
|
1469
|
+
*/
|
|
1470
|
+
function KindBadge({ kind, t }) {
|
|
1471
|
+
if (text(kind) === '') return null
|
|
1472
|
+
return h('span', { className: 'pmp-badge pmu-kindBadge' }, kind === 'git' ? t('updatesKindGit') : t('updatesKindNpm'))
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
/**
|
|
1476
|
+
* 「已禁用」次左徽标:独立显示在主状态徽标左侧,不合并进主状态。
|
|
1477
|
+
* @param {object} props - 组件属性。
|
|
1478
|
+
* @returns {object|null} React 元素。
|
|
1479
|
+
*/
|
|
1480
|
+
function DisabledBadge({ row, t }) {
|
|
1481
|
+
// 只在已禁用时渲染;该列在共享 grid 模板里有固定轨道且后续列都显式 grid-column,
|
|
1482
|
+
// 所以空列也天然占位,其他行不会位移。
|
|
1483
|
+
if (row.enabled !== false) return null
|
|
1484
|
+
return h('span', { className: 'pmp-badge pmu-disabledBadge' }, t('updatesStateDisabled'))
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
/**
|
|
1488
|
+
* 「无法检查」的悬浮原因文案。
|
|
1489
|
+
* @param {string} reason - 候选的 reason(index-miss / unpinned-git-spec / 其它)。
|
|
1490
|
+
* @param {(key: string) => string} t - 翻译函数。
|
|
1491
|
+
* @returns {string} 文案。
|
|
1492
|
+
*/
|
|
1493
|
+
function uncheckableReasonText(reason, t) {
|
|
1494
|
+
if (reason === 'index-miss') return t('updatesUncheckableReasonIndexMiss')
|
|
1495
|
+
if (reason === 'unpinned-git-spec') return t('updatesUncheckableReasonUnpinned')
|
|
1496
|
+
return t('updatesUncheckableReasonOther')
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
/**
|
|
1500
|
+
* 主状态徽标:整行只渲染一个,覆盖 无法检查/可更新/不兼容/预发布/已废弃/已豁免/未检查/检查失败/无更新。
|
|
1501
|
+
* @param {object} props - 组件属性。
|
|
1502
|
+
* @returns {object} React 元素。
|
|
1503
|
+
*/
|
|
1504
|
+
function StatusBadge({ row, exempted, t }) {
|
|
1505
|
+
const state = statusOf(row, exempted)
|
|
1506
|
+
const labelKey = STATUS_LABEL_KEYS[state] ?? STATUS_LABEL_KEYS.unknown
|
|
1507
|
+
const title = state === 'uncheckable' ? uncheckableReasonText(text(row.reason), t) : undefined
|
|
1508
|
+
return h('span', {
|
|
1509
|
+
className: 'pmp-badge pmu-statusBadge',
|
|
1510
|
+
'data-state': state,
|
|
1511
|
+
'data-tone': STATUS_TONES[state] ?? 'idle',
|
|
1512
|
+
title,
|
|
1513
|
+
}, h('span', { className: 'pmp-dot' }), t(labelKey))
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
/**
|
|
1517
|
+
* 行的主状态(整行只显示一个)。
|
|
1518
|
+
*
|
|
1519
|
+
* 优先级(高→低):检查失败 > 无法检查 > 不兼容(未豁免)> 已豁免 > 已废弃 > 预发布 > 跳过 >
|
|
1520
|
+
* 无更新 > 未检查 > 可更新。「已禁用」不属于主状态,作为独立徽标显示在主状态左侧。
|
|
1521
|
+
* @param {object} row - 行。
|
|
1522
|
+
* @param {boolean} exempted - 是否已豁免。
|
|
1523
|
+
* @returns {string} 状态键。
|
|
1524
|
+
*/
|
|
1525
|
+
function statusOf(row, exempted) {
|
|
1526
|
+
const state = text(row.state)
|
|
1527
|
+
if (state === 'failed') return 'failed'
|
|
1528
|
+
if (state === 'uncheckable') return 'uncheckable'
|
|
1529
|
+
if (state === 'incompatible' || row.incompatible === true) return exempted === true ? 'exempted' : 'incompatible'
|
|
1530
|
+
// 目标版本自身的属性优先于 Host 的 available/skipped(开关打开时 Host 仍给 available + 标记)。
|
|
1531
|
+
if (state === 'deprecated' || row.deprecated === true) return 'deprecated'
|
|
1532
|
+
if (state === 'prerelease' || row.prerelease === true) return 'prerelease'
|
|
1533
|
+
if (state === 'skipped') return 'skipped'
|
|
1534
|
+
if (state === 'current') return 'current'
|
|
1535
|
+
if (state === 'unknown') return 'unknown'
|
|
1536
|
+
return 'updatable'
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
/**
|
|
1540
|
+
* 弹窗外壳(Escape 关闭 + 点击遮罩关闭)。
|
|
1541
|
+
* @param {object} props - 组件属性。
|
|
1542
|
+
* @returns {object} React 元素。
|
|
1543
|
+
*/
|
|
1544
|
+
function UpdatesModal({ title, onClose, children }) {
|
|
1545
|
+
React.useEffect(() => {
|
|
1546
|
+
/**
|
|
1547
|
+
* @param {object} event - 键盘事件。
|
|
1548
|
+
* @returns {void}
|
|
1549
|
+
*/
|
|
1550
|
+
const onKey = (event) => { if (event?.key === 'Escape') onClose() }
|
|
1551
|
+
try {
|
|
1552
|
+
document.addEventListener('keydown', onKey)
|
|
1553
|
+
return () => { document.removeEventListener('keydown', onKey) }
|
|
1554
|
+
} catch {
|
|
1555
|
+
return undefined
|
|
1556
|
+
}
|
|
1557
|
+
}, [onClose])
|
|
1558
|
+
const panel = h('div', { className: 'pmu-modal', role: 'dialog', 'aria-modal': 'true', 'aria-label': title, onClick: (event) => { event.stopPropagation() } },
|
|
1559
|
+
h('h3', { className: 'pmu-modalTitle' }, title),
|
|
1560
|
+
children)
|
|
1561
|
+
return h('div', { className: 'pmu-modalLayer', onClick: onClose }, panel)
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
/**
|
|
1565
|
+
* 确认框里的一项(包、当前 → 目标版本、来源)。
|
|
1566
|
+
* @param {object} props - 组件属性。
|
|
1567
|
+
* @returns {object} React 元素。
|
|
1568
|
+
*/
|
|
1569
|
+
function ConfirmRow({ row, t }) {
|
|
1570
|
+
return h('div', { className: 'pmu-confirmRow' },
|
|
1571
|
+
h('span', { className: 'pmu-confirmKey' }, row.name),
|
|
1572
|
+
h('span', { className: 'pmu-confirmValue' },
|
|
1573
|
+
`${t('updatesConfirmFrom')} ${row.current === '' ? t('updatesUnknownVersion') : row.current} → ${t('updatesConfirmTo')} ${row.latest === '' ? t('updatesUnknownVersion') : row.latest}`),
|
|
1574
|
+
h('span', { className: 'pmu-confirmKey' }, t('updatesConfirmSource')),
|
|
1575
|
+
h('span', { className: 'pmu-confirmValue' }, locationText(row, t)))
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
/**
|
|
1579
|
+
* 安装来源位置展示。
|
|
1580
|
+
* @param {object} row - 行。
|
|
1581
|
+
* @param {(key: string, params?: object) => string} t - 翻译函数。
|
|
1582
|
+
* @returns {string} 文本。
|
|
1583
|
+
*/
|
|
1584
|
+
function locationText(row, t) {
|
|
1585
|
+
if (row.location !== '') return row.location
|
|
1586
|
+
if (row.spec !== '') return row.spec
|
|
1587
|
+
const parts = []
|
|
1588
|
+
if (row.repository !== '') parts.push(row.repository)
|
|
1589
|
+
if (row.directory !== '') parts.push(row.directory)
|
|
1590
|
+
if (row.commit !== '') parts.push(row.commit.slice(0, 12))
|
|
1591
|
+
if (parts.length > 0) return parts.join(' ')
|
|
1592
|
+
if (row.registry !== '') return `${t('updatesKindNpm')} ${row.registry}`
|
|
1593
|
+
return row.kind === 'git' ? t('updatesKindGit') : t('updatesKindNpm')
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
/**
|
|
1597
|
+
* 进度视图。
|
|
1598
|
+
* @param {object} props - 组件属性。
|
|
1599
|
+
* @returns {object} React 元素。
|
|
1600
|
+
*/
|
|
1601
|
+
function UpdatesProgress({ items, status, summary, running, cancelling, openLogs, t, onToggleLog, onCancel, onClose }) {
|
|
1602
|
+
const ready = items.length > 0 && items.every(progressTerminal)
|
|
1603
|
+
const finished = status !== 'running' && (status === 'done' || (ready && running !== true))
|
|
1604
|
+
const counts = readSummary(summary) ?? {
|
|
1605
|
+
success: items.filter(item => item.success === true).length,
|
|
1606
|
+
failed: items.filter(item => item.failed === true || (progressTerminal(item) && item.cancelled !== true && item.success !== true && item.restartRequired !== true)).length,
|
|
1607
|
+
restart: items.filter(item => item.restartRequired === true).length,
|
|
1608
|
+
skipped: items.filter(item => item.cancelled === true || ['cancelled', 'canceled', 'skipped'].includes(text(item.stage).toLowerCase())).length,
|
|
1609
|
+
}
|
|
1610
|
+
const done = counts.success
|
|
1611
|
+
const failed = counts.failed
|
|
1612
|
+
const restart = counts.restart
|
|
1613
|
+
const skipped = counts.skipped
|
|
1614
|
+
const current = items.find(item => !progressTerminal(item))
|
|
1615
|
+
const currentIndex = items.length === 0 || current === undefined ? items.length : items.indexOf(current) + 1
|
|
1616
|
+
return h('div', { className: 'pmu-root' },
|
|
1617
|
+
h('div', { className: 'pmu-progressHead' },
|
|
1618
|
+
h('h3', { className: 'pmu-title' }, t('updatesProgressTitle')),
|
|
1619
|
+
h('span', { className: 'pmu-summaryText' }, t('updatesProgressOf', { index: currentIndex, total: items.length })),
|
|
1620
|
+
h('span', { className: 'pmu-summaryActions' },
|
|
1621
|
+
current !== undefined && h('button', { type: 'button', className: 'pmp-btn pmp-btnDanger', disabled: cancelling, onClick: onCancel }, cancelling ? t('updatesCancelling') : t('updatesCancelQueue'))),
|
|
1622
|
+
),
|
|
1623
|
+
h('p', { className: 'pmu-hint' }, t('updatesCancelHint')),
|
|
1624
|
+
...items.map((item) => h('div', { className: 'pmu-progressItem', key: item.key, 'data-current': item === current ? 'true' : undefined },
|
|
1625
|
+
h('div', { className: 'pmu-progressTop' },
|
|
1626
|
+
h('span', { className: 'pmu-progressName' }, item.name),
|
|
1627
|
+
h('span', { className: 'pmu-versions' }, `${item.from === '' ? t('updatesUnknownVersion') : item.from} → ${item.to === '' ? t('updatesUnknownVersion') : item.to}`),
|
|
1628
|
+
h('span', { className: 'pmp-badge', 'data-tone': item.failed === true ? 'bad' : item.success === true || item.restartRequired === true ? 'ok' : 'idle' },
|
|
1629
|
+
h('span', { className: 'pmp-dot' }), item.stage === '' ? t('stagePending') : stageLabel(item.stage, t))),
|
|
1630
|
+
item.error !== '' && h('p', { className: 'pmu-error' }, item.error),
|
|
1631
|
+
list(item.stages).length > 1 && h('p', { className: 'pmu-hint' }, h('b', null, `${t('updatesStages')} `), list(item.stages).map(value => stageLabel(value, t)).join(' → ')),
|
|
1632
|
+
item.restore !== null && h('p', { className: 'pmu-hint' }, h('b', null, `${t('updatesStages')} `), restoreText(item.restore, t)),
|
|
1633
|
+
h('div', { className: 'pmu-progressTop' },
|
|
1634
|
+
h('button', { type: 'button', className: 'pmu-link', onClick: () => { onToggleLog(item.key) } }, t('updatesLogToggle')),
|
|
1635
|
+
item.restartRequired === true && h('span', { className: 'pmu-progressText' }, t('updatesRestartRequired'))),
|
|
1636
|
+
openLogs[item.key] === true && h('div', { className: 'pmu-log' }, item.log === '' ? t('updatesLogEmpty') : item.log))),
|
|
1637
|
+
finished && h('div', { className: 'pmu-summary' },
|
|
1638
|
+
h('span', { className: 'pmu-summaryText' }, `${t('updatesSuccessItems', { n: done })} · ${t('updatesFailedItems', { n: failed })} · ${t('updatesRestartItems', { n: restart })}${skipped > 0 ? ` · ${t('updatesSkippedItems', { n: skipped })}` : ''}`),
|
|
1639
|
+
h('span', { className: 'pmu-summaryActions' },
|
|
1640
|
+
h('button', { type: 'button', className: 'pmp-btn pmp-btnPrimary', onClick: onClose }, t('updatesClose')))),
|
|
1641
|
+
)
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
/**
|
|
1645
|
+
* 回滚结果文本。
|
|
1646
|
+
*
|
|
1647
|
+
* Host 的 `restore` 是 `pluginManager.updateBundle()` 的 ChangeResult:
|
|
1648
|
+
* `{application:'applied'|'restart-required'|'failed'|'unchanged', error?:{code,diagnostic,...}}`。
|
|
1649
|
+
* `applied`/`restart-required` = 已装回原版本;`failed` = 回滚也失败(显示诊断);
|
|
1650
|
+
* `unchanged` 或其他 = 没发生实际回滚(中性文案)。
|
|
1651
|
+
* @param {object} restore - restore(ChangeResult)。
|
|
1652
|
+
* @param {(key: string, params?: object) => string} t - 翻译函数。
|
|
1653
|
+
* @returns {string} 文本。
|
|
1654
|
+
*/
|
|
1655
|
+
function restoreText(restore, t) {
|
|
1656
|
+
const value = rec(restore)
|
|
1657
|
+
const application = text(value.application) || text(value.result) || text(value.status)
|
|
1658
|
+
const error = rec(value.error)
|
|
1659
|
+
const diagnostic = text(error.diagnostic) || text(error.message) || text(error.code)
|
|
1660
|
+
if (application === 'applied' || application === 'restart-required') return t('updatesRestored')
|
|
1661
|
+
if (application === 'failed' || Object.keys(error).length > 0) {
|
|
1662
|
+
return `${t('updatesRestoreFailed')}${diagnostic === '' ? '' : `: ${diagnostic}`}`
|
|
1663
|
+
}
|
|
1664
|
+
return t('updatesRestoreIdle')
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
/**
|
|
1668
|
+
* 「可更新」页主体:plugins.tab 席位内容。
|
|
1669
|
+
* @param {object} props - 宿主注入属性(owner props + 本插件注入的 t)。
|
|
1670
|
+
* @returns {object} React 元素。
|
|
1671
|
+
*/
|
|
1672
|
+
function UpdatesSection(props) {
|
|
1673
|
+
// owner props:openPackage 打开官方详情页;install/update 在本页不使用。
|
|
1674
|
+
const openPackage = typeof props?.openPackage === 'function' ? props.openPackage : null
|
|
1675
|
+
const t = typeof props?.t === 'function' ? props.t : fallbackT
|
|
1676
|
+
|
|
1677
|
+
const [rows, setRows] = React.useState([])
|
|
1678
|
+
const [loaded, setLoaded] = React.useState(false)
|
|
1679
|
+
const [loadError, setLoadError] = React.useState('')
|
|
1680
|
+
const [checkedAt, setCheckedAt] = React.useState(null)
|
|
1681
|
+
const [settings, setSettings] = React.useState({ includeDisabled: false, includePrerelease: false, showFailed: false, settable: true })
|
|
1682
|
+
const [search, setSearch] = React.useState('')
|
|
1683
|
+
const [selected, setSelected] = React.useState({})
|
|
1684
|
+
const [exemptPanels, setExemptPanels] = React.useState({})
|
|
1685
|
+
const [exempted, setExempted] = React.useState(() => ({}))
|
|
1686
|
+
const [notice, setNotice] = React.useState(null)
|
|
1687
|
+
const [busy, setBusy] = React.useState('')
|
|
1688
|
+
const [confirm, setConfirm] = React.useState(null)
|
|
1689
|
+
const [exemptAck, setExemptAck] = React.useState({})
|
|
1690
|
+
const [confirmSecond, setConfirmSecond] = React.useState(null)
|
|
1691
|
+
const [progress, setProgress] = React.useState(null)
|
|
1692
|
+
const [cancelling, setCancelling] = React.useState(false)
|
|
1693
|
+
const [openLogs, setOpenLogs] = React.useState({})
|
|
1694
|
+
const [settingsOpen, setSettingsOpen] = React.useState(false)
|
|
1695
|
+
const [menuPos, setMenuPos] = React.useState(null)
|
|
1696
|
+
const alive = React.useRef(true)
|
|
1697
|
+
const pollRef = React.useRef(null)
|
|
1698
|
+
const requestRef = React.useRef('')
|
|
1699
|
+
const selectAllRef = React.useRef(null)
|
|
1700
|
+
const settingsRef = React.useRef(null)
|
|
1701
|
+
const stagesRef = React.useRef({})
|
|
1702
|
+
const startPollingRef = React.useRef(null)
|
|
1703
|
+
const tRef = React.useRef(t)
|
|
1704
|
+
tRef.current = t
|
|
1705
|
+
|
|
1706
|
+
const seen = (name, latest) => cellKey(name, latest)
|
|
1707
|
+
|
|
1708
|
+
/** 让阶段记录跨轮询保留(Host 只发增量时也能看到历史)。 */
|
|
1709
|
+
const mergeStages = (items) => {
|
|
1710
|
+
const previous = stagesRef.current ?? {}
|
|
1711
|
+
const next = {}
|
|
1712
|
+
const merged = items.map((item) => {
|
|
1713
|
+
const prior = previous[item.key] ?? {}
|
|
1714
|
+
const priorStages = list(prior.stages)
|
|
1715
|
+
const stage = text(item.stage)
|
|
1716
|
+
const stages = stage === '' || priorStages[priorStages.length - 1] === stage ? priorStages : [...priorStages, stage]
|
|
1717
|
+
// Host 的顶层 logs 只覆盖当前 active 项,队列结束后会变空:保留最后一次看到的日志。
|
|
1718
|
+
const log = text(item.log) !== '' ? text(item.log) : text(prior.log)
|
|
1719
|
+
next[item.key] = { stages, log }
|
|
1720
|
+
return Object.assign({}, item, { stages, log })
|
|
1721
|
+
})
|
|
1722
|
+
stagesRef.current = next
|
|
1723
|
+
return merged
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
const load = React.useCallback(async (skipResume) => {
|
|
1727
|
+
try {
|
|
1728
|
+
const payload = await getJson(`${UPDATES_API}`)
|
|
1729
|
+
if (!alive.current) return
|
|
1730
|
+
const body = rec(payload)
|
|
1731
|
+
if (body.ok === false) {
|
|
1732
|
+
setLoadError(text(body.message) || text(body.error) || 'error')
|
|
1733
|
+
setLoaded(true)
|
|
1734
|
+
return
|
|
1735
|
+
}
|
|
1736
|
+
// Host 契约:candidates[] + config{} + checkedAt + running
|
|
1737
|
+
setRows(list(body.candidates ?? body.updates ?? body.items).map(toRow).filter(Boolean))
|
|
1738
|
+
const incomingSettings = readSettings(body)
|
|
1739
|
+
if (incomingSettings.known) setSettings(previous => mergeSettings(previous, incomingSettings))
|
|
1740
|
+
setCheckedAt(body.checkedAt === undefined || body.checkedAt === null ? null : num(body.checkedAt, Date.now()))
|
|
1741
|
+
setLoadError('')
|
|
1742
|
+
setLoaded(true)
|
|
1743
|
+
if (body.running === true && skipResume !== true) {
|
|
1744
|
+
// 打开页面时已有队列在跑:接上进度,不再自己入队。
|
|
1745
|
+
setNotice({ tone: 'warn', text: tRef.current('updatesRunningElsewhere') })
|
|
1746
|
+
setProgress({ requestId: '', status: 'running', running: true, summary: {}, items: [] })
|
|
1747
|
+
if (typeof startPollingRef.current === 'function') startPollingRef.current()
|
|
1748
|
+
}
|
|
1749
|
+
} catch (failure) {
|
|
1750
|
+
if (!alive.current) return
|
|
1751
|
+
setLoadError(String(failure?.message ?? failure))
|
|
1752
|
+
setLoaded(true)
|
|
1753
|
+
}
|
|
1754
|
+
}, [])
|
|
1755
|
+
|
|
1756
|
+
// 「筛选」下拉打开时响应 Escape(真实浏览器;点击外部由遮罩层处理)。
|
|
1757
|
+
React.useEffect(() => {
|
|
1758
|
+
if (settingsOpen !== true) return undefined
|
|
1759
|
+
/**
|
|
1760
|
+
* @param {object} event - 键盘事件。
|
|
1761
|
+
* @returns {void}
|
|
1762
|
+
*/
|
|
1763
|
+
const onKey = (event) => { if (event?.key === 'Escape') setSettingsOpen(false) }
|
|
1764
|
+
try {
|
|
1765
|
+
document.addEventListener('keydown', onKey)
|
|
1766
|
+
return () => { document.removeEventListener('keydown', onKey) }
|
|
1767
|
+
} catch {
|
|
1768
|
+
return undefined
|
|
1769
|
+
}
|
|
1770
|
+
}, [settingsOpen])
|
|
1771
|
+
|
|
1772
|
+
const applyCandidates = React.useCallback((body) => {
|
|
1773
|
+
const source = rec(body)
|
|
1774
|
+
const candidates = list(source.candidates)
|
|
1775
|
+
if (candidates.length === 0) return false
|
|
1776
|
+
setRows(candidates.map(toRow).filter(Boolean))
|
|
1777
|
+
if (source.checkedAt !== undefined && source.checkedAt !== null) setCheckedAt(num(source.checkedAt, Date.now()))
|
|
1778
|
+
return true
|
|
1779
|
+
}, [])
|
|
1780
|
+
|
|
1781
|
+
React.useEffect(() => {
|
|
1782
|
+
alive.current = true
|
|
1783
|
+
void load()
|
|
1784
|
+
return () => {
|
|
1785
|
+
alive.current = false
|
|
1786
|
+
if (pollRef.current !== null) clearInterval(pollRef.current)
|
|
1787
|
+
}
|
|
1788
|
+
}, [load])
|
|
1789
|
+
|
|
1790
|
+
const finish = React.useCallback((items, summary) => {
|
|
1791
|
+
const counts = readSummary(summary)
|
|
1792
|
+
const failed = counts === null
|
|
1793
|
+
? items.filter(item => item.failed === true && item.restartRequired !== true).length
|
|
1794
|
+
: counts.failed
|
|
1795
|
+
const done = counts === null
|
|
1796
|
+
? items.filter(item => item.success === true || item.restartRequired === true).length
|
|
1797
|
+
: counts.success + counts.restart
|
|
1798
|
+
setNotice(failed > 0
|
|
1799
|
+
? { tone: 'error', text: `${t('updatesFailedItems', { n: failed })} · ${t('updatesSuccessItems', { n: done })}` }
|
|
1800
|
+
: { tone: 'ok', text: `${t('updatesSuccessItems', { n: done })}${done === 0 || items.some(item => item.restartRequired === true) || (counts?.restart ?? 0) > 0 ? ` · ${t('updatesRestartRequired')}` : ''}` })
|
|
1801
|
+
setSelected({})
|
|
1802
|
+
setCancelling(false)
|
|
1803
|
+
// 队列刚结束:只刷新列表,不要再把「正在跑」的旧状态接回来(否则 finish→load→poll 会自激)。
|
|
1804
|
+
void load(true)
|
|
1805
|
+
}, [t, load])
|
|
1806
|
+
|
|
1807
|
+
const stopPolling = React.useCallback(() => {
|
|
1808
|
+
if (pollRef.current !== null) {
|
|
1809
|
+
clearInterval(pollRef.current)
|
|
1810
|
+
pollRef.current = null
|
|
1811
|
+
}
|
|
1812
|
+
}, [])
|
|
1813
|
+
|
|
1814
|
+
const poll = React.useCallback(async () => {
|
|
1815
|
+
try {
|
|
1816
|
+
const payload = await getJson(`${UPDATES_API}/state`)
|
|
1817
|
+
if (!alive.current) return
|
|
1818
|
+
const body = rec(payload)
|
|
1819
|
+
const current = readProgress(body)
|
|
1820
|
+
const items = mergeStages(current.items)
|
|
1821
|
+
setProgress({
|
|
1822
|
+
requestId: current.requestId === '' ? requestRef.current : current.requestId,
|
|
1823
|
+
status: current.status,
|
|
1824
|
+
running: current.running,
|
|
1825
|
+
summary: current.summary,
|
|
1826
|
+
items,
|
|
1827
|
+
})
|
|
1828
|
+
if (current.status === 'done') {
|
|
1829
|
+
stopPolling()
|
|
1830
|
+
finish(items, current.summary)
|
|
1831
|
+
}
|
|
1832
|
+
} catch {
|
|
1833
|
+
if (!alive.current) return
|
|
1834
|
+
stopPolling()
|
|
1835
|
+
setCancelling(false)
|
|
1836
|
+
setNotice({ tone: 'error', text: t('updatesStateLost') })
|
|
1837
|
+
}
|
|
1838
|
+
}, [finish, mergeStages, stopPolling, t])
|
|
1839
|
+
|
|
1840
|
+
const startPolling = React.useCallback(() => {
|
|
1841
|
+
stopPolling()
|
|
1842
|
+
pollRef.current = setInterval(() => { void poll() }, POLL_MS)
|
|
1843
|
+
void poll()
|
|
1844
|
+
}, [poll, stopPolling])
|
|
1845
|
+
startPollingRef.current = startPolling
|
|
1846
|
+
|
|
1847
|
+
/**
|
|
1848
|
+
* 打开开关:先本地生效保证交互即时,再持久化到插件配置并重取列表。
|
|
1849
|
+
* @param {'includeDisabled'|'includePrerelease'} key - 开关。
|
|
1850
|
+
* @param {boolean} next - 新值。
|
|
1851
|
+
* @returns {void}
|
|
1852
|
+
*/
|
|
1853
|
+
const toggleSetting = (key, next) => {
|
|
1854
|
+
const nextSettings = Object.assign({}, settings, { [key]: next })
|
|
1855
|
+
setSettings(nextSettings)
|
|
1856
|
+
setBusy('settings')
|
|
1857
|
+
setNotice(null)
|
|
1858
|
+
void postJson('/settings', {
|
|
1859
|
+
updatesIncludeDisabled: nextSettings.includeDisabled === true,
|
|
1860
|
+
updatesIncludePrerelease: nextSettings.includePrerelease === true,
|
|
1861
|
+
updatesShowFailed: nextSettings.showFailed === true,
|
|
1862
|
+
}).then(async (payload) => {
|
|
1863
|
+
if (!alive.current) return
|
|
1864
|
+
const incoming = readSettings(payload)
|
|
1865
|
+
// 响应没带配置(例如 {ok:true})时保留乐观值,随后用 GET /updates 的 config 校准。
|
|
1866
|
+
if (incoming.known) setSettings(previous => mergeSettings(previous, incoming))
|
|
1867
|
+
if (incoming.settable === false) setNotice({ tone: 'warn', text: t('updatesSetsLocalOnly') })
|
|
1868
|
+
await load()
|
|
1869
|
+
}).catch((failure) => {
|
|
1870
|
+
if (alive.current) setNotice({ tone: 'error', text: t('updatesSettingsFailed', { error: String(failure?.message ?? failure) }) })
|
|
1871
|
+
}).finally(() => {
|
|
1872
|
+
if (alive.current) setBusy('')
|
|
1873
|
+
})
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
const check = async () => {
|
|
1877
|
+
setBusy('check')
|
|
1878
|
+
setNotice(null)
|
|
1879
|
+
try {
|
|
1880
|
+
const names = rows.map(row => row.name)
|
|
1881
|
+
const payload = await postJson('/updates/check', names.length > 0 ? { names } : {})
|
|
1882
|
+
if (!alive.current) return
|
|
1883
|
+
const body = rec(payload)
|
|
1884
|
+
if (!applyCandidates(body)) await load()
|
|
1885
|
+
if (!alive.current) return
|
|
1886
|
+
const candidates = list(body.candidates).map(toRow).filter(Boolean)
|
|
1887
|
+
let updatable = 0
|
|
1888
|
+
for (const row of candidates) {
|
|
1889
|
+
if (autoSelectable(row, settings)) updatable += 1
|
|
1890
|
+
}
|
|
1891
|
+
setNotice({ tone: 'ok', text: t('updatesCheckDone', { n: updatable }) })
|
|
1892
|
+
} catch (failure) {
|
|
1893
|
+
if (alive.current) setNotice({ tone: 'error', text: t('updatesCheckFailed', { error: String(failure?.message ?? failure) }) })
|
|
1894
|
+
} finally {
|
|
1895
|
+
if (alive.current) setBusy('')
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
const startApply = async (items) => {
|
|
1900
|
+
setConfirm(null)
|
|
1901
|
+
setBusy('apply')
|
|
1902
|
+
setNotice(null)
|
|
1903
|
+
setSelected({})
|
|
1904
|
+
requestRef.current = ''
|
|
1905
|
+
try {
|
|
1906
|
+
// Host 契约:items 只带 name;只有 Git 包才需要 spec/commit(registry 一律不带)。
|
|
1907
|
+
const payload = await postJson('/updates/apply', {
|
|
1908
|
+
items: items.map(row => {
|
|
1909
|
+
const item = { name: row.name }
|
|
1910
|
+
if (row.kind === 'git') {
|
|
1911
|
+
if (row.spec !== '') item.spec = row.spec
|
|
1912
|
+
else if (row.commit !== '') item.commit = row.commit
|
|
1913
|
+
}
|
|
1914
|
+
return item
|
|
1915
|
+
}),
|
|
1916
|
+
})
|
|
1917
|
+
if (!alive.current) return
|
|
1918
|
+
const ack = applyAck(payload)
|
|
1919
|
+
if (!ack.ok) throw new Error(ack.message === '' ? t('updatesAnotherRunning') : ack.message)
|
|
1920
|
+
requestRef.current = ack.requestId
|
|
1921
|
+
setProgress({
|
|
1922
|
+
requestId: ack.requestId,
|
|
1923
|
+
status: 'running',
|
|
1924
|
+
running: true,
|
|
1925
|
+
summary: {},
|
|
1926
|
+
items: items.map(row => ({
|
|
1927
|
+
key: `${row.name}@0`, name: row.name, from: row.current, to: row.latest, stage: 'pending',
|
|
1928
|
+
success: false, failed: false, error: '', restore: null, restartRequired: false, log: '', stages: [],
|
|
1929
|
+
})),
|
|
1930
|
+
})
|
|
1931
|
+
stagesRef.current = {}
|
|
1932
|
+
startPolling()
|
|
1933
|
+
} catch (failure) {
|
|
1934
|
+
if (alive.current) setNotice({ tone: 'error', text: t('updatesStartFailed', { error: String(failure?.message ?? failure) }) })
|
|
1935
|
+
} finally {
|
|
1936
|
+
if (alive.current) setBusy('')
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
const cancelCurrent = async () => {
|
|
1941
|
+
if (progress === null) return
|
|
1942
|
+
setCancelling(true)
|
|
1943
|
+
try {
|
|
1944
|
+
// Host 契约:POST {} → {ok,cancelled,name?,state}
|
|
1945
|
+
await postJson('/updates/cancel', {})
|
|
1946
|
+
if (alive.current) void poll()
|
|
1947
|
+
} catch (failure) {
|
|
1948
|
+
if (alive.current) {
|
|
1949
|
+
setCancelling(false)
|
|
1950
|
+
setNotice({ tone: 'error', text: String(failure?.message ?? failure) })
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
const exemptAndUpdate = async (row, incompatibility) => {
|
|
1956
|
+
setBusy(`exempt:${row.name}`)
|
|
1957
|
+
setNotice(null)
|
|
1958
|
+
const runtimeVersion = text(incompatibility?.runtimeVersion)
|
|
1959
|
+
try {
|
|
1960
|
+
// Host 契约:{package,version,acceptRisk:true,runtimeVersion?} → {ok,runtimeVersion,result}
|
|
1961
|
+
const request = { package: row.name, version: row.latest, acceptRisk: true }
|
|
1962
|
+
if (runtimeVersion !== '') request.runtimeVersion = runtimeVersion
|
|
1963
|
+
const payload = await postJson('/updates/exempt', request)
|
|
1964
|
+
if (!alive.current) return
|
|
1965
|
+
const body = rec(payload)
|
|
1966
|
+
setExempted(previous => Object.assign({}, previous, {
|
|
1967
|
+
[seen(row.name, row.latest)]: text(body.runtimeVersion) || runtimeVersion || 'true',
|
|
1968
|
+
}))
|
|
1969
|
+
const next = Object.assign({}, row, { incompatible: false, state: 'updatable' })
|
|
1970
|
+
await startApply([next])
|
|
1971
|
+
} catch (failure) {
|
|
1972
|
+
if (alive.current) setNotice({ tone: 'error', text: t('updatesExemptFailed', { error: String(failure?.message ?? failure) }) })
|
|
1973
|
+
} finally {
|
|
1974
|
+
if (alive.current) setBusy('')
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
const visibleRows = React.useMemo(() => {
|
|
1979
|
+
const needle = search.trim().toLowerCase()
|
|
1980
|
+
return rows.filter((row) => {
|
|
1981
|
+
if (!inScope(row, settings.showFailed === true)) return false
|
|
1982
|
+
if (!visibleBySettings(row, settings)) return false
|
|
1983
|
+
if (needle !== '' && !row.name.toLowerCase().includes(needle)) return false
|
|
1984
|
+
return true
|
|
1985
|
+
})
|
|
1986
|
+
}, [rows, search, settings.includeDisabled, settings.includePrerelease, settings.showFailed])
|
|
1987
|
+
|
|
1988
|
+
// 当前搜索范围内被「显示检查失败的项」开关隐藏的条目数(空态提示用)。
|
|
1989
|
+
const hiddenFailedCount = React.useMemo(() => {
|
|
1990
|
+
const needle = search.trim().toLowerCase()
|
|
1991
|
+
return rows.filter(row => visibleBySettings(row, settings)
|
|
1992
|
+
&& (needle === '' || row.name.toLowerCase().includes(needle))
|
|
1993
|
+
&& !inScope(row, settings.showFailed === true) && inScope(row, true)).length
|
|
1994
|
+
}, [rows, search, settings.includeDisabled, settings.includePrerelease, settings.showFailed])
|
|
1995
|
+
|
|
1996
|
+
// 当前搜索范围内是否一个候选都没有(用于区分「搜索无命中」与「没有可更新的项」)。
|
|
1997
|
+
const searchedCount = React.useMemo(() => {
|
|
1998
|
+
const needle = search.trim().toLowerCase()
|
|
1999
|
+
return rows.filter(row => visibleBySettings(row, settings)
|
|
2000
|
+
&& (needle === '' || row.name.toLowerCase().includes(needle))).length
|
|
2001
|
+
}, [rows, search, settings.includeDisabled, settings.includePrerelease])
|
|
2002
|
+
|
|
2003
|
+
const installable = installableRows(visibleRows, settings)
|
|
2004
|
+
const selectedRows = visibleRows.filter(row => selected[row.key] === true)
|
|
2005
|
+
const allSelected = installable.length > 0 && installable.every(row => selected[row.key] === true)
|
|
2006
|
+
const someSelected = installable.some(row => selected[row.key] === true)
|
|
2007
|
+
const selectedCount = selectedRows.length
|
|
2008
|
+
|
|
2009
|
+
// 原生 indeterminate 只能用 DOM 属性;data-state 同步一份供样式/无障碍使用。
|
|
2010
|
+
const selectAllState = allSelected ? 'all' : someSelected ? 'indeterminate' : 'none'
|
|
2011
|
+
React.useEffect(() => {
|
|
2012
|
+
const node = selectAllRef.current
|
|
2013
|
+
if (node !== null && node !== undefined) node.indeterminate = selectAllState === 'indeterminate'
|
|
2014
|
+
}, [selectAllState])
|
|
2015
|
+
|
|
2016
|
+
const toggleSelect = (key, next) => {
|
|
2017
|
+
setSelected(previous => {
|
|
2018
|
+
const copy = Object.assign({}, previous)
|
|
2019
|
+
if (next) copy[key] = true
|
|
2020
|
+
else delete copy[key]
|
|
2021
|
+
return copy
|
|
2022
|
+
})
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
const toggleAll = () => {
|
|
2026
|
+
setSelected(() => {
|
|
2027
|
+
const copy = {}
|
|
2028
|
+
if (!allSelected) {
|
|
2029
|
+
for (const row of installable) copy[row.key] = true
|
|
2030
|
+
}
|
|
2031
|
+
return copy
|
|
2032
|
+
})
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
const toggleExemptPanel = (key) => {
|
|
2036
|
+
setExemptPanels(previous => {
|
|
2037
|
+
const copy = Object.assign({}, previous)
|
|
2038
|
+
if (copy[key] === true) delete copy[key]
|
|
2039
|
+
else copy[key] = true
|
|
2040
|
+
return copy
|
|
2041
|
+
})
|
|
2042
|
+
// 收起时清掉该行的风险勾选,重新打开需再次确认风险。
|
|
2043
|
+
setAck(key, false)
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
/**
|
|
2047
|
+
* 某一行的风险勾选状态(按行 key 区分,互不影响)。
|
|
2048
|
+
* @param {string} key - 行键。
|
|
2049
|
+
* @returns {boolean} 是否已勾选。
|
|
2050
|
+
*/
|
|
2051
|
+
const ackOf = (key) => exemptAck[key] === true
|
|
2052
|
+
|
|
2053
|
+
/**
|
|
2054
|
+
* 写入某一行的风险勾选。
|
|
2055
|
+
* @param {string} key - 行键。
|
|
2056
|
+
* @param {boolean} next - 是否勾选。
|
|
2057
|
+
* @returns {void}
|
|
2058
|
+
*/
|
|
2059
|
+
const setAck = (key, next) => {
|
|
2060
|
+
setExemptAck(previous => {
|
|
2061
|
+
const copy = Object.assign({}, previous)
|
|
2062
|
+
if (next) copy[key] = true
|
|
2063
|
+
else delete copy[key]
|
|
2064
|
+
return copy
|
|
2065
|
+
})
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
const toggleLog = (key) => {
|
|
2069
|
+
setOpenLogs(previous => {
|
|
2070
|
+
const copy = Object.assign({}, previous)
|
|
2071
|
+
if (copy[key] === true) delete copy[key]
|
|
2072
|
+
else copy[key] = true
|
|
2073
|
+
return copy
|
|
2074
|
+
})
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
/**
|
|
2078
|
+
* 打开插件详情(名称即入口)。
|
|
2079
|
+
* @param {string} name - 包名。
|
|
2080
|
+
* @returns {void}
|
|
2081
|
+
*/
|
|
2082
|
+
const openDetails = (name) => {
|
|
2083
|
+
if (openPackage !== null) openPackage(name)
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
/**
|
|
2087
|
+
* 展开 / 收起「筛选」菜单(展开时先量一次落点,避免菜单出视口)。
|
|
2088
|
+
* @returns {void}
|
|
2089
|
+
*/
|
|
2090
|
+
const toggleSettingsMenu = () => {
|
|
2091
|
+
if (settingsOpen === true) {
|
|
2092
|
+
setSettingsOpen(false)
|
|
2093
|
+
return
|
|
2094
|
+
}
|
|
2095
|
+
setMenuPos(measureMenuPlacement(settingsRef.current))
|
|
2096
|
+
setSettingsOpen(true)
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
const progressItems = progress?.items ?? []
|
|
2100
|
+
const progressReady = progressItems.length > 0 && progressItems.every(progressTerminal)
|
|
2101
|
+
const openConfirm = (target) => { setConfirm(target); setExemptAck({}); setConfirmSecond(null) }
|
|
2102
|
+
|
|
2103
|
+
return h('div', { className: 'pmu-root' },
|
|
2104
|
+
// 工具条(单行):检查更新 | 搜索框 | 齿轮设置 | 更新全部 | 更新已选
|
|
2105
|
+
h('div', { className: 'pmu-toolbar' },
|
|
2106
|
+
h('button', {
|
|
2107
|
+
type: 'button', className: 'pmp-btn pmp-btnPrimary pmu-checkBtn',
|
|
2108
|
+
disabled: busy !== '' || progress !== null && !progressReady,
|
|
2109
|
+
onClick: () => { void check() },
|
|
2110
|
+
}, busy === 'check' ? t('updatesChecking') : t('updatesCheck')),
|
|
2111
|
+
h('input', {
|
|
2112
|
+
className: 'pmu-search', type: 'search', value: search, placeholder: t('updatesSearchPlaceholder'),
|
|
2113
|
+
'aria-label': t('updatesSearchPlaceholder'), onChange: (event) => { setSearch(text(event?.target?.value)) },
|
|
2114
|
+
}),
|
|
2115
|
+
// 齿轮设置:遮罩与菜单是 wrap 下的兄弟节点(菜单以 wrap 为包含块,不能嵌进全屏 fixed 遮罩)。
|
|
2116
|
+
h('div', {
|
|
2117
|
+
className: 'pmu-filterWrap pmu-settingsWrap', ref: settingsRef,
|
|
2118
|
+
onKeyDown: (event) => { if (event?.key === 'Escape' && settingsOpen) setSettingsOpen(false) },
|
|
2119
|
+
},
|
|
2120
|
+
settingsOpen && h('div', { className: 'pmu-menuLayer', onClick: () => { setSettingsOpen(false) } }),
|
|
2121
|
+
h('button', {
|
|
2122
|
+
type: 'button', className: 'pmp-btn pmu-gearBtn',
|
|
2123
|
+
'aria-haspopup': 'true', 'aria-expanded': settingsOpen ? 'true' : 'false',
|
|
2124
|
+
'aria-label': t('updatesSettingsMenu'), title: t('updatesSettingsMenu'),
|
|
2125
|
+
onClick: toggleSettingsMenu,
|
|
2126
|
+
}, h('svg', {
|
|
2127
|
+
className: 'pmu-gear', viewBox: '0 0 24 24', width: '15', height: '15',
|
|
2128
|
+
'aria-hidden': 'true', focusable: 'false', fill: 'none', stroke: 'currentColor',
|
|
2129
|
+
'stroke-width': '2', 'stroke-linecap': 'round', 'stroke-linejoin': 'round',
|
|
2130
|
+
}, h('circle', { cx: '12', cy: '12', r: '3' }), h('path', { d: GEAR_PATH }))),
|
|
2131
|
+
settingsOpen && h('div', {
|
|
2132
|
+
className: 'pmu-menu pmu-settingsMenu', role: 'menu', 'aria-label': t('updatesSettingsMenu'),
|
|
2133
|
+
'data-placement': menuPos === null ? 'bottom' : menuPos.placement,
|
|
2134
|
+
'data-anchored': menuPos === null ? 'css' : 'fixed',
|
|
2135
|
+
style: menuPos === null ? undefined : { position: 'fixed', left: `${menuPos.left}px`, top: `${menuPos.top}px` },
|
|
2136
|
+
onClick: (event) => { event.stopPropagation() },
|
|
2137
|
+
},
|
|
2138
|
+
h(FilterMenuRow, {
|
|
2139
|
+
checked: settings.showFailed === true,
|
|
2140
|
+
disabled: settings.settable === false || busy !== '',
|
|
2141
|
+
label: t('updatesShowFailed'),
|
|
2142
|
+
onChange: (next) => { toggleSetting('showFailed', next) },
|
|
2143
|
+
}),
|
|
2144
|
+
h(FilterMenuRow, {
|
|
2145
|
+
checked: settings.includePrerelease === true,
|
|
2146
|
+
disabled: settings.settable === false || busy !== '',
|
|
2147
|
+
label: t('updatesIncludePrerelease'),
|
|
2148
|
+
onChange: (next) => { toggleSetting('includePrerelease', next) },
|
|
2149
|
+
}),
|
|
2150
|
+
h(FilterMenuRow, {
|
|
2151
|
+
checked: settings.includeDisabled === true,
|
|
2152
|
+
disabled: settings.settable === false || busy !== '',
|
|
2153
|
+
label: t('updatesIncludeDisabled'),
|
|
2154
|
+
onChange: (next) => { toggleSetting('includeDisabled', next) },
|
|
2155
|
+
}))),
|
|
2156
|
+
h('button', { type: 'button', className: 'pmp-btn', disabled: busy !== '' || installable.length === 0, onClick: () => { openConfirm({ rows: installable }) } }, t('updatesUpdateAll')),
|
|
2157
|
+
h('button', { type: 'button', className: 'pmp-btn', disabled: busy !== '' || selectedCount === 0, onClick: () => { openConfirm({ rows: selectedRows }) } }, t('updatesUpdateSelected'))),
|
|
2158
|
+
|
|
2159
|
+
notice !== null && h('p', { className: 'pmu-notice', 'data-tone': notice.tone }, notice.text),
|
|
2160
|
+
loadError !== '' && h('p', { className: 'pmu-error' }, t('updatesLoadFailed', { error: loadError })),
|
|
2161
|
+
|
|
2162
|
+
progress !== null && h(UpdatesProgress, {
|
|
2163
|
+
items: progressItems,
|
|
2164
|
+
status: progress.status,
|
|
2165
|
+
summary: progress.summary,
|
|
2166
|
+
running: progress.running,
|
|
2167
|
+
cancelling,
|
|
2168
|
+
openLogs,
|
|
2169
|
+
t,
|
|
2170
|
+
onToggleLog: toggleLog,
|
|
2171
|
+
onCancel: () => { void cancelCurrent() },
|
|
2172
|
+
onClose: () => { setProgress(null); setOpenLogs({}); setStagesRefSafe() },
|
|
2173
|
+
}),
|
|
2174
|
+
|
|
2175
|
+
// 统计条
|
|
2176
|
+
h('div', { className: 'pmu-summary' },
|
|
2177
|
+
h('label', { className: 'pmu-selectAll' },
|
|
2178
|
+
h('input', {
|
|
2179
|
+
ref: selectAllRef, type: 'checkbox', className: 'pmu-check', 'aria-label': t('updatesSelectAll'),
|
|
2180
|
+
'data-state': selectAllState, checked: allSelected, disabled: installable.length === 0,
|
|
2181
|
+
onChange: () => { toggleAll() },
|
|
2182
|
+
}),
|
|
2183
|
+
t('updatesSelectAll')),
|
|
2184
|
+
h('span', { className: 'pmu-summaryText' }, t('updatesSummary', { updates: installable.length, selected: selectedCount })),
|
|
2185
|
+
h('span', { className: 'pmu-summaryTime' }, checkedAt === null ? t('updatesNeverChecked') : t('updatesLastChecked', { time: formatTimeOnly(checkedAt) }))),
|
|
2186
|
+
|
|
2187
|
+
// 列表
|
|
2188
|
+
visibleRows.length === 0
|
|
2189
|
+
? h('p', { className: 'pmu-hint' }, loaded
|
|
2190
|
+
? (rows.length === 0
|
|
2191
|
+
? t('updatesEmpty')
|
|
2192
|
+
: (searchedCount === 0
|
|
2193
|
+
? t('updatesEmptyFilter')
|
|
2194
|
+
: (hiddenFailedCount > 0 && settings.showFailed !== true ? t('updatesEmptyShowFailed') : t('updatesEmptyNoUpdate'))))
|
|
2195
|
+
: t('updatesLoading'))
|
|
2196
|
+
: h('div', { className: 'pmu-list' }, ...visibleRows.map(row => renderRow(row))),
|
|
2197
|
+
|
|
2198
|
+
// 更新确认框
|
|
2199
|
+
confirm !== null && h(UpdatesModal, {
|
|
2200
|
+
title: confirm.rows.length === 1 ? t('updatesConfirmTitle') : t('updatesConfirmTitleBulk', { n: confirm.rows.length }),
|
|
2201
|
+
onClose: () => { setConfirm(null) },
|
|
2202
|
+
},
|
|
2203
|
+
h('p', { className: 'pmu-modalBody' }, confirm.rows.length === 1 ? t('updatesConfirmLeadSingle') : t('updatesConfirmLeadBulk', { n: confirm.rows.length })),
|
|
2204
|
+
...confirm.rows.slice(0, 20).map(row => h(ConfirmRow, { key: `${row.key}:confirm`, row, t })),
|
|
2205
|
+
h('p', { className: 'pmu-modalBody' }, t('updatesConfirmRollback')),
|
|
2206
|
+
h('p', { className: 'pmu-hint' }, t('updatesConfirmQueue')),
|
|
2207
|
+
h('div', { className: 'pmu-modalActions' },
|
|
2208
|
+
h('button', { type: 'button', className: 'pmp-btn', onClick: () => { setConfirm(null) } }, t('updatesCancel')),
|
|
2209
|
+
h('button', { type: 'button', className: 'pmp-btn pmp-btnPrimary', disabled: busy !== '', onClick: () => { void startApply(confirm.rows) } }, t('updatesConfirmNow')))),
|
|
2210
|
+
|
|
2211
|
+
// 豁免:第二层确认弹窗(勾选风险在第一层,见行的展开区)
|
|
2212
|
+
h(UpdatesExemptDialogs, {
|
|
2213
|
+
pending: confirmSecond,
|
|
2214
|
+
t,
|
|
2215
|
+
onCancel: () => { setConfirmSecond(null); setExemptAck({}) },
|
|
2216
|
+
onConfirm: () => {
|
|
2217
|
+
const target = confirmSecond
|
|
2218
|
+
setConfirmSecond(null)
|
|
2219
|
+
setExemptAck({})
|
|
2220
|
+
if (target !== null) void exemptAndUpdate(target.row, target.incompatibility)
|
|
2221
|
+
},
|
|
2222
|
+
}),
|
|
2223
|
+
)
|
|
2224
|
+
|
|
2225
|
+
/**
|
|
2226
|
+
* 渲染一行。
|
|
2227
|
+
* @param {object} row - 行数据。
|
|
2228
|
+
* @returns {object} React 元素。
|
|
2229
|
+
*/
|
|
2230
|
+
function renderRow(row) {
|
|
2231
|
+
const key = row.key
|
|
2232
|
+
const exempt = text(exempted[seen(row.name, row.latest)]) !== ''
|
|
2233
|
+
const incompatible = row.incompatible === true && !exempt
|
|
2234
|
+
const selectable = selectableRow(row)
|
|
2235
|
+
const showExempt = incompatible && canExempt(row)
|
|
2236
|
+
const exemptOpen = showExempt && exemptPanels[key] === true
|
|
2237
|
+
const acked = ackOf(key)
|
|
2238
|
+
return h('div', {
|
|
2239
|
+
className: 'pmu-row', key, 'data-tone': incompatible ? 'bad' : undefined,
|
|
2240
|
+
'data-busy': busy === `exempt:${row.name}` ? 'true' : undefined,
|
|
2241
|
+
},
|
|
2242
|
+
h('div', { className: 'pmu-rowMain' },
|
|
2243
|
+
h('input', {
|
|
2244
|
+
type: 'checkbox', className: 'pmu-check', 'aria-label': row.name,
|
|
2245
|
+
checked: selected[key] === true, disabled: !selectable || busy !== '',
|
|
2246
|
+
onChange: () => { toggleSelect(key, selected[key] !== true) },
|
|
2247
|
+
}),
|
|
2248
|
+
// 插件名(网格第 2 列,吃剩余空间;过长省略号 + title 显示全名)。
|
|
2249
|
+
openPackage !== null
|
|
2250
|
+
? h('button', {
|
|
2251
|
+
type: 'button', className: 'pmu-name pmu-nameLink pmu-nameCell', title: row.name,
|
|
2252
|
+
onClick: () => { openDetails(row.name) },
|
|
2253
|
+
}, row.name)
|
|
2254
|
+
: h('span', { className: 'pmu-name pmu-nameCell', title: row.name }, row.name),
|
|
2255
|
+
// 中间固定列:来源 → 版本变动(所有行共享同一轨道,垂直对齐)。
|
|
2256
|
+
h(KindBadge, { kind: row.kind, t }),
|
|
2257
|
+
h('span', { className: 'pmu-versions' },
|
|
2258
|
+
row.current === '' ? t('updatesUnknownVersion') : row.current,
|
|
2259
|
+
h('span', { className: 'pmu-arrow' }, '→'),
|
|
2260
|
+
row.latest === '' ? t('updatesUnknownVersion') : row.latest),
|
|
2261
|
+
// 弹性空隙 + 已禁用列(空也占位)+ 主状态列 + 操作列(右对齐、内部可换行)。
|
|
2262
|
+
h('span', { className: 'pmu-spacer' }),
|
|
2263
|
+
h(DisabledBadge, { row, t }),
|
|
2264
|
+
h(StatusBadge, { row, exempted: exempt, t }),
|
|
2265
|
+
h('span', { className: 'pmu-rowActions' },
|
|
2266
|
+
h('button', {
|
|
2267
|
+
type: 'button', className: 'pmp-btn pmp-btnPrimary',
|
|
2268
|
+
disabled: !selectable || incompatible || busy !== '',
|
|
2269
|
+
onClick: () => { openConfirm({ rows: [row] }) },
|
|
2270
|
+
}, t('updatesRowUpdate')),
|
|
2271
|
+
showExempt && h('button', {
|
|
2272
|
+
type: 'button', className: 'pmp-btn pmp-btnDanger',
|
|
2273
|
+
'aria-expanded': exemptOpen ? 'true' : 'false',
|
|
2274
|
+
disabled: busy !== '',
|
|
2275
|
+
onClick: () => { toggleExemptPanel(key) },
|
|
2276
|
+
}, t('updatesExemptEntry'))) ),
|
|
2277
|
+
|
|
2278
|
+
// 版本豁免:入口展开风险勾选 → 「豁免此版本并更新」 → 二次确认弹窗 → POST /updates/exempt
|
|
2279
|
+
exemptOpen && h('div', { className: 'pmu-detail pmu-exempt' },
|
|
2280
|
+
h('p', { className: 'pmu-hint' }, t('updatesExemptIntro')),
|
|
2281
|
+
h('label', { className: 'pmu-ack' },
|
|
2282
|
+
h('input', {
|
|
2283
|
+
type: 'checkbox', className: 'pmu-check', 'aria-label': t('updatesExemptAck'),
|
|
2284
|
+
checked: acked, disabled: busy !== '',
|
|
2285
|
+
onChange: () => { setAck(key, !acked) },
|
|
2286
|
+
}),
|
|
2287
|
+
t('updatesExemptAck')),
|
|
2288
|
+
h('div', { className: 'pmu-rowActions' },
|
|
2289
|
+
h('button', {
|
|
2290
|
+
type: 'button', className: 'pmp-btn pmp-btnDanger',
|
|
2291
|
+
disabled: acked !== true || busy !== '',
|
|
2292
|
+
onClick: () => { setConfirmSecond({ row, incompatibility: row.incompatibility }) },
|
|
2293
|
+
}, busy === `exempt:${row.name}` ? t('updatesExemptDoing') : t('updatesExemptFlow')))))
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2296
|
+
/** 清掉阶段历史(关闭进度视图时)。 */
|
|
2297
|
+
function setStagesRefSafe() {
|
|
2298
|
+
stagesRef.current = {}
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2302
|
+
/**
|
|
2303
|
+
* 豁免流程的第二层:风险说明 + 二次确认弹窗。
|
|
2304
|
+
* @param {object} props - 组件属性。
|
|
2305
|
+
* @returns {object} React 元素。
|
|
2306
|
+
*/
|
|
2307
|
+
function UpdatesExemptDialogs(props) {
|
|
2308
|
+
const { pending, t, onCancel, onConfirm } = props
|
|
2309
|
+
if (pending === null || pending === undefined) return null
|
|
2310
|
+
const row = pending.row
|
|
2311
|
+
const incompatibility = rec(pending.incompatibility)
|
|
2312
|
+
const runtime = text(incompatibility.runtimeVersion) || '—'
|
|
2313
|
+
return h(UpdatesModal, { title: t('updatesExemptConfirmTitle'), onClose: onCancel },
|
|
2314
|
+
h('p', { className: 'pmu-modalBody' }, t('updatesExemptConfirmBody', { pkg: `${row.name}@${row.latest}`, runtime, target: row.latest })),
|
|
2315
|
+
h('p', { className: 'pmu-hint' }, t('updatesExemptIntro')),
|
|
2316
|
+
h('p', { className: 'pmu-hint' }, `${row.name}@${row.latest} × DSH ${runtime}`),
|
|
2317
|
+
h('div', { className: 'pmu-modalActions' },
|
|
2318
|
+
h('button', { type: 'button', className: 'pmp-btn', onClick: onCancel }, t('updatesCancel')),
|
|
2319
|
+
h('button', { type: 'button', className: 'pmp-btn pmp-btnDanger', onClick: onConfirm }, t('updatesExemptConfirmYes'))))
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
/**
|
|
2323
|
+
* GET 同源 JSON。
|
|
2324
|
+
* @param {string} path - API 子路径。
|
|
2325
|
+
* @returns {Promise<object>} 响应体。
|
|
2326
|
+
*/
|
|
2327
|
+
async function getJson(path) {
|
|
2328
|
+
const response = await fetch(api(path), { headers: { accept: 'application/json' }, credentials: 'same-origin' })
|
|
2329
|
+
const payload = await readBody(response)
|
|
2330
|
+
if (!response || response.ok !== true) throw new Error(messageOf(payload, response))
|
|
2331
|
+
if (payload.ok === false) throw new Error(messageOf(payload, response))
|
|
2332
|
+
return payload
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
/**
|
|
2336
|
+
* POST 同源 JSON。
|
|
2337
|
+
* @param {string} path - API 子路径。
|
|
2338
|
+
* @param {object} body - 请求体。
|
|
2339
|
+
* @returns {Promise<object>} 响应体。
|
|
2340
|
+
*/
|
|
2341
|
+
async function postJson(path, body) {
|
|
2342
|
+
const response = await fetch(api(path), {
|
|
2343
|
+
method: 'POST',
|
|
2344
|
+
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
2345
|
+
credentials: 'same-origin',
|
|
2346
|
+
body: JSON.stringify(body ?? {}),
|
|
2347
|
+
})
|
|
2348
|
+
const payload = await readBody(response)
|
|
2349
|
+
if (!response || response.ok !== true) throw new Error(messageOf(payload, response))
|
|
2350
|
+
if (payload.ok === false) throw new Error(messageOf(payload, response))
|
|
2351
|
+
return payload
|
|
2352
|
+
}
|
|
2353
|
+
|
|
2354
|
+
/**
|
|
2355
|
+
* 读取响应体(非 JSON 时退化成文本)。
|
|
2356
|
+
* @param {object} response - fetch 响应。
|
|
2357
|
+
* @returns {Promise<object>} 响应体。
|
|
2358
|
+
*/
|
|
2359
|
+
async function readBody(response) {
|
|
2360
|
+
if (typeof response?.json === 'function') {
|
|
2361
|
+
try {
|
|
2362
|
+
return rec(await response.json())
|
|
2363
|
+
} catch {
|
|
2364
|
+
return {}
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
if (typeof response?.text === 'function') {
|
|
2368
|
+
try {
|
|
2369
|
+
const raw = await response.text()
|
|
2370
|
+
return raw === '' ? {} : { message: raw }
|
|
2371
|
+
} catch {
|
|
2372
|
+
return {}
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
return {}
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
/**
|
|
2379
|
+
* 组装错误信息。
|
|
2380
|
+
* @param {object} payload - 响应体。
|
|
2381
|
+
* @param {object} response - fetch 响应。
|
|
2382
|
+
* @returns {string} 错误文本。
|
|
2383
|
+
*/
|
|
2384
|
+
function messageOf(payload, response) {
|
|
2385
|
+
const message = text(rec(payload).message) || text(rec(payload).error)
|
|
2386
|
+
if (message !== '') return message
|
|
2387
|
+
const status = num(response?.status, 0)
|
|
2388
|
+
return status > 0 ? `HTTP ${status}` : 'request failed'
|
|
479
2389
|
}
|
|
480
2390
|
|
|
481
2391
|
return {
|
|
482
2392
|
inject: ['slots', 'locale'],
|
|
2393
|
+
/** 纯逻辑/常量出口,仅供自检脚本读取;不参与运行时行为。 */
|
|
2394
|
+
inspectable,
|
|
483
2395
|
apply(ctx) {
|
|
484
2396
|
ctx.effect(() => ctx.locale.register(NS, { zh: I18N.zh, en: I18N.en }), 'dsh-pluginmarket-plus: dictionaries')
|
|
485
2397
|
|
|
@@ -494,30 +2406,26 @@ window.__ModuleLoader__.load({
|
|
|
494
2406
|
|
|
495
2407
|
const t = ctx.locale.bind(NS)
|
|
496
2408
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
2409
|
+
// 插件页(Plugins)「插件源缓存」标签:排在自带的 Discover 之后、「可更新」之前。
|
|
2410
|
+
ctx.slots.inject(UPDATES_SLOT, () => ctx.slots.register({
|
|
2411
|
+
name: UPDATES_SLOT,
|
|
2412
|
+
id: CACHE_ID,
|
|
2413
|
+
order: CACHE_ORDER,
|
|
2414
|
+
label: () => t('cacheTab'),
|
|
502
2415
|
locale: NS,
|
|
503
2416
|
inject: () => ({ t }),
|
|
504
2417
|
}, MarketCacheSection))
|
|
505
2418
|
|
|
506
|
-
//
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
2419
|
+
// 插件页(Plugins)新增「可更新」标签:排在自带的 Installed / Discover 之后。
|
|
2420
|
+
// 数据只走同源 /api/pluginmarket-plus/updates*;「详情」复用官方详情页。
|
|
2421
|
+
ctx.slots.inject(UPDATES_SLOT, () => ctx.slots.register({
|
|
2422
|
+
name: UPDATES_SLOT,
|
|
2423
|
+
id: UPDATES_ID,
|
|
2424
|
+
order: UPDATES_ORDER,
|
|
2425
|
+
label: () => t('updatesTab'),
|
|
512
2426
|
locale: NS,
|
|
513
2427
|
inject: () => ({ t }),
|
|
514
|
-
},
|
|
515
|
-
|
|
516
|
-
ctx.slots.inject('settings.section.icon', () => ctx.slots.register({
|
|
517
|
-
name: 'settings.section.icon',
|
|
518
|
-
id: 'pluginmarket-plus',
|
|
519
|
-
order: 41,
|
|
520
|
-
}, CacheIcon))
|
|
2428
|
+
}, UpdatesSection))
|
|
521
2429
|
},
|
|
522
2430
|
}
|
|
523
2431
|
},
|