dsh-bulk-update 0.0.0-stage → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.en.md +91 -0
- package/README.md +89 -2
- package/client.js +1041 -0
- package/cordis.patch.yml +7 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/preview.svg +50 -0
- package/icon.svg +6 -0
- package/index.js +8 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +60 -4
package/client.js
ADDED
|
@@ -0,0 +1,1041 @@
|
|
|
1
|
+
// Browser half of dsh-bulk-update: the "批量更新 / Bulk update" tab of the
|
|
2
|
+
// Plugins page. Tick the third-party plugins installed in this profile, check
|
|
3
|
+
// which have a newer release, then update the ticked ones in order with one
|
|
4
|
+
// click. Everything goes through the shipped `pluginManager` Remote, so this
|
|
5
|
+
// package adds no Host behaviour and never runs in the background.
|
|
6
|
+
//
|
|
7
|
+
// Hand-written in the shape DSH's module loader expects, so the package needs
|
|
8
|
+
// no build step.
|
|
9
|
+
window.__ModuleLoader__.load({
|
|
10
|
+
id: 'dsh-bulk-update',
|
|
11
|
+
factory(require) {
|
|
12
|
+
const React = require('react');
|
|
13
|
+
const h = React.createElement;
|
|
14
|
+
|
|
15
|
+
/** Dictionary namespace owned by this tab. */
|
|
16
|
+
const NS = 'bulkUpdate';
|
|
17
|
+
/** Where the ticked packages are remembered, so a reload keeps the choice. */
|
|
18
|
+
const STORAGE_KEY = 'dsh-bulk-update:selection';
|
|
19
|
+
/**
|
|
20
|
+
* How many packages to check at once.
|
|
21
|
+
*
|
|
22
|
+
* This is not the only concurrency in play: the Host answers one `listVersions` by running `pnpm view` once for
|
|
23
|
+
* the version list and then once per newer version, up to its `versionListLimit` (20 by default), with its own
|
|
24
|
+
* `versionLookupConcurrency` (4). Two packages here therefore start up to eight pnpm processes that each parse a
|
|
25
|
+
* dependency tree, which is the whole cost of a check on a profile whose plugins publish hundreds of versions.
|
|
26
|
+
* One is the calmest setting; two halves the wall-clock time against one and still leaves half the machine idle.
|
|
27
|
+
*/
|
|
28
|
+
const CHECK_CONCURRENCY = 2;
|
|
29
|
+
/**
|
|
30
|
+
* How long a finished check stays usable. A run reuses an answer this recent instead of asking again, so pressing
|
|
31
|
+
* Check and then Update does not query every package twice. Older answers are re-read: a release that appeared
|
|
32
|
+
* since then must not be reported as absent.
|
|
33
|
+
*/
|
|
34
|
+
const CHECK_FRESH_MS = 5 * 60 * 1000;
|
|
35
|
+
|
|
36
|
+
// ---------------------------------------------------------------------
|
|
37
|
+
// Copy
|
|
38
|
+
// ---------------------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
const zh = {
|
|
41
|
+
title: '批量更新',
|
|
42
|
+
heading: '批量更新第三方插件',
|
|
43
|
+
intro: '勾选要管理的插件,检查有没有新版本,然后按顺序一次更新完。只列出你自己安装的第三方插件;DSH 自带的插件不会出现在这里,也不会被改动。',
|
|
44
|
+
refresh: '刷新列表',
|
|
45
|
+
check: '检查更新',
|
|
46
|
+
update: '一键更新',
|
|
47
|
+
checking: '正在检查…',
|
|
48
|
+
updating: '正在更新…',
|
|
49
|
+
selectAll: '全选',
|
|
50
|
+
selectNone: '全不选',
|
|
51
|
+
empty: '这个 profile 里没有可以自动更新的第三方插件。',
|
|
52
|
+
loading: '正在读取已安装的插件…',
|
|
53
|
+
loadFailed: '读取插件列表失败:{reason}',
|
|
54
|
+
name: '插件',
|
|
55
|
+
current: '当前版本',
|
|
56
|
+
latest: '最新版本',
|
|
57
|
+
state: '状态',
|
|
58
|
+
noCheck: '未检查',
|
|
59
|
+
rowChecking: '正在检查…',
|
|
60
|
+
upToDate: '已是最新',
|
|
61
|
+
updateAvailable: '可更新到 {version}',
|
|
62
|
+
updateSkipped: '没有可用更新',
|
|
63
|
+
checkFailed: '检查失败:{reason}',
|
|
64
|
+
notUpdatable: 'Git 安装,不能自动更新',
|
|
65
|
+
notUpdatableHint: '从 Git 安装的插件只能手动换到另一个提交。',
|
|
66
|
+
enabled: '已启用',
|
|
67
|
+
enabledShort: '已启用',
|
|
68
|
+
disabledShort: '已停用',
|
|
69
|
+
disabledHint: '已安装但在 profile 里没有启用。更新它会装上,但启用与否仍由插件页决定。',
|
|
70
|
+
summary: '共 {total} 个插件 · 已启用 {enabled} 个 · 已勾选 {selected} 个 · {updates}',
|
|
71
|
+
updatesNone: '尚未检查更新',
|
|
72
|
+
updatesChecking: '正在检查…',
|
|
73
|
+
updatesFound: '其中 {count} 个有新版本',
|
|
74
|
+
checkedAt: '上次检查:{time}',
|
|
75
|
+
neverChecked: '还没有检查过',
|
|
76
|
+
runTitle: '更新进度',
|
|
77
|
+
runIdle: '还没有开始更新。勾选插件后点「一键更新」。',
|
|
78
|
+
runSummary: '完成 {done} / {total},成功 {ok} 个,失败 {failed} 个',
|
|
79
|
+
runAllCurrent: '全部已是最新,没有需要更新的:勾选的 {count} 个插件都已是正式版里的最高版本。',
|
|
80
|
+
runPreparing: '正在检查勾选的插件…',
|
|
81
|
+
runNothing: '勾选的插件都没有可用更新。',
|
|
82
|
+
runUpdating: '正在更新 {name}({from} → {to})…',
|
|
83
|
+
runSuccess: '成功',
|
|
84
|
+
runFailed: '失败',
|
|
85
|
+
runRestart: '成功,需要重启 DSH 才加载新版本',
|
|
86
|
+
runCancelled: '已停止',
|
|
87
|
+
stop: '停止',
|
|
88
|
+
stopped: '下一次更新结束后停止。',
|
|
89
|
+
incompatibleSkipped: '跳过 {name}:{version} 不兼容当前 DSH',
|
|
90
|
+
prereleaseNote: '只选正式版:预发布版本和已弃用版本不会被自动选中。',
|
|
91
|
+
slowCheckHint: '插件较多时第一次检查会比较慢:每个包都要查一次版本列表,再逐个版本核对兼容性。',
|
|
92
|
+
leftCount: '另有 {count} 个新版本未列出',
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const en = {
|
|
96
|
+
title: 'Bulk update',
|
|
97
|
+
heading: 'Bulk update third-party plugins',
|
|
98
|
+
intro: 'Tick the plugins you want to manage, check for newer releases, then update them all in order with one click. Only third-party plugins you installed yourself are listed; the plugins DSH ships are left out and never touched.',
|
|
99
|
+
refresh: 'Refresh list',
|
|
100
|
+
check: 'Check for updates',
|
|
101
|
+
update: 'Update selected',
|
|
102
|
+
checking: 'Checking…',
|
|
103
|
+
updating: 'Updating…',
|
|
104
|
+
selectAll: 'Select all',
|
|
105
|
+
selectNone: 'Clear selection',
|
|
106
|
+
empty: 'No third-party plugins in this profile can be updated automatically.',
|
|
107
|
+
loading: 'Reading the installed plugins…',
|
|
108
|
+
loadFailed: 'Could not read the plugin list: {reason}',
|
|
109
|
+
name: 'Plugin',
|
|
110
|
+
current: 'Installed',
|
|
111
|
+
latest: 'Latest',
|
|
112
|
+
state: 'Status',
|
|
113
|
+
noCheck: 'Not checked',
|
|
114
|
+
rowChecking: 'Checking…',
|
|
115
|
+
upToDate: 'Up to date',
|
|
116
|
+
updateAvailable: 'Update to {version}',
|
|
117
|
+
updateSkipped: 'No update available',
|
|
118
|
+
checkFailed: 'Check failed: {reason}',
|
|
119
|
+
notUpdatable: 'Installed from Git, cannot update automatically',
|
|
120
|
+
notUpdatableHint: 'A plugin installed from Git only moves to another commit by hand.',
|
|
121
|
+
enabled: 'Enabled',
|
|
122
|
+
enabledShort: 'Enabled',
|
|
123
|
+
disabledShort: 'Disabled',
|
|
124
|
+
disabledHint: 'Installed but not switched on in this profile. Updating it installs the package; switching it on stays the Plugins page decision.',
|
|
125
|
+
summary: '{total} plugins · {enabled} enabled · {selected} selected · {updates}',
|
|
126
|
+
updatesNone: 'not checked yet',
|
|
127
|
+
updatesChecking: 'checking…',
|
|
128
|
+
updatesFound: '{count} with a newer release',
|
|
129
|
+
checkedAt: 'Last checked: {time}',
|
|
130
|
+
neverChecked: 'Not checked yet',
|
|
131
|
+
runTitle: 'Progress',
|
|
132
|
+
runIdle: 'No run yet. Tick the plugins you want, then press Update selected.',
|
|
133
|
+
runSummary: 'Finished {done} / {total}, {ok} updated, {failed} failed',
|
|
134
|
+
runAllCurrent: 'Everything is current: all {count} selected plugins are already on the newest stable release.',
|
|
135
|
+
runPreparing: 'Checking the selected plugins…',
|
|
136
|
+
runNothing: 'None of the selected plugins has an update available.',
|
|
137
|
+
runUpdating: 'Updating {name} ({from} → {to})…',
|
|
138
|
+
runSuccess: 'Updated',
|
|
139
|
+
runFailed: 'Failed',
|
|
140
|
+
runRestart: 'Updated; a restart is needed to load the new version',
|
|
141
|
+
runCancelled: 'Stopped',
|
|
142
|
+
stop: 'Stop',
|
|
143
|
+
stopped: 'Stopping after the update in flight finishes.',
|
|
144
|
+
incompatibleSkipped: 'Skipped {name}: {version} does not accept this DSH',
|
|
145
|
+
prereleaseNote: 'Stable releases only: prereleases and deprecated versions are never selected automatically.',
|
|
146
|
+
slowCheckHint: 'The first check of a large profile is slow: each package costs a version-list lookup plus one per newer version to test compatibility.',
|
|
147
|
+
leftCount: '{count} earlier newer versions are not listed',
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// ---------------------------------------------------------------------
|
|
151
|
+
// A tiny snapshot store, so the tab re-renders on every controller update
|
|
152
|
+
// without depending on any other Harness Client package.
|
|
153
|
+
// ---------------------------------------------------------------------
|
|
154
|
+
|
|
155
|
+
function createStore(initial) {
|
|
156
|
+
let snapshot = initial;
|
|
157
|
+
const listeners = new Set();
|
|
158
|
+
return {
|
|
159
|
+
getSnapshot: () => snapshot,
|
|
160
|
+
subscribe(listener) {
|
|
161
|
+
listeners.add(listener);
|
|
162
|
+
return () => {
|
|
163
|
+
listeners.delete(listener);
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
patch(fields) {
|
|
167
|
+
snapshot = { ...snapshot, ...fields };
|
|
168
|
+
for (const listener of [...listeners]) {
|
|
169
|
+
try {
|
|
170
|
+
listener();
|
|
171
|
+
} catch (error) {
|
|
172
|
+
// A broken subscriber must not stop the others from updating.
|
|
173
|
+
void error;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ---------------------------------------------------------------------
|
|
181
|
+
// Selection persistence
|
|
182
|
+
// ---------------------------------------------------------------------
|
|
183
|
+
|
|
184
|
+
function readSelection() {
|
|
185
|
+
try {
|
|
186
|
+
const raw = window.localStorage.getItem(STORAGE_KEY);
|
|
187
|
+
if (raw === null) return null;
|
|
188
|
+
const parsed = JSON.parse(raw);
|
|
189
|
+
return Array.isArray(parsed) ? parsed.filter((name) => typeof name === 'string') : null;
|
|
190
|
+
} catch (error) {
|
|
191
|
+
void error;
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function writeSelection(names) {
|
|
197
|
+
try {
|
|
198
|
+
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(names));
|
|
199
|
+
} catch (error) {
|
|
200
|
+
// A profile with storage disabled still works for this session.
|
|
201
|
+
void error;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// ---------------------------------------------------------------------
|
|
206
|
+
// Reading the Host's answers
|
|
207
|
+
// ---------------------------------------------------------------------
|
|
208
|
+
|
|
209
|
+
/** The newest version that can replace the installed one: a bundle, compatible, stable, not deprecated. */
|
|
210
|
+
function updateCandidate(list) {
|
|
211
|
+
if (list === undefined || list === null || list.status !== 'listed') return undefined;
|
|
212
|
+
return list.versions.find((version) => version.bundle === true
|
|
213
|
+
&& version.incompatible === undefined
|
|
214
|
+
&& version.deprecated === undefined
|
|
215
|
+
&& version.prerelease !== true);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** The newest stable version the running DSH refuses, which the row explains instead of offering it. */
|
|
219
|
+
function firstRejected(list) {
|
|
220
|
+
if (list === undefined || list === null || list.status !== 'listed') return undefined;
|
|
221
|
+
return list.versions.find((version) => version.prerelease !== true && version.incompatible !== undefined);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** A refused Remote answer in the words the Host gave. */
|
|
225
|
+
function failureText(answer) {
|
|
226
|
+
const error = answer === undefined || answer === null ? undefined : answer.error;
|
|
227
|
+
if (error === undefined || error === null) return 'unknown error';
|
|
228
|
+
return typeof error.message === 'string' && error.message !== '' ? error.message : 'unknown error';
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** An exception thrown by the transport, in its own words. */
|
|
232
|
+
function thrownText(error) {
|
|
233
|
+
return error instanceof Error ? error.message : String(error);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Whether a bundle is a third-party plugin installed in this profile that the Host can replace. */
|
|
237
|
+
function manageable(bundle) {
|
|
238
|
+
return bundle.installed === true
|
|
239
|
+
&& bundle.official !== true
|
|
240
|
+
&& bundle.availability === 'profile'
|
|
241
|
+
&& bundle.readOnlyReason === undefined
|
|
242
|
+
&& bundle.update !== undefined;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** Whether this tab can replace the bundle itself rather than asking for a Git commit. */
|
|
246
|
+
function autoUpdatable(row) {
|
|
247
|
+
return row.update === 'registry';
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Whether a click on a row should toggle its tick: yes for the row's free area, never for a click that starts on
|
|
252
|
+
* a control. The box handles its own clicks through `onChange`, and toggling here as well would undo it.
|
|
253
|
+
* @param target The click's target, or anything with `tagName` and `closest`.
|
|
254
|
+
* @param disabled Whether the row ignores clicks at all.
|
|
255
|
+
* @returns true when the row itself should toggle the tick.
|
|
256
|
+
*/
|
|
257
|
+
function rowClickToggles(target, disabled) {
|
|
258
|
+
if (disabled) return false;
|
|
259
|
+
if (target === null || target === undefined) return false;
|
|
260
|
+
if (typeof target.closest !== 'function') return false;
|
|
261
|
+
// `closest` covers a click on a child of a control, such as the box's own glyph.
|
|
262
|
+
return target.closest('input,a,button,label,select,textarea') === null;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// ---------------------------------------------------------------------
|
|
266
|
+
// Controller: the Host's plugins, the checks, the run, and the ticks
|
|
267
|
+
// ---------------------------------------------------------------------
|
|
268
|
+
|
|
269
|
+
function createController(ctx) {
|
|
270
|
+
const store = createStore({
|
|
271
|
+
status: 'idle',
|
|
272
|
+
error: null,
|
|
273
|
+
rows: [],
|
|
274
|
+
selected: [],
|
|
275
|
+
selectionReady: false,
|
|
276
|
+
checks: {},
|
|
277
|
+
run: null,
|
|
278
|
+
stopped: false,
|
|
279
|
+
});
|
|
280
|
+
let disposed = false;
|
|
281
|
+
let busy = false;
|
|
282
|
+
/** Set by the Stop button; read between two updates so the one in flight always finishes. */
|
|
283
|
+
let stopRequested = false;
|
|
284
|
+
|
|
285
|
+
const state = () => store.getSnapshot();
|
|
286
|
+
const patch = (fields) => {
|
|
287
|
+
if (!disposed) store.patch(fields);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/** The display name of a row: its localized title, else its package name. */
|
|
291
|
+
const titleOf = (row) => {
|
|
292
|
+
const title = row.title;
|
|
293
|
+
if (title === undefined) return row.name;
|
|
294
|
+
try {
|
|
295
|
+
return typeof ctx.locale.resolveText === 'function' ? ctx.locale.resolveText(title) : String(title);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
void error;
|
|
298
|
+
return row.name;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/** Read the profile's managed bundles, keeping the ticks that still name a listed package. */
|
|
303
|
+
const load = async () => {
|
|
304
|
+
if (state().status === 'idle') patch({ status: 'loading' });
|
|
305
|
+
let answer;
|
|
306
|
+
try {
|
|
307
|
+
answer = await ctx.remote.pluginManager.listBundles();
|
|
308
|
+
} catch (error) {
|
|
309
|
+
patch({ status: 'error', error: thrownText(error) });
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (disposed) return;
|
|
313
|
+
if (!answer.ok) {
|
|
314
|
+
patch({ status: 'error', error: failureText(answer) });
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const rows = answer.value.filter(manageable).map((bundle) => ({
|
|
318
|
+
name: bundle.name,
|
|
319
|
+
title: bundle.meta === undefined ? undefined : bundle.meta.title,
|
|
320
|
+
// A base64 data URL the Host read from the package's manifest icon or its exported `./icon`.
|
|
321
|
+
icon: bundle.meta === undefined ? undefined : bundle.meta.icon,
|
|
322
|
+
version: bundle.version,
|
|
323
|
+
update: bundle.update,
|
|
324
|
+
enabled: bundle.enabled === true,
|
|
325
|
+
description: bundle.description,
|
|
326
|
+
})).sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
327
|
+
const names = new Set(rows.map((row) => row.name));
|
|
328
|
+
const savedSelection = readSelection();
|
|
329
|
+
const initial = state().selectionReady
|
|
330
|
+
? state().selected
|
|
331
|
+
: (savedSelection === null ? rows.filter(autoUpdatable).map((row) => row.name) : savedSelection);
|
|
332
|
+
const selected = initial.filter((name) => names.has(name));
|
|
333
|
+
patch({ status: 'ready', error: null, rows, selected, selectionReady: true });
|
|
334
|
+
writeSelection(selected);
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Check one package's newer versions and keep the answer.
|
|
339
|
+
* @returns the stored check entry, so a run can reuse it without asking again.
|
|
340
|
+
*/
|
|
341
|
+
const checkOne = async (name) => {
|
|
342
|
+
// One publish for the in-flight mark, one for the answer. Each publish
|
|
343
|
+
// copies the whole check table, so two per package on a 17-plugin profile
|
|
344
|
+
// copied it 34 times; the copy is the cost, not the network call.
|
|
345
|
+
patch({ checks: { ...state().checks, [name]: { phase: 'checking' } } });
|
|
346
|
+
let entry;
|
|
347
|
+
try {
|
|
348
|
+
// The generated Remote takes every business argument before its optional signal; `{}` asks the Host's plan.
|
|
349
|
+
const answer = await ctx.remote.pluginManager.listVersions(name, {});
|
|
350
|
+
entry = answer.ok
|
|
351
|
+
? { phase: 'done', list: answer.value, checkedAt: Date.now() }
|
|
352
|
+
: { phase: 'done', failure: failureText(answer), checkedAt: Date.now() };
|
|
353
|
+
} catch (error) {
|
|
354
|
+
entry = { phase: 'done', failure: thrownText(error), checkedAt: Date.now() };
|
|
355
|
+
}
|
|
356
|
+
if (!disposed) patch({ checks: { ...state().checks, [name]: entry } });
|
|
357
|
+
return entry;
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
/** Look one package up without publishing; the batch publishes when it is done. */
|
|
361
|
+
const checkOneQuiet = async (name) => {
|
|
362
|
+
try {
|
|
363
|
+
const answer = await ctx.remote.pluginManager.listVersions(name, {});
|
|
364
|
+
return answer.ok
|
|
365
|
+
? { phase: 'done', list: answer.value, checkedAt: Date.now() }
|
|
366
|
+
: { phase: 'done', failure: failureText(answer), checkedAt: Date.now() };
|
|
367
|
+
} catch (error) {
|
|
368
|
+
return { phase: 'done', failure: thrownText(error), checkedAt: Date.now() };
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Check many packages, publishing each answer as it lands.
|
|
374
|
+
*
|
|
375
|
+
* A per-package publish is what lets a row show its result the moment that
|
|
376
|
+
* package is done, instead of the whole list filling in at once after the
|
|
377
|
+
* last lookup. The store copies the check table on every publish, which is
|
|
378
|
+
* cheap next to a registry round trip, so the earlier batching was trading
|
|
379
|
+
* the only visible progress for a saving nobody could feel.
|
|
380
|
+
*
|
|
381
|
+
* Only the checking runs in parallel: `listVersions` reads the registry and
|
|
382
|
+
* writes nothing, so several may overlap. Installation may not: the Host
|
|
383
|
+
* holds the profile's `package.json` lock for a whole `updateBundle`, and a
|
|
384
|
+
* second concurrent install would wait out that lock and race the lockfile.
|
|
385
|
+
* @param names The package names to check.
|
|
386
|
+
* @param limit The most lookups in flight.
|
|
387
|
+
* @returns the answers, keyed by package name.
|
|
388
|
+
*/
|
|
389
|
+
const checkBatch = async (names, limit = CHECK_CONCURRENCY) => {
|
|
390
|
+
if (names.length === 0) return {};
|
|
391
|
+
// Mark every target as in flight before the first lookup. Without this a
|
|
392
|
+
// second check looked frozen: each row already read "up to date", its
|
|
393
|
+
// answer came back "up to date" again, and nothing on screen moved until
|
|
394
|
+
// the whole batch finished. The mark is one publish for the batch.
|
|
395
|
+
const pending = { ...state().checks };
|
|
396
|
+
for (const name of names) pending[name] = { phase: 'checking' };
|
|
397
|
+
if (!disposed) patch({ checks: pending });
|
|
398
|
+
|
|
399
|
+
const results = {};
|
|
400
|
+
const queue = [...names];
|
|
401
|
+
const worker = async () => {
|
|
402
|
+
while (queue.length > 0) {
|
|
403
|
+
if (disposed || stopRequested) return;
|
|
404
|
+
const name = queue.shift();
|
|
405
|
+
if (name === undefined) return;
|
|
406
|
+
const entry = await checkOneQuiet(name);
|
|
407
|
+
results[name] = entry;
|
|
408
|
+
if (!disposed) patch({ checks: { ...state().checks, [name]: entry } });
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
await Promise.all(Array.from({ length: Math.min(Math.max(1, limit), queue.length) }, worker));
|
|
412
|
+
return results;
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
/** Replace one package with a version the Host already answered for. */
|
|
416
|
+
const updateOne = async (row, candidate, check) => {
|
|
417
|
+
const registry = check === undefined || check.list === undefined || check.list.status !== 'listed'
|
|
418
|
+
? undefined
|
|
419
|
+
: check.list.registry;
|
|
420
|
+
let answer;
|
|
421
|
+
try {
|
|
422
|
+
answer = await ctx.remote.pluginManager.updateBundle(row.name, candidate.version,
|
|
423
|
+
registry === undefined ? {} : { registry });
|
|
424
|
+
} catch (error) {
|
|
425
|
+
return { name: row.name, from: row.version, to: candidate.version, ok: false, message: thrownText(error) };
|
|
426
|
+
}
|
|
427
|
+
if (!answer.ok) {
|
|
428
|
+
return { name: row.name, from: row.version, to: candidate.version, ok: false, message: failureText(answer) };
|
|
429
|
+
}
|
|
430
|
+
const outcome = answer.value;
|
|
431
|
+
const change = outcome.result;
|
|
432
|
+
const applied = change.changed === true
|
|
433
|
+
&& (change.application === 'applied' || change.application === 'restart-required' || change.application === 'overridden');
|
|
434
|
+
if (!applied) {
|
|
435
|
+
const reason = change.error === undefined
|
|
436
|
+
? change.application
|
|
437
|
+
: (change.error.diagnostic === undefined ? change.error.code : change.error.diagnostic);
|
|
438
|
+
return { name: row.name, from: outcome.from, to: outcome.to, ok: false, message: String(reason) };
|
|
439
|
+
}
|
|
440
|
+
return {
|
|
441
|
+
name: row.name,
|
|
442
|
+
from: outcome.from,
|
|
443
|
+
to: outcome.to,
|
|
444
|
+
ok: true,
|
|
445
|
+
restart: change.application === 'restart-required',
|
|
446
|
+
};
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Check the ticked packages, then update each one that has a newer stable release, in list order.
|
|
451
|
+
*
|
|
452
|
+
* A target whose check finished within `CHECK_FRESH_MS` reuses that answer, so pressing Check and then Update
|
|
453
|
+
* asks the registry once rather than twice. Anything older, or never checked, is queried again: an answer from
|
|
454
|
+
* an earlier moment may predate the release that now exists, and skipping on it would report "no update" for a
|
|
455
|
+
* plugin that has one. The checks overlap, the installs do not. A failed install is recorded and the run
|
|
456
|
+
* continues, so one plugin cannot strand the rest.
|
|
457
|
+
*/
|
|
458
|
+
const runSelected = async () => {
|
|
459
|
+
if (busy) return;
|
|
460
|
+
const { rows, selected, checks } = state();
|
|
461
|
+
const targets = rows.filter((row) => selected.includes(row.name) && autoUpdatable(row));
|
|
462
|
+
if (targets.length === 0) {
|
|
463
|
+
patch({ run: { phase: 'done', total: 0, done: 0, results: [], nothing: true } });
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
busy = true;
|
|
467
|
+
stopRequested = false;
|
|
468
|
+
patch({ run: { phase: 'preparing', total: targets.length, done: 0, results: [], current: null }, stopped: false });
|
|
469
|
+
try {
|
|
470
|
+
const now = Date.now();
|
|
471
|
+
const stale = targets
|
|
472
|
+
.filter((row) => {
|
|
473
|
+
const check = checks[row.name];
|
|
474
|
+
return check === undefined || check.phase !== 'done' || now - check.checkedAt >= CHECK_FRESH_MS;
|
|
475
|
+
})
|
|
476
|
+
.map((row) => row.name);
|
|
477
|
+
await checkBatch(stale);
|
|
478
|
+
const planned = state().checks;
|
|
479
|
+
for (const row of targets) {
|
|
480
|
+
if (disposed || stopRequested) break;
|
|
481
|
+
const check = planned[row.name];
|
|
482
|
+
const candidate = updateCandidate(check === undefined ? undefined : check.list);
|
|
483
|
+
const current = state().run;
|
|
484
|
+
if (candidate === undefined) {
|
|
485
|
+
patch({
|
|
486
|
+
run: {
|
|
487
|
+
...current,
|
|
488
|
+
done: current.done + 1,
|
|
489
|
+
results: [...current.results, { name: row.name, ok: true, skipped: true }],
|
|
490
|
+
},
|
|
491
|
+
});
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
patch({ run: { ...current, phase: 'running', current: { name: row.name, from: row.version, to: candidate.version } } });
|
|
495
|
+
const result = await updateOne(row, candidate, check);
|
|
496
|
+
if (disposed) return;
|
|
497
|
+
const after = state().run;
|
|
498
|
+
patch({
|
|
499
|
+
run: {
|
|
500
|
+
...after,
|
|
501
|
+
phase: 'running',
|
|
502
|
+
current: null,
|
|
503
|
+
done: after.done + 1,
|
|
504
|
+
results: [...after.results, result],
|
|
505
|
+
},
|
|
506
|
+
});
|
|
507
|
+
await load();
|
|
508
|
+
}
|
|
509
|
+
if (disposed) return;
|
|
510
|
+
patch({ run: { ...state().run, phase: stopRequested ? 'stopped' : 'done', current: null } });
|
|
511
|
+
// Re-read only the versions this run actually replaced, so their rows
|
|
512
|
+
// show the new installs. Re-checking every ticked package here asked
|
|
513
|
+
// the registry a second time for packages that did not change.
|
|
514
|
+
const replaced = new Set(state().run.results
|
|
515
|
+
.filter((result) => result.ok === true && result.skipped !== true)
|
|
516
|
+
.map((result) => result.name));
|
|
517
|
+
await checkBatch([...replaced]);
|
|
518
|
+
} finally {
|
|
519
|
+
busy = false;
|
|
520
|
+
// The flag belongs to this run alone. Clearing only the store's notice left it set for ever, and every
|
|
521
|
+
// later `checkBatch` returns on its first test, so Check quietly stopped doing anything until the next run
|
|
522
|
+
// reset it. It is cleared here, not before the re-check above, so a stopped run does not check again.
|
|
523
|
+
stopRequested = false;
|
|
524
|
+
if (!disposed) patch({ stopped: false });
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
const toggle = (name, checked) => {
|
|
529
|
+
const selected = state().selected.filter((item) => item !== name);
|
|
530
|
+
if (checked) selected.push(name);
|
|
531
|
+
patch({ selected });
|
|
532
|
+
writeSelection(selected);
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
const selectAll = (checked) => {
|
|
536
|
+
const names = checked ? state().rows.filter(autoUpdatable).map((row) => row.name) : [];
|
|
537
|
+
patch({ selected: names });
|
|
538
|
+
writeSelection(names);
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
const requestStop = () => {
|
|
542
|
+
stopRequested = true;
|
|
543
|
+
patch({ stopped: true });
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
return {
|
|
547
|
+
store,
|
|
548
|
+
titleOf,
|
|
549
|
+
load,
|
|
550
|
+
checkBatch,
|
|
551
|
+
runSelected,
|
|
552
|
+
toggle,
|
|
553
|
+
selectAll,
|
|
554
|
+
requestStop,
|
|
555
|
+
isBusy: () => busy,
|
|
556
|
+
dispose() {
|
|
557
|
+
disposed = true;
|
|
558
|
+
},
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// ---------------------------------------------------------------------
|
|
563
|
+
// Styling: host theme tokens only, rendered as an element so unmounting
|
|
564
|
+
// removes it.
|
|
565
|
+
// ---------------------------------------------------------------------
|
|
566
|
+
|
|
567
|
+
const CSS = `
|
|
568
|
+
.bu-root{display:flex;flex-direction:column;gap:14px;max-width:760px;color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px}
|
|
569
|
+
.bu-head{display:flex;flex-direction:column;gap:6px}
|
|
570
|
+
.bu-title{margin:0;font-size:15px;font-weight:600;line-height:22px}
|
|
571
|
+
.bu-intro{margin:0;color:var(--dsw-alias-label-secondary);font-size:13px}
|
|
572
|
+
.bu-bar{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
|
|
573
|
+
.bu-btn{font:inherit;font-size:13px;line-height:20px;padding:4px 12px;border-radius:8px;cursor:pointer;border:.5px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-primary)}
|
|
574
|
+
.bu-btn:hover:not(:disabled){background:var(--dsw-alias-bg-layer-2)}
|
|
575
|
+
.bu-btn:disabled{opacity:.45;cursor:default}
|
|
576
|
+
.bu-btn[data-primary=true]{background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary);color:#fff}
|
|
577
|
+
/* The generic hover rule below outranks this one on specificity (class + two
|
|
578
|
+
pseudo-classes beats class + attribute), so the primary button's background
|
|
579
|
+
was replaced on hover and its white label became invisible on a light fill.
|
|
580
|
+
Repeat the primary rule with the hover states attached to win it back. */
|
|
581
|
+
.bu-btn[data-primary=true]:hover:not(:disabled){background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary);color:#fff;filter:brightness(1.12)}
|
|
582
|
+
.bu-btn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,var(--dsw-alias-brand-primary));outline-offset:2px}
|
|
583
|
+
.bu-btn-quiet{border-color:transparent;color:var(--dsw-alias-label-secondary)}
|
|
584
|
+
/* Same specificity trap as the primary button: the generic hover background
|
|
585
|
+
would win over this rule, so the quiet hover repeats the full selector. */
|
|
586
|
+
.bu-btn-quiet:hover:not(:disabled){background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary)}
|
|
587
|
+
.bu-divider{width:1px;align-self:stretch;margin:2px 2px;background:var(--dsw-alias-border-l1);flex:none}
|
|
588
|
+
.bu-spacer{flex:1}
|
|
589
|
+
.bu-note{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;margin:0}
|
|
590
|
+
.bu-allCurrent{color:var(--dsw-alias-state-success-primary);font-size:13px;font-weight:500}
|
|
591
|
+
.bu-summary{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;margin:0;font-variant-numeric:tabular-nums}
|
|
592
|
+
.bu-count{color:var(--dsw-alias-label-secondary);font-size:12px;white-space:nowrap}
|
|
593
|
+
.bu-list{list-style:none;margin:0;padding:0;border:.5px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1);overflow:hidden}
|
|
594
|
+
.bu-row{display:grid;grid-template-columns:auto auto auto minmax(0,1fr) auto;align-items:center;gap:10px;padding:8px 12px;line-height:18px;position:relative}
|
|
595
|
+
/* One hairline between rows instead of a box around each: a stack of bordered
|
|
596
|
+
cards read as a ladder of lines. The rule belongs to the row below it, so the
|
|
597
|
+
card's own top edge is never doubled, and it is inset to clear the rounded
|
|
598
|
+
corners. */
|
|
599
|
+
.bu-row + .bu-row{box-shadow:inset 0 .5px 0 var(--dsw-alias-border-l1)}
|
|
600
|
+
.bu-row[data-off=true]{opacity:.62}
|
|
601
|
+
.bu-row[data-clickable=true]{cursor:pointer}
|
|
602
|
+
.bu-row[data-clickable=true]:hover{background:var(--dsw-alias-bg-layer-2)}
|
|
603
|
+
.bu-row[data-clickable=true] .bu-check{cursor:pointer}
|
|
604
|
+
.bu-check{width:14px;height:14px;margin:0;cursor:pointer;accent-color:var(--dsw-alias-brand-primary)}
|
|
605
|
+
.bu-check:disabled{cursor:default}
|
|
606
|
+
.bu-enabled{display:inline-flex;align-items:center;justify-content:center;width:14px;height:14px;flex:none;border-radius:50%;cursor:default;background:var(--dsw-alias-state-idle-primary);box-shadow:inset 0 0 0 1px color-mix(in srgb, currentColor 12%, transparent)}
|
|
607
|
+
.bu-enabled[data-on=true]{background:var(--dsw-alias-state-success-primary)}
|
|
608
|
+
.bu-art-frame{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;flex:none;color:var(--dsw-alias-label-secondary)}
|
|
609
|
+
.bu-art{width:28px;height:28px;border-radius:6px;object-fit:contain;display:block}
|
|
610
|
+
.bu-art-fallback{display:flex;align-items:center;justify-content:center;border-radius:6px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);font-weight:600;line-height:1;user-select:none}
|
|
611
|
+
.bu-main{display:flex;flex-direction:column;gap:0;min-width:0}
|
|
612
|
+
.bu-name{font-weight:500;overflow-wrap:anywhere}
|
|
613
|
+
.bu-sub{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:16px;overflow-wrap:anywhere}
|
|
614
|
+
.bu-right{display:flex;flex-direction:row;align-items:baseline;gap:8px;white-space:nowrap}
|
|
615
|
+
.bu-ver{font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
616
|
+
.bu-arrow{color:var(--dsw-alias-label-secondary);margin:0 3px}
|
|
617
|
+
.bu-next{color:var(--dsw-alias-state-success-primary);font-weight:500}
|
|
618
|
+
.bu-bad{color:var(--dsw-alias-state-error-primary)}
|
|
619
|
+
.bu-warn{color:var(--dsw-alias-state-warn-primary)}
|
|
620
|
+
.bu-idle{color:var(--dsw-alias-label-secondary);font-size:12px}
|
|
621
|
+
.bu-run{display:flex;flex-direction:column;gap:8px;padding:12px;border:.5px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-layer-1)}
|
|
622
|
+
.bu-run[data-idle=true]{border-style:dashed;border-color:var(--dsw-alias-border-l1);background:transparent}
|
|
623
|
+
.bu-run[data-idle=true] .bu-run-title{color:var(--dsw-alias-label-secondary);font-weight:500}
|
|
624
|
+
.bu-run-title{margin:0;font-weight:600;font-size:13px}
|
|
625
|
+
.bu-track{height:4px;border-radius:2px;background:var(--dsw-alias-bg-layer-2);overflow:hidden}
|
|
626
|
+
.bu-fill{height:100%;background:var(--dsw-alias-brand-primary);transition:width .2s ease}
|
|
627
|
+
.bu-results{list-style:none;margin:0;padding:0 4px 0 0;display:flex;flex-direction:column;gap:3px;max-height:104px;overflow-y:auto;overscroll-behavior:contain}
|
|
628
|
+
.bu-results::-webkit-scrollbar{width:8px}
|
|
629
|
+
.bu-results::-webkit-scrollbar-thumb{background:var(--dsw-alias-border-l2);border-radius:4px}
|
|
630
|
+
.bu-results::-webkit-scrollbar-track{background:transparent}
|
|
631
|
+
.bu-result{display:flex;gap:8px;align-items:baseline;font-size:12px;line-height:18px;flex-wrap:wrap}
|
|
632
|
+
.bu-result b{font-weight:500;overflow-wrap:anywhere}
|
|
633
|
+
.bu-empty{margin:0;color:var(--dsw-alias-label-secondary)}
|
|
634
|
+
.bu-fail{display:flex;align-items:center;gap:10px;color:var(--dsw-alias-state-error-primary)}
|
|
635
|
+
@media (max-width:560px){.bu-row{grid-template-columns:auto auto auto minmax(0,1fr)}.bu-right{grid-column:3 / -1;justify-content:flex-start;flex-wrap:wrap}}
|
|
636
|
+
`;
|
|
637
|
+
|
|
638
|
+
// ---------------------------------------------------------------------
|
|
639
|
+
// View
|
|
640
|
+
// ---------------------------------------------------------------------
|
|
641
|
+
|
|
642
|
+
function fill(template, values) {
|
|
643
|
+
return String(template).replace(/\{(\w+)\}/g, (match, key) => (values[key] === undefined ? match : String(values[key])));
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* The moment a check finished, as `YYYY-MM-DD HH:MM`. Written out rather than
|
|
648
|
+
* localised so the same reading appears in every interface language and does
|
|
649
|
+
* not change shape between day, month and year positions.
|
|
650
|
+
* @param stamp Milliseconds since the epoch.
|
|
651
|
+
* @returns the local date and time, to the minute.
|
|
652
|
+
*/
|
|
653
|
+
function formatCheckedAt(stamp) {
|
|
654
|
+
const at = new Date(stamp);
|
|
655
|
+
const pad = (value) => String(value).padStart(2, '0');
|
|
656
|
+
return `${at.getFullYear()}-${pad(at.getMonth() + 1)}-${pad(at.getDate())} ${pad(at.getHours())}:${pad(at.getMinutes())}`;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/** Insert the tab's stylesheet once per mounted tab, and let React keep it across renders. */
|
|
660
|
+
function StyleOnce() {
|
|
661
|
+
// An empty component whose only job is to keep the module-level CSS string
|
|
662
|
+
// in one element. Its identity never changes, so React reuses the element
|
|
663
|
+
// instead of replacing it on every parent render.
|
|
664
|
+
return h('style', null, CSS);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function RowStatus({ row, check, t }) {
|
|
668
|
+
if (!autoUpdatable(row)) return h('span', { className: 'bu-idle' }, t('notUpdatable'));
|
|
669
|
+
// A check in flight says so. Without the middle state the row's text was
|
|
670
|
+
// identical before and after a re-check, so the pass looked like nothing
|
|
671
|
+
// happened until the whole batch landed.
|
|
672
|
+
if (check !== undefined && check.phase === 'checking') {
|
|
673
|
+
return h('span', { className: 'bu-idle' }, t('rowChecking'));
|
|
674
|
+
}
|
|
675
|
+
if (check === undefined || check.phase !== 'done') return h('span', { className: 'bu-idle' }, t('noCheck'));
|
|
676
|
+
if (check.failure !== undefined) {
|
|
677
|
+
return h('span', { className: 'bu-bad' }, fill(t('checkFailed'), { reason: check.failure }));
|
|
678
|
+
}
|
|
679
|
+
const candidate = updateCandidate(check.list);
|
|
680
|
+
if (candidate !== undefined) return h('span', { className: 'bu-next' }, fill(t('updateAvailable'), { version: candidate.version }));
|
|
681
|
+
const rejected = firstRejected(check.list);
|
|
682
|
+
if (rejected !== undefined) return h('span', { className: 'bu-warn' }, fill(t('incompatibleSkipped'), { name: row.name, version: rejected.version }));
|
|
683
|
+
if (check.list !== undefined && check.list.status === 'refused') {
|
|
684
|
+
return h('span', { className: 'bu-warn' }, fill(t('checkFailed'), { reason: check.list.reason }));
|
|
685
|
+
}
|
|
686
|
+
return h('span', { className: 'bu-idle' }, t('upToDate'));
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* The short label a plugin without artwork is drawn with. Two letters keep the six iconless plugins in this
|
|
691
|
+
* profile apart: `builtin-browser` reads `BB`, `computer-use-win` `CU`, `cost-meter` `CM`, `prompt` `PR`,
|
|
692
|
+
* `see-on-phone` `SO`, `synapse` `SY`. One initial would collide (`computer`/`cost`, `see`/`synapse`).
|
|
693
|
+
* @param name The package name the row lists.
|
|
694
|
+
* @returns two upper-case characters, or `?` for a name with none.
|
|
695
|
+
*/
|
|
696
|
+
function initialOf(name) {
|
|
697
|
+
const bare = String(name).replace(/^@[^/]+\//, '').replace(/^dsh-/, '');
|
|
698
|
+
const words = bare.split(/[-_.\s]+/).filter((word) => /[a-z0-9]/i.test(word));
|
|
699
|
+
const letters = words.length > 1
|
|
700
|
+
? words.slice(0, 2).map((word) => word[0]).join('')
|
|
701
|
+
: (words[0] ?? '').slice(0, 2);
|
|
702
|
+
return letters === '' ? '?' : letters.toUpperCase();
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Artwork for a plugin whose manifest publishes no icon, or whose image fails to decode: a tinted square carrying
|
|
707
|
+
* the package's two-letter label. A letter never reads as a second checkbox beside the row's own.
|
|
708
|
+
*/
|
|
709
|
+
function ArtworkFallback({ name, size }) {
|
|
710
|
+
return h('span', {
|
|
711
|
+
className: 'bu-art-fallback',
|
|
712
|
+
style: { width: `${size}px`, height: `${size}px`, fontSize: `${Math.round(size * 0.42)}px` },
|
|
713
|
+
'aria-hidden': true,
|
|
714
|
+
}, initialOf(name));
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/** A plugin's own icon, read from the Host as a data URL; a failed decode keeps the initial in place. */
|
|
718
|
+
function PluginArtwork({ src, name, size }) {
|
|
719
|
+
const [failed, setFailed] = React.useState();
|
|
720
|
+
return src === undefined || src === failed
|
|
721
|
+
? h(ArtworkFallback, { name, size })
|
|
722
|
+
: h('img', {
|
|
723
|
+
className: 'bu-art',
|
|
724
|
+
src,
|
|
725
|
+
width: size,
|
|
726
|
+
height: size,
|
|
727
|
+
alt: '',
|
|
728
|
+
loading: 'lazy',
|
|
729
|
+
decoding: 'async',
|
|
730
|
+
onError: () => { setFailed(src); },
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* One row. Wrapped in `React.memo` below so a change to one plugin's check
|
|
736
|
+
* does not re-render the other sixteen: a check publishes twice per package,
|
|
737
|
+
* and without this every publish redrew the whole list.
|
|
738
|
+
*/
|
|
739
|
+
function PluginRowView({ row, check, checked, busy, t, titleOf, onToggle }) {
|
|
740
|
+
const candidate = check === undefined || check.phase !== 'done' ? undefined : updateCandidate(check.list);
|
|
741
|
+
const disabled = busy || !autoUpdatable(row);
|
|
742
|
+
// The row's free area toggles the tick, so clicking the artwork, the name
|
|
743
|
+
// or the version does what clicking the box does. A click that starts on
|
|
744
|
+
// the box itself is left alone: the box's own onChange already handled it,
|
|
745
|
+
// and reacting here too would toggle it straight back.
|
|
746
|
+
const onRowClick = (event) => {
|
|
747
|
+
if (rowClickToggles(event.target, disabled)) onToggle(row.name, !checked);
|
|
748
|
+
};
|
|
749
|
+
return h('li', {
|
|
750
|
+
className: 'bu-row',
|
|
751
|
+
'data-off': String(!autoUpdatable(row)),
|
|
752
|
+
'data-clickable': String(!disabled),
|
|
753
|
+
onClick: onRowClick,
|
|
754
|
+
},
|
|
755
|
+
h('input', {
|
|
756
|
+
className: 'bu-check',
|
|
757
|
+
type: 'checkbox',
|
|
758
|
+
checked,
|
|
759
|
+
disabled,
|
|
760
|
+
'aria-label': titleOf(row),
|
|
761
|
+
onChange: (event) => { onToggle(row.name, event.target.checked); },
|
|
762
|
+
}),
|
|
763
|
+
// Whether the profile switches this bundle on, between the tick and the artwork. It is a state, not a
|
|
764
|
+
// control: turning a plugin on or off belongs on the Plugins page, which owns that decision. Drawn as a
|
|
765
|
+
// dot alone — the word beside it repeated sixteen times said nothing the colour did not.
|
|
766
|
+
h('span', {
|
|
767
|
+
className: 'bu-enabled',
|
|
768
|
+
'data-on': String(row.enabled),
|
|
769
|
+
title: row.enabled ? t('enabled') : t('disabledHint'),
|
|
770
|
+
role: 'img',
|
|
771
|
+
'aria-label': row.enabled ? t('enabled') : t('disabledShort'),
|
|
772
|
+
}),
|
|
773
|
+
h('span', { className: 'bu-art-frame', 'aria-hidden': true },
|
|
774
|
+
h(PluginArtwork, { src: row.icon, name: row.name, size: 28 }),
|
|
775
|
+
),
|
|
776
|
+
h('div', { className: 'bu-main' },
|
|
777
|
+
h('span', { className: 'bu-name' }, titleOf(row)),
|
|
778
|
+
h('span', { className: 'bu-sub' }, autoUpdatable(row) ? row.name : `${row.name} · ${t('notUpdatableHint')}`),
|
|
779
|
+
),
|
|
780
|
+
h('div', { className: 'bu-right' },
|
|
781
|
+
h('span', { className: 'bu-ver' },
|
|
782
|
+
h('span', null, row.version === undefined ? '—' : row.version),
|
|
783
|
+
candidate === undefined ? null : h('span', { className: 'bu-arrow' }, '→'),
|
|
784
|
+
candidate === undefined ? null : h('span', { className: 'bu-next' }, candidate.version),
|
|
785
|
+
),
|
|
786
|
+
h(RowStatus, { row, check, t }),
|
|
787
|
+
),
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Compare the props that actually decide a row's output. `t`, `titleOf` and
|
|
793
|
+
* `onToggle` are stable references from the controller, so they are compared
|
|
794
|
+
* as-is; `row`, `check`, `checked` and `busy` are what change.
|
|
795
|
+
*/
|
|
796
|
+
function rowPropsEqual(a, b) {
|
|
797
|
+
return a.row === b.row
|
|
798
|
+
&& a.check === b.check
|
|
799
|
+
&& a.checked === b.checked
|
|
800
|
+
&& a.busy === b.busy
|
|
801
|
+
&& a.t === b.t
|
|
802
|
+
&& a.titleOf === b.titleOf
|
|
803
|
+
&& a.onToggle === b.onToggle;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// `memo` is used when the page's React provides it, and skipped when it does
|
|
807
|
+
// not: the row is correct either way, and a bare `React.memo(...)` call would
|
|
808
|
+
// blank the whole tab on a runtime without it. The tab's real saving comes
|
|
809
|
+
// from publishing once per batch rather than twice per package.
|
|
810
|
+
const PluginRow = typeof React.memo === 'function'
|
|
811
|
+
? React.memo(PluginRowView, rowPropsEqual)
|
|
812
|
+
: PluginRowView;
|
|
813
|
+
|
|
814
|
+
function RunPanel({ run, t, onStop }) {
|
|
815
|
+
// The panel keeps its seat before the list has ever run, showing the idle
|
|
816
|
+
// line instead of disappearing. Hiding it made the list jump down the first
|
|
817
|
+
// time a run started.
|
|
818
|
+
const idle = run === null;
|
|
819
|
+
const total = idle || run.total === undefined ? 0 : run.total;
|
|
820
|
+
const done = idle || run.done === undefined ? 0 : run.done;
|
|
821
|
+
const results = idle || run.results === undefined ? [] : run.results;
|
|
822
|
+
const ok = results.filter((result) => result.ok === true && result.skipped !== true).length;
|
|
823
|
+
const failed = results.filter((result) => result.ok === false).length;
|
|
824
|
+
const skipped = results.filter((result) => result.skipped === true).length;
|
|
825
|
+
const percent = total === 0 ? 0 : Math.round((done / total) * 100);
|
|
826
|
+
const active = !idle && (run.phase === 'running' || run.phase === 'preparing');
|
|
827
|
+
// A run where nothing needed installing must say so in its summary. The
|
|
828
|
+
// bare totals ("finished 17 / 17, 0 updated, 0 failed") read like the run
|
|
829
|
+
// did nothing at all, which is how "everything is already current" looked
|
|
830
|
+
// like a silent no-op.
|
|
831
|
+
const nothingToDo = !idle && !active && run.nothing !== true && run.phase !== 'stopped'
|
|
832
|
+
&& failed === 0 && ok === 0 && skipped > 0;
|
|
833
|
+
// The list holds only what actually happened: an install that succeeded or
|
|
834
|
+
// failed. A package already on its newest release produced no change, and a
|
|
835
|
+
// run of eighteen plugins where one updated listed seventeen lines of noise
|
|
836
|
+
// around the single line worth reading. Newest first, so the current install
|
|
837
|
+
// stays at the top of the capped box.
|
|
838
|
+
const shownResults = [...results]
|
|
839
|
+
.filter((result) => result.skipped !== true)
|
|
840
|
+
.reverse();
|
|
841
|
+
return h('section', { className: 'bu-run', 'data-idle': String(idle), 'aria-live': 'polite' },
|
|
842
|
+
h('div', { className: 'bu-bar' },
|
|
843
|
+
h('h3', { className: 'bu-run-title' }, t('runTitle')),
|
|
844
|
+
active ? h('span', { className: 'bu-spacer' }) : null,
|
|
845
|
+
active ? h('button', { className: 'bu-btn', type: 'button', onClick: onStop }, t('stop')) : null,
|
|
846
|
+
),
|
|
847
|
+
total > 0 && !idle ? h('div', { className: 'bu-track' }, h('div', { className: 'bu-fill', style: { width: `${percent}%` } })) : null,
|
|
848
|
+
h('p', { className: nothingToDo ? 'bu-note bu-allCurrent' : 'bu-note' },
|
|
849
|
+
idle
|
|
850
|
+
? t('runIdle')
|
|
851
|
+
: run.phase === 'preparing'
|
|
852
|
+
? t('runPreparing')
|
|
853
|
+
: run.phase === 'running' && run.current !== null
|
|
854
|
+
? fill(t('runUpdating'), { name: run.current.name, from: run.current.from, to: run.current.to })
|
|
855
|
+
: run.nothing === true
|
|
856
|
+
? t('runNothing')
|
|
857
|
+
: run.phase === 'stopped'
|
|
858
|
+
? t('runCancelled')
|
|
859
|
+
: nothingToDo
|
|
860
|
+
? fill(t('runAllCurrent'), { count: skipped })
|
|
861
|
+
: fill(t('runSummary'), { done, total, ok, failed }),
|
|
862
|
+
),
|
|
863
|
+
// Only the rows that changed something are listed. A plugin already on
|
|
864
|
+
// its newest release wrote nothing, and printing "no update available"
|
|
865
|
+
// for each of them buried the one or two lines that matter.
|
|
866
|
+
shownResults.length === 0 ? null : h('ul', { className: 'bu-results' }, shownResults.map((result, index) => h('li', { className: 'bu-result', key: `${result.name}-${index}` },
|
|
867
|
+
h('b', null, result.name),
|
|
868
|
+
result.ok === true
|
|
869
|
+
? h('span', { className: 'bu-next' }, result.restart === true ? t('runRestart') : t('runSuccess'))
|
|
870
|
+
: h('span', { className: 'bu-bad' }, `${t('runFailed')} · ${result.message === undefined ? '' : result.message}`),
|
|
871
|
+
result.ok === true ? h('span', { className: 'bu-idle' }, `${result.from} → ${result.to}`) : null,
|
|
872
|
+
))),
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
function BulkUpdateTab(props) {
|
|
877
|
+
const { store, actions, t } = props;
|
|
878
|
+
const state = React.useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
879
|
+
const [checking, setChecking] = React.useState(false);
|
|
880
|
+
const [starting, setStarting] = React.useState(false);
|
|
881
|
+
const mounted = React.useRef(true);
|
|
882
|
+
|
|
883
|
+
React.useEffect(() => {
|
|
884
|
+
mounted.current = true;
|
|
885
|
+
return () => { mounted.current = false; };
|
|
886
|
+
}, []);
|
|
887
|
+
|
|
888
|
+
React.useEffect(() => { void actions.load(); }, [actions]);
|
|
889
|
+
|
|
890
|
+
const running = state.run !== null && (state.run.phase === 'running' || state.run.phase === 'preparing');
|
|
891
|
+
const busy = checking || starting || running;
|
|
892
|
+
const updatable = state.rows.filter(autoUpdatable);
|
|
893
|
+
const selectedUpdatable = updatable.filter((row) => state.selected.includes(row.name));
|
|
894
|
+
/** How many ticked plugins actually have a newer release: asked of the checks, never of the ticks. */
|
|
895
|
+
const selectedWithUpdate = selectedUpdatable.filter((row) => {
|
|
896
|
+
const check = state.checks[row.name];
|
|
897
|
+
return check !== undefined && check.phase === 'done' && updateCandidate(check.list) !== undefined;
|
|
898
|
+
}).length;
|
|
899
|
+
|
|
900
|
+
const onCheck = async () => {
|
|
901
|
+
// Every listable plugin is checked, ticked or not: the tick decides what
|
|
902
|
+
// gets installed, not what gets looked at. The cost of that is bounded by
|
|
903
|
+
// checking one package at a time, not by narrowing the list.
|
|
904
|
+
const targets = updatable.map((row) => row.name);
|
|
905
|
+
if (targets.length === 0) return;
|
|
906
|
+
setChecking(true);
|
|
907
|
+
try {
|
|
908
|
+
await actions.checkBatch(targets);
|
|
909
|
+
} finally {
|
|
910
|
+
if (mounted.current) setChecking(false);
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
|
|
914
|
+
const onRun = async () => {
|
|
915
|
+
setStarting(true);
|
|
916
|
+
try {
|
|
917
|
+
await actions.runSelected();
|
|
918
|
+
} finally {
|
|
919
|
+
if (mounted.current) setStarting(false);
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
const checkedAt = Object.values(state.checks)
|
|
924
|
+
.map((check) => check.checkedAt)
|
|
925
|
+
.filter((value) => typeof value === 'number')
|
|
926
|
+
.sort((a, b) => b - a)[0];
|
|
927
|
+
|
|
928
|
+
return h('div', { className: 'bu-root' },
|
|
929
|
+
// The stylesheet is mounted once for the package, not on every render:
|
|
930
|
+
// re-creating this element whenever the controller published a change
|
|
931
|
+
// made the tab rewrite its whole style sheet dozens of times per check.
|
|
932
|
+
h(StyleOnce, null),
|
|
933
|
+
h('div', { className: 'bu-head' },
|
|
934
|
+
h('h2', { className: 'bu-title' }, t('heading')),
|
|
935
|
+
h('p', { className: 'bu-intro' }, t('intro')),
|
|
936
|
+
h('p', { className: 'bu-summary' }, fill(t('summary'), {
|
|
937
|
+
total: state.rows.length,
|
|
938
|
+
enabled: state.rows.filter((row) => row.enabled).length,
|
|
939
|
+
// The ticks themselves: a row that cannot be ticked is not counted, and nothing here asks whether it
|
|
940
|
+
// has an update. Whether a ticked plugin actually updates is the fourth field's own count.
|
|
941
|
+
selected: state.selected.length,
|
|
942
|
+
updates: checking
|
|
943
|
+
? t('updatesChecking')
|
|
944
|
+
: checkedAt === undefined
|
|
945
|
+
? t('updatesNone')
|
|
946
|
+
: fill(t('updatesFound'), { count: selectedWithUpdate }),
|
|
947
|
+
})),
|
|
948
|
+
),
|
|
949
|
+
// One toolbar row: the actions on the left, the last check's time pushed
|
|
950
|
+
// to the right edge. Two rows spent a full line on three secondary
|
|
951
|
+
// buttons and made the list start lower than it needed to.
|
|
952
|
+
h('div', { className: 'bu-bar' },
|
|
953
|
+
h('button', { className: 'bu-btn', type: 'button', disabled: busy, onClick: () => { void actions.load(); } }, t('refresh')),
|
|
954
|
+
h('button', { className: 'bu-btn', type: 'button', disabled: busy || updatable.length === 0, onClick: () => { void onCheck(); } },
|
|
955
|
+
checking ? t('checking') : t('check')),
|
|
956
|
+
h('button', {
|
|
957
|
+
className: 'bu-btn',
|
|
958
|
+
type: 'button',
|
|
959
|
+
'data-primary': 'true',
|
|
960
|
+
disabled: busy || selectedUpdatable.length === 0,
|
|
961
|
+
onClick: () => { void onRun(); },
|
|
962
|
+
}, starting && !running ? t('checking') : t('update')),
|
|
963
|
+
h('span', { className: 'bu-divider', 'aria-hidden': true }),
|
|
964
|
+
h('button', { className: 'bu-btn bu-btn-quiet', type: 'button', disabled: busy, onClick: () => { actions.selectAll(true); } }, t('selectAll')),
|
|
965
|
+
h('button', { className: 'bu-btn bu-btn-quiet', type: 'button', disabled: busy, onClick: () => { actions.selectAll(false); } }, t('selectNone')),
|
|
966
|
+
checkedAt === undefined ? null : h('span', { className: 'bu-spacer' }),
|
|
967
|
+
checkedAt === undefined ? null : h('span', { className: 'bu-count' }, fill(t('checkedAt'), { time: formatCheckedAt(checkedAt) })),
|
|
968
|
+
),
|
|
969
|
+
state.status === 'loading' ? h('p', { className: 'bu-empty' }, t('loading')) : null,
|
|
970
|
+
state.status === 'error' ? h('div', { className: 'bu-fail' },
|
|
971
|
+
h('span', null, fill(t('loadFailed'), { reason: state.error === null ? '' : state.error })),
|
|
972
|
+
h('button', { className: 'bu-btn', type: 'button', onClick: () => { void actions.load(); } }, t('refresh')),
|
|
973
|
+
) : null,
|
|
974
|
+
// The progress panel sits between the buttons and the list, and keeps its place whether or not a run is
|
|
975
|
+
// under way. Below the list it was off-screen for a long profile, and appearing there pushed nothing; above
|
|
976
|
+
// the list but shown only after a click it would shove every row down mid-click. A fixed seat costs a little
|
|
977
|
+
// height and never moves the rows.
|
|
978
|
+
h(RunPanel, { run: state.run, t, onStop: actions.requestStop }),
|
|
979
|
+
state.stopped === true ? h('p', { className: 'bu-note' }, t('stopped')) : null,
|
|
980
|
+
state.status === 'ready' && state.rows.length === 0 ? h('p', { className: 'bu-empty' }, t('empty')) : null,
|
|
981
|
+
state.rows.length === 0 ? null : h('ul', { className: 'bu-list' }, state.rows.map((row) => h(PluginRow, {
|
|
982
|
+
key: row.name,
|
|
983
|
+
row,
|
|
984
|
+
check: state.checks[row.name],
|
|
985
|
+
checked: state.selected.includes(row.name),
|
|
986
|
+
busy,
|
|
987
|
+
t,
|
|
988
|
+
titleOf: actions.titleOf,
|
|
989
|
+
onToggle: actions.toggle,
|
|
990
|
+
}))),
|
|
991
|
+
state.rows.length === 0 ? null : h('p', { className: 'bu-note' }, t('prereleaseNote')),
|
|
992
|
+
// A check takes a while on a large profile. Saying so while it runs is the
|
|
993
|
+
// difference between "working" and "frozen".
|
|
994
|
+
checking ? h('p', { className: 'bu-note' }, t('slowCheckHint')) : null,
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// ---------------------------------------------------------------------
|
|
999
|
+
// Registration
|
|
1000
|
+
// ---------------------------------------------------------------------
|
|
1001
|
+
|
|
1002
|
+
return {
|
|
1003
|
+
// `remote` belongs here as well as `remote.pluginManager`: a Cordis scope only exposes a service the
|
|
1004
|
+
// context it is read through declares, so the nested scope below could not read `ctx.remote` without it.
|
|
1005
|
+
inject: ['slots', 'locale', 'remote'],
|
|
1006
|
+
apply(ctx) {
|
|
1007
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'bulk-update: dictionaries');
|
|
1008
|
+
const t = ctx.locale.bind(NS);
|
|
1009
|
+
// The plugin manager is optional: without it the tab is never registered, and nothing else notices.
|
|
1010
|
+
ctx.inject(['remote', 'remote.pluginManager'], (scope) => {
|
|
1011
|
+
const controller = createController(scope);
|
|
1012
|
+
scope.effect(() => () => { controller.dispose(); }, 'bulk-update: controller');
|
|
1013
|
+
const face = {
|
|
1014
|
+
store: controller.store,
|
|
1015
|
+
actions: {
|
|
1016
|
+
load: controller.load,
|
|
1017
|
+
checkBatch: controller.checkBatch,
|
|
1018
|
+
runSelected: controller.runSelected,
|
|
1019
|
+
toggle: controller.toggle,
|
|
1020
|
+
selectAll: controller.selectAll,
|
|
1021
|
+
requestStop: controller.requestStop,
|
|
1022
|
+
titleOf: controller.titleOf,
|
|
1023
|
+
},
|
|
1024
|
+
};
|
|
1025
|
+
scope.slots.inject('plugins.tab', () => scope.slots.register({
|
|
1026
|
+
name: 'plugins.tab',
|
|
1027
|
+
id: 'bulk-update',
|
|
1028
|
+
order: 20,
|
|
1029
|
+
label: () => t('title'),
|
|
1030
|
+
locale: NS,
|
|
1031
|
+
inject: () => face,
|
|
1032
|
+
}, BulkUpdateTab));
|
|
1033
|
+
});
|
|
1034
|
+
},
|
|
1035
|
+
/** The two-letter label a row without artwork is drawn with; exposed for the offline harness. */
|
|
1036
|
+
labelOf: initialOf,
|
|
1037
|
+
/** The row's click decision; exposed so the offline harness tests the real rule rather than a copy. */
|
|
1038
|
+
rowClickToggles: rowClickToggles,
|
|
1039
|
+
};
|
|
1040
|
+
},
|
|
1041
|
+
});
|