@moonsand/dsh-ui-optimize 0.9.31 → 0.11.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js CHANGED
@@ -88,6 +88,55 @@ window.__ModuleLoader__.load({
88
88
  'desktop.reloadNotDesktop': 'This is a browser session, so the reload button is not offered — this shell already has its own refresh entry. The switch works only inside the desktop app.',
89
89
  'legacy.title': '@moonsand/dsh-desktop-restart is still installed',
90
90
  'legacy.body': 'Both plugins draw reload/restart buttons, so the sidebar foot will show two sets. Uninstall dsh-desktop-restart under Settings → Plugins and keep only this one.',
91
+ 'updates.tab': 'Updates',
92
+ 'updates.title': 'Plugin updates',
93
+ 'updates.sub': 'One click updates every installed plugin whose newest release is at least a day old. Anything younger is skipped — a release published hours ago can still be withdrawn or patched.',
94
+ 'section.updates': 'Updates',
95
+ 'updates.switch': 'Updates tab',
96
+ 'updates.switchHint': 'Adds an Updates tab (one-click update plus a count badge) to the plugin page. Turning it off stops every update check this plugin makes.',
97
+ 'updates.fallbackSwitch': 'Fall back to the previous release',
98
+ 'updates.fallbackSwitchHint': 'When the newest release is less than a day old, install the newest one that already is, instead of waiting.',
99
+ 'updates.fallbackTag': 'previous release',
100
+ 'updates.off': 'Updates are turned off',
101
+ 'updates.offHint': 'Turn on “Updates tab” under Settings → UI Optimize to bring it back.',
102
+ 'updates.check': 'Check again',
103
+ 'updates.checking': 'Checking…',
104
+ 'updates.loadingDetail': 'Reading the installed plugins and their publish dates…',
105
+ 'updates.notesLoading': 'Loading the release notes…',
106
+ 'updates.notesEmpty': 'No release notes for this version.',
107
+ 'updates.notesRate': 'GitHub is rate-limiting anonymous requests. Try again in a few minutes.',
108
+ 'updates.notesFailed': 'Could not load the release notes.',
109
+ 'updates.notesToggle': 'Show or hide the release notes',
110
+ 'updates.notesNoZh': 'No Chinese release notes for these versions.',
111
+ 'updates.notesNoZhVersion': 'No Chinese notes for this version.',
112
+ 'updates.notesSpan': 'Changes since {from}',
113
+ 'updates.updateAll': 'Update all',
114
+ 'updates.needRestartHint': '{n} of them only take effect after DSH restarts — the new code is on disk, the running process still has the old one. Restarting also reloads the page, so one restart covers both. Restart when convenient.',
115
+ 'updates.needRefreshHint': 'Done. Reload the page to load the new client code.',
116
+ 'updates.updating': 'Updating…',
117
+ 'updates.none': 'Nothing to update.',
118
+ 'updates.upToDate': '{n} already up to date',
119
+ 'updates.fallbackWhy': 'The latest release is under 24 hours old, so this installs the newest release that is already old enough.',
120
+ 'updates.latestSoon': '{hours}h left',
121
+ 'updates.idle': 'Not checked yet.',
122
+ 'updates.unsupported': 'This host exposes no plugin manager, so updates cannot be checked here. Installed plugins still work.',
123
+ 'updates.registryDown': 'The npm registry did not answer, so the release dates are unknown. Public plugins stay listed as unchecked.',
124
+ 'updates.pmTimeout': 'The host plugin manager is still busy after {ms}s. Try again in a moment.',
125
+ 'updates.pmWaiting': 'Waiting for the host plugin manager…',
126
+ 'updates.pmStalled': 'The host plugin manager did not answer. Try again in a moment.',
127
+ 'updates.loadFailed': 'The check failed',
128
+ 'updates.waiting': 'Published under a day ago — skipped until it is 24 hours old',
129
+ 'updates.unknownAge': 'Publish time could not be read — skipped, since the 24-hour rule cannot be confirmed',
130
+ 'updates.readingAge': 'Reading the publish time…',
131
+ 'updates.section.ready': 'Ready to update',
132
+ 'updates.section.waiting': 'Not yet',
133
+ 'updates.section.waitingHint': 'Published less than 24 hours ago.',
134
+ 'updates.queued': 'Queued',
135
+ 'updates.running': 'Updating',
136
+ 'updates.succeeded': 'Updated',
137
+ 'updates.failed': 'Failed',
138
+ 'updates.checked': 'installed plugins checked',
139
+ 'updates.reloadHint': 'Reload the page after a plugin update — the new client half only loads on a fresh page.',
91
140
  storageNote: 'Storage unavailable — the choice lasts until this page reloads.',
92
141
  },
93
142
  zh: {
@@ -146,6 +195,55 @@ window.__ModuleLoader__.load({
146
195
  'desktop.reloadNotDesktop': '当前是网页端,刷新按钮不提供——这个外壳已经自带刷新入口。此开关仅在桌面应用里可开。',
147
196
  'legacy.title': '检测到 @moonsand/dsh-desktop-restart 仍在安装',
148
197
  'legacy.body': '两个插件都会提供刷新/重启按钮,侧栏底部会出现两套。请到「设置 → 插件」卸载 dsh-desktop-restart,只保留本插件。',
198
+ 'updates.tab': '更新',
199
+ 'updates.title': '插件更新',
200
+ 'updates.sub': '一键更新所有「最新版发布满 24 小时」的已装插件;更年轻的版本先跳过——刚发几小时的版本还可能被撤回或补丁。',
201
+ 'section.updates': '更新',
202
+ 'updates.switch': '「更新」页签',
203
+ 'updates.switchHint': '在插件页加一个「更新」页签(一键更新 + 数量徽章)。关掉后本插件不再做任何更新检查。',
204
+ 'updates.fallbackSwitch': '退回次新版',
205
+ 'updates.fallbackSwitchHint': '最新版发布不足 24 小时时,改装「已经满一天的最新版本」,而不是干等。',
206
+ 'updates.fallbackTag': '次新版',
207
+ 'updates.off': '更新功能已关闭',
208
+ 'updates.offHint': '到「设置 → 界面优化」打开「更新页签」即可恢复。',
209
+ 'updates.check': '重新检查',
210
+ 'updates.checking': '检查中…',
211
+ 'updates.loadingDetail': '正在读取已装插件和它们的发布时间…',
212
+ 'updates.notesLoading': '正在读取更新说明…',
213
+ 'updates.notesEmpty': '这个版本没有更新说明。',
214
+ 'updates.notesRate': 'GitHub 的匿名请求被限流了,过几分钟再试。',
215
+ 'updates.notesFailed': '更新说明读取失败。',
216
+ 'updates.notesToggle': '展开或收起更新说明',
217
+ 'updates.notesNoZh': '这些版本没有中文更新说明。',
218
+ 'updates.notesNoZhVersion': '该版本没有中文说明。',
219
+ 'updates.notesSpan': '自 {from} 以来的改动',
220
+ 'updates.updateAll': '一键更新',
221
+ 'updates.needRestartHint': '{n} 个插件要重启 DSH 才真正生效——新代码已经在磁盘上,跑着的进程还是旧的。重启会连页面一起刷新,所以重启一次就都齐了,不急着马上重。',
222
+ 'updates.needRefreshHint': '都更新完了,刷新页面即可加载新的客户端代码。',
223
+ 'updates.updating': '更新中…',
224
+ 'updates.none': '没有可更新的插件。',
225
+ 'updates.upToDate': '其余 {n} 个已是最新版',
226
+ 'updates.fallbackWhy': '最新版发布不足 24 小时,这一版装的是已满 24 小时的最新版本。',
227
+ 'updates.latestSoon': '剩余 {hours} 小时',
228
+ 'updates.idle': '还没检查。',
229
+ 'updates.unsupported': '这台宿主没有可用的插件管理服务,所以这里查不了更新(已装插件不受影响)。',
230
+ 'updates.registryDown': 'npm registry 没有回应,读不到发布时间。公开插件暂时按「未检查」处理。',
231
+ 'updates.pmTimeout': '宿主的插件管理服务 {ms} 秒还没应答,过一会儿再试。',
232
+ 'updates.pmWaiting': '正在等宿主插件管理服务应答…',
233
+ 'updates.pmStalled': '宿主的插件管理服务没有应答,过一会儿再试。',
234
+ 'updates.loadFailed': '检查失败',
235
+ 'updates.waiting': '发布不足 24 小时 —— 等满一天再更新',
236
+ 'updates.unknownAge': '读不到发布时间 —— 无法确认是否满 24 小时,先跳过',
237
+ 'updates.readingAge': '正在读取发布时间…',
238
+ 'updates.section.ready': '可更新',
239
+ 'updates.section.waiting': '暂不可更新',
240
+ 'updates.section.waitingHint': '发布不足 24 小时',
241
+ 'updates.queued': '排队中',
242
+ 'updates.running': '更新中',
243
+ 'updates.succeeded': '已更新',
244
+ 'updates.failed': '失败',
245
+ 'updates.checked': '个已装插件已检查',
246
+ 'updates.reloadHint': '插件更新完成后刷新页面,新的客户端代码才会加载。',
149
247
  storageNote: '浏览器存储不可用——选择的主题只在本次页面加载内有效。',
150
248
  },
151
249
  }
@@ -403,7 +501,7 @@ window.__ModuleLoader__.load({
403
501
  * ------------------------------------------------------------------ */
404
502
 
405
503
  function defaultState() {
406
- return { version: 4, theme: null, reload: true, restart: true, sidebar: false }
504
+ return { version: 5, theme: null, reload: true, restart: true, sidebar: false, updates: true, updatesFallback: false }
407
505
  }
408
506
 
409
507
  function normalize(stored) {
@@ -415,6 +513,8 @@ window.__ModuleLoader__.load({
415
513
  if (typeof stored.reload === 'boolean') out.reload = stored.reload
416
514
  if (typeof stored.restart === 'boolean') out.restart = stored.restart
417
515
  if (typeof stored.sidebar === 'boolean') out.sidebar = stored.sidebar
516
+ if (typeof stored.updates === 'boolean') out.updates = stored.updates
517
+ if (typeof stored.updatesFallback === 'boolean') out.updatesFallback = stored.updatesFallback
418
518
  return out
419
519
  }
420
520
 
@@ -928,6 +1028,49 @@ body:not([data-ds-dark-theme]) .dsuik-mc > .dsuik-mc-b{display:none;}
928
1028
  }),
929
1029
  ),
930
1030
  ),
1031
+ h(
1032
+ 'div',
1033
+ { className: 'dsuik-section' },
1034
+ h('p', { className: 'dsuik-sectiontitle' }, translate('section.updates')),
1035
+ h(
1036
+ 'div',
1037
+ { className: 'dsuik-row' },
1038
+ h(
1039
+ 'div',
1040
+ { className: 'dsuik-rowtext' },
1041
+ h('span', { className: 'dsuik-rowname' }, translate('updates.switch')),
1042
+ h('span', { className: 'dsuik-rowhint' }, translate('updates.switchHint')),
1043
+ ),
1044
+ h(Switch, {
1045
+ checked: state.updates !== false,
1046
+ label: translate('updates.switch'),
1047
+ onChange: function (next) {
1048
+ store.setFlag('updates', next)
1049
+ if (!next) updateBadge.set(0)
1050
+ else refreshUpdateBadge()
1051
+ },
1052
+ }),
1053
+ ),
1054
+ h(
1055
+ 'div',
1056
+ { className: 'dsuik-row' },
1057
+ h(
1058
+ 'div',
1059
+ { className: 'dsuik-rowtext' },
1060
+ h('span', { className: 'dsuik-rowname' }, translate('updates.fallbackSwitch')),
1061
+ h('span', { className: 'dsuik-rowhint' }, translate('updates.fallbackSwitchHint')),
1062
+ ),
1063
+ h(Switch, {
1064
+ checked: state.updatesFallback === true,
1065
+ disabled: state.updates === false,
1066
+ label: translate('updates.fallbackSwitch'),
1067
+ onChange: function (next) {
1068
+ store.setFlag('updatesFallback', next)
1069
+ if (state.updates !== false) refreshUpdateBadge()
1070
+ },
1071
+ }),
1072
+ ),
1073
+ ),
931
1074
  surface.controller && !surface.controller.active()
932
1075
  ? h(
933
1076
  'p',
@@ -1736,8 +1879,13 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
1736
1879
  function openMore() {
1737
1880
  const button = moreRef.current
1738
1881
  if (!button) return
1739
- const x = pos ? pos.left : 12
1740
- const y = pos ? pos.top : 120
1882
+ /* Measure the row right now. The cached `pos` is computed when the card
1883
+ * opens and goes stale as soon as the sidebar re-lays out (collapse,
1884
+ * resize, a panel switching tabs) — which parked the shell menu in the
1885
+ * corner, outside the panel, until a reload. */
1886
+ const rect = button.getBoundingClientRect()
1887
+ const x = rect.width > 0 ? rect.left : (pos ? pos.left : 12)
1888
+ const y = rect.width > 0 ? rect.bottom : (pos ? pos.top : 120)
1741
1889
  try {
1742
1890
  const style = document.documentElement.style
1743
1891
  style.setProperty('--muik-more-x', x + 'px')
@@ -1865,7 +2013,9 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
1865
2013
  * ------------------------------------------------------------------ */
1866
2014
 
1867
2015
  return {
1868
- inject: ['slots'],
2016
+ /* `remote` is the Host's plugin-manager bridge; cordis refuses to hand out
2017
+ * `ctx.remote` at all unless the plugin declares it here first. */
2018
+ inject: ['slots', 'remote', 'remote.pluginManager'],
1869
2019
  apply(ctx) {
1870
2020
  try {
1871
2021
  const locale = typeof ctx.get === 'function' ? ctx.get('locale') : undefined
@@ -2002,6 +2152,1190 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
2002
2152
  })
2003
2153
  }
2004
2154
 
2155
+ /* ------------------------------------------------------------------ *
2156
+ * Updates tab
2157
+ *
2158
+ * The official plugin page exposes exactly one slot we can use without
2159
+ * touching its DOM: `plugins.tab`. Everything in it talks to the market's
2160
+ * public update API (v1) rather than driving pnpm ourselves, so the market
2161
+ * keeps ownership of installs, rollbacks and its fresh-release wait — and
2162
+ * a host without that market simply reports that it cannot check here.
2163
+ * ------------------------------------------------------------------ */
2164
+
2165
+ const FRESH_RELEASE_MS = 24 * 60 * 60 * 1000
2166
+ const UPDATE_REGISTRY = 'https://registry.npmjs.org/'
2167
+
2168
+ /* Everything this tab needs comes from two sources that exist on every
2169
+ * host: the Host's own plugin manager (what is installed) and the npm
2170
+ * registry (what exists and how old it is). No marketplace plugin is
2171
+ * involved, so it keeps working when dshmarket is absent. */
2172
+ function pluginManager() {
2173
+ const remote = ctx.remote || (typeof ctx.get === 'function' ? ctx.get('remote') : null)
2174
+ const pm = remote && remote.pluginManager
2175
+ return pm && typeof pm.listBundles === 'function' ? pm : null
2176
+ }
2177
+
2178
+ function withTimeout(promise, ms) {
2179
+ return new Promise(function (resolve) {
2180
+ const timer = setTimeout(function () {
2181
+ resolve({ timedOut: true })
2182
+ }, ms)
2183
+ Promise.resolve(promise).then(
2184
+ function (value) {
2185
+ clearTimeout(timer)
2186
+ resolve({ timedOut: false, value: value })
2187
+ },
2188
+ function (error) {
2189
+ clearTimeout(timer)
2190
+ resolve({ timedOut: false, error: error })
2191
+ }
2192
+ )
2193
+ })
2194
+ }
2195
+
2196
+ function failureMessage(error) {
2197
+ if (!error) return ''
2198
+ if (typeof error === 'string') return error
2199
+ return String(error.message || error.code || error.kind || '')
2200
+ }
2201
+
2202
+ /* The market tells us which releases are due; only the registry can tell us
2203
+ * how old the newest one is, and the age is the user's actual rule here. */
2204
+ /* "Second newest" for the fallback switch: the highest release at or below
2205
+ * `version` that is already past the 24-hour rule. */
2206
+ function previousMatureVersion(time, version) {
2207
+ if (!time || typeof time !== 'object') return null
2208
+ const names = Object.keys(time)
2209
+ let best = null
2210
+ for (let i = 0; i < names.length; i += 1) {
2211
+ const name = names[i]
2212
+ if (name === 'created' || name === 'modified' || !time[name]) continue
2213
+ if (compareVersions(name, version) >= 0) continue
2214
+ const stamp = Date.parse(time[name])
2215
+ if (!Number.isFinite(stamp)) continue
2216
+ const age = Date.now() - stamp
2217
+ if (age < FRESH_RELEASE_MS) continue
2218
+ if (best === null || compareVersions(name, best.version) > 0) best = { version: name, age: age }
2219
+ }
2220
+ return best
2221
+ }
2222
+
2223
+ const REGISTRY_TIMEOUT_MS = 8000
2224
+ const REGISTRY_CONCURRENCY = 6
2225
+
2226
+ /* Every packument is a few hundred KB. The badge scan, a tab switch and a
2227
+ * page reload all used to re-download all of them, which is why the first
2228
+ * look at this tab felt like it hung. One cache, one network round trip. */
2229
+ const REGISTRY_CACHE_MS = 10 * 60 * 1000
2230
+ const SCAN_CACHE_MS = 2 * 60 * 1000
2231
+ const registryCache = new Map()
2232
+ const compatCache = new Map()
2233
+ let scanCache = { at: 0, value: null }
2234
+
2235
+ async function readRegistry(name) {
2236
+ const cached = registryCache.get(name)
2237
+ if (cached && Date.now() - cached.at < REGISTRY_CACHE_MS) return cached.doc
2238
+ const controller = typeof AbortController === 'function' ? new AbortController() : null
2239
+ const timer = controller
2240
+ ? setTimeout(function () {
2241
+ controller.abort()
2242
+ }, REGISTRY_TIMEOUT_MS)
2243
+ : null
2244
+ try {
2245
+ const path = encodeURIComponent(name).replace(/^%40/, '@')
2246
+ const res = await fetch(UPDATE_REGISTRY + path, {
2247
+ /* The abbreviated (install-v1) document has no `time` table at all,
2248
+ * so asking for it first meant every package looked undated. */
2249
+ headers: { accept: 'application/json' },
2250
+ signal: controller ? controller.signal : undefined,
2251
+ })
2252
+ if (!res.ok) return null
2253
+ const doc = await res.json()
2254
+ const time = (doc && doc.time) || {}
2255
+ const tags = (doc && doc['dist-tags']) || {}
2256
+ const parsed = {
2257
+ latest: typeof tags.latest === 'string' ? tags.latest : '',
2258
+ time: time,
2259
+ repo: readRepo(doc),
2260
+ }
2261
+ registryCache.set(name, { at: Date.now(), doc: parsed })
2262
+ return parsed
2263
+ } catch (err) {
2264
+ return null
2265
+ } finally {
2266
+ if (timer) clearTimeout(timer)
2267
+ }
2268
+ }
2269
+
2270
+ /* Whether the running DSH version accepts this exact release. The Host
2271
+ * answers authoritatively: `listVersions` marks a version `incompatible`
2272
+ * when its `engines.dsh` (or a DSH peer) rejects the running build, and
2273
+ * it already honours `compatibility.json` exemptions. */
2274
+ async function readCompat(pm, name, version) {
2275
+ const key = name + '@' + version
2276
+ const cachedCompat = compatCache.get(key)
2277
+ if (cachedCompat !== undefined && Date.now() - cachedCompat.at < REGISTRY_CACHE_MS) return cachedCompat.doc
2278
+ try {
2279
+ const answer = await withTimeout(pm.listVersions(name), 8000)
2280
+ if (!answer || answer.timedOut || answer.error !== undefined) return null
2281
+ const result = answer.value
2282
+ if (!result || result.ok !== true) return null
2283
+ const value = result.value
2284
+ if (!value || value.status !== 'listed' || !Array.isArray(value.versions)) return null
2285
+ const hit = value.versions.find(function (entry) {
2286
+ return entry && entry.version === version
2287
+ })
2288
+ if (!hit || !hit.incompatible) return null
2289
+ const requirements = hit.incompatible.requirements || {}
2290
+ const listed = Object.keys(requirements).map(function (key) {
2291
+ return key + ' ' + requirements[key]
2292
+ })
2293
+ const verdict = {
2294
+ runtime: hit.incompatible.runtimeVersion || '',
2295
+ required: requirements['engines.dsh'] || listed.join(', '),
2296
+ }
2297
+ compatCache.set(key, { at: Date.now(), doc: verdict })
2298
+ return verdict
2299
+ } catch (err) {
2300
+ return null
2301
+ }
2302
+ }
2303
+
2304
+ /* One scan, one truth: which installed plugins have a newer release, how
2305
+ * old that release is, and what the fallback would be. The list, the
2306
+ * section split, the count and the badge all derive from this. */
2307
+ async function collectUpdates(onRow) {
2308
+ if (scanCache.value && Date.now() - scanCache.at < SCAN_CACHE_MS) return scanCache.value
2309
+ const pm = pluginManager()
2310
+ if (!pm) return { supported: false, checked: 0, rows: [] }
2311
+ let listed = null
2312
+ /* A remote proxy can throw on the call itself (dead channel), not only
2313
+ * reject the promise — that used to escape load() and leave the panel
2314
+ * in "loading" with the watchdog as the only thing still talking. */
2315
+ let answer
2316
+ try {
2317
+ answer = await withTimeout(pm.listBundles(), 8000)
2318
+ } catch (err) {
2319
+ return {
2320
+ supported: false,
2321
+ checked: 0,
2322
+ rows: [],
2323
+ stalled: 'listBundles',
2324
+ }
2325
+ }
2326
+ if (answer.timedOut) {
2327
+ return { supported: false, checked: 0, rows: [], stalled: 'listBundles' }
2328
+ }
2329
+ if (answer.error !== undefined) return { supported: false, checked: 0, rows: [] }
2330
+ listed = answer.value
2331
+ if (!listed || listed.ok !== true) return { supported: false, checked: 0, rows: [] }
2332
+ const installed = (listed.value || []).filter(function (item) {
2333
+ return item && item.installed === true
2334
+ })
2335
+ /* `updatable` is the Host's own verdict: a registry dependency saved
2336
+ * under its own name with a semver version. Links and local paths are
2337
+ * excluded for us — updating those would overwrite the checkout. */
2338
+ const candidates = installed.filter(function (item) {
2339
+ return item.updatable === true && typeof item.version === 'string' && item.version !== ''
2340
+ })
2341
+ const found = []
2342
+ const stats = { tried: 0, failed: 0 }
2343
+ let cursor = 0
2344
+ /* Six at a time: the public registry throttles a burst of thirty, and a
2345
+ * big packument on one lane must not hold the others in "loading". */
2346
+ async function worker() {
2347
+ while (cursor < candidates.length) {
2348
+ const item = candidates[cursor]
2349
+ cursor += 1
2350
+ stats.tried += 1
2351
+ const doc = await readRegistry(item.name)
2352
+ if (!doc || !doc.latest) {
2353
+ stats.failed += 1
2354
+ continue
2355
+ }
2356
+ if (compareVersions(doc.latest, item.version) <= 0) continue
2357
+ const published = doc.time[doc.latest]
2358
+ const stamp = published === undefined ? NaN : Date.parse(published)
2359
+ const age = Number.isFinite(stamp) ? Date.now() - stamp : null
2360
+ const fallback = previousMatureVersion(doc.time, doc.latest)
2361
+ /* Draw the row first: `listVersions` is a Host round trip of its own,
2362
+ * and waiting for it before painting made an already-slow list feel
2363
+ * frozen. The compatibility verdict lands on the row a moment later. */
2364
+ const row = {
2365
+ compat: null,
2366
+ name: item.name,
2367
+ installed: item.version,
2368
+ latest: doc.latest,
2369
+ age: age,
2370
+ repo: doc.repo,
2371
+ fallbackVersion: fallback ? fallback.version : '',
2372
+ fallbackAge: fallback ? fallback.age : null,
2373
+ state: 'idle',
2374
+ percent: 0,
2375
+ detail: '',
2376
+ }
2377
+ found.push(row)
2378
+ if (typeof onRow === 'function') onRow(row)
2379
+ readCompat(pm, item.name, doc.latest).then(function (compat) {
2380
+ if (!compat) return
2381
+ row.compat = compat
2382
+ if (typeof onRow === 'function') onRow(Object.assign({}, row))
2383
+ })
2384
+ }
2385
+ }
2386
+ const lanes = []
2387
+ for (let i = 0; i < Math.min(REGISTRY_CONCURRENCY, candidates.length); i += 1) lanes.push(worker())
2388
+ await Promise.all(lanes)
2389
+ found.sort(function (a, b) {
2390
+ return a.name.localeCompare(b.name)
2391
+ })
2392
+ const result = { supported: true, checked: installed.length, rows: found, stats: stats }
2393
+ /* The badge scan runs at start-up, so by the time the tab is opened the
2394
+ * answer is normally already here: keep it for a couple of minutes. */
2395
+ scanCache = { at: Date.now(), value: result }
2396
+ return result
2397
+ }
2398
+
2399
+ /* The packument's repository field is the only place that knows where the
2400
+ * changelog lives, so it travels with the age read. */
2401
+ function readRepo(doc) {
2402
+ const raw = doc && (doc.repository && (doc.repository.url || doc.repository))
2403
+ if (typeof raw !== 'string') return ''
2404
+ const hit = raw.match(/github\.com[:/]+([^/]+)\/([^/#?]+)/i)
2405
+ if (!hit) return ''
2406
+ return hit[1] + '/' + hit[2].replace(/\.git$/i, '')
2407
+ }
2408
+
2409
+ /* Panels remount on every tab switch, so the parsed notes survive in a
2410
+ * module-level map: the second open is instant, not another 2-3s round trip. */
2411
+ const changelogCache = new Map()
2412
+
2413
+ /* Loose semver compare: enough to tell 1.10.0 from 1.9.4 and to bound the
2414
+ * range of versions a single click should explain. */
2415
+ function versionParts(text) {
2416
+ return String(text || '')
2417
+ .replace(/^v/i, '')
2418
+ .split(/[.\-+]/)
2419
+ .map(function (piece) {
2420
+ const n = parseInt(piece, 10)
2421
+ return Number.isFinite(n) ? n : 0
2422
+ })
2423
+ }
2424
+
2425
+ function compareVersions(a, b) {
2426
+ const left = versionParts(a)
2427
+ const right = versionParts(b)
2428
+ const size = Math.max(left.length, right.length)
2429
+ for (let i = 0; i < size; i += 1) {
2430
+ const diff = (left[i] || 0) - (right[i] || 0)
2431
+ if (diff !== 0) return diff > 0 ? 1 : -1
2432
+ }
2433
+ return 0
2434
+ }
2435
+
2436
+ /* Cross-version updates deserve cross-version notes, so the whole release
2437
+ * list is read once and then narrowed to (installed, latest]. */
2438
+ async function readChangelog(repo, upperBound, installed) {
2439
+ if (!repo) return { state: 'empty' }
2440
+ const cacheKey = repo + '|' + String(installed || '') + '|' + String(upperBound || '')
2441
+ if (changelogCache.has(cacheKey)) return changelogCache.get(cacheKey)
2442
+ const base = 'https://api.github.com/repos/' + repo
2443
+ let res
2444
+ try {
2445
+ res = await fetch(base + '/releases?per_page=60', {
2446
+ headers: { accept: 'application/vnd.github+json' },
2447
+ })
2448
+ } catch (err) {
2449
+ return { state: 'failed' }
2450
+ }
2451
+ if (res.status === 403) return { state: 'rate' }
2452
+ if (!res.ok) return { state: 'failed' }
2453
+ const list = await res.json().catch(function () {
2454
+ return null
2455
+ })
2456
+ if (!Array.isArray(list)) return { state: 'failed' }
2457
+
2458
+ const releases = list
2459
+ .filter(function (item) {
2460
+ return item && !item.draft && typeof item.body === 'string' && item.body.trim() !== ''
2461
+ })
2462
+ .map(function (item) {
2463
+ return {
2464
+ version: String(item.tag_name || item.name || '').replace(/^v/i, ''),
2465
+ body: String(item.body || ''),
2466
+ }
2467
+ })
2468
+ .filter(function (item) {
2469
+ return item.version !== ''
2470
+ })
2471
+ .sort(function (a, b) {
2472
+ return compareVersions(b.version, a.version)
2473
+ })
2474
+
2475
+ const upper = String(upperBound || '')
2476
+ const lower = String(installed || '')
2477
+ let picked = releases.filter(function (item) {
2478
+ if (compareVersions(item.version, upper) > 0) return false
2479
+ if (lower && compareVersions(item.version, lower) <= 0) return false
2480
+ return true
2481
+ })
2482
+ if (picked.length === 0) {
2483
+ picked = releases.filter(function (item) {
2484
+ return compareVersions(item.version, upper) === 0
2485
+ })
2486
+ }
2487
+ /* A long gap could mean twenty releases; the newest eight is plenty. */
2488
+ const result = picked.length === 0
2489
+ ? { state: 'empty' }
2490
+ : { state: 'ready', groups: picked.slice(0, 8).map(function (item) { return item }) }
2491
+ changelogCache.set(cacheKey, result)
2492
+ return result
2493
+ }
2494
+
2495
+ /* The notes are shown in Chinese, so drop the blocks that carry no CJK at
2496
+ * all and keep everything else in its original order. */
2497
+ function chineseBlocks(text) {
2498
+ const cjk = /[\u3400-\u9fff\u3000-\u303f\uff00-\uffef]/
2499
+ return String(text || '')
2500
+ .split(/\r?\n/)
2501
+ .filter(function (line) {
2502
+ return cjk.test(line)
2503
+ })
2504
+ }
2505
+
2506
+ /* A deliberately tiny Markdown reader: headings, list items, bold, inline
2507
+ * code and links — enough for release notes, small enough to stay here. */
2508
+ function renderInline(text, keyPrefix) {
2509
+ const out = []
2510
+ const pattern = /(\*\*[^*]+\*\*|`[^`]+`|\[[^\]]+\]\([^)]+\))/g
2511
+ let cursor = 0
2512
+ let match = pattern.exec(text)
2513
+ let index = 0
2514
+ while (match) {
2515
+ if (match.index > cursor) out.push(text.slice(cursor, match.index))
2516
+ const token = match[0]
2517
+ index += 1
2518
+ if (token.startsWith('**')) {
2519
+ out.push(h('strong', { key: keyPrefix + '-b' + String(index) }, token.slice(2, -2)))
2520
+ } else if (token.startsWith('`')) {
2521
+ out.push(h('code', { key: keyPrefix + '-c' + String(index) }, token.slice(1, -1)))
2522
+ } else {
2523
+ const label = token.slice(1, token.indexOf(']'))
2524
+ out.push(h('span', { key: keyPrefix + '-l' + String(index), className: 'dsuik-up-link' }, label))
2525
+ }
2526
+ cursor = match.index + token.length
2527
+ match = pattern.exec(text)
2528
+ }
2529
+ if (cursor < text.length) out.push(text.slice(cursor))
2530
+ return out
2531
+ }
2532
+
2533
+ function renderNotes(text, keyPrefix) {
2534
+ const lines = chineseBlocks(text)
2535
+ const nodes = []
2536
+ lines.forEach(function (line, index) {
2537
+ const trimmed = line.trim()
2538
+ if (trimmed === '') return
2539
+ const key = keyPrefix + '-' + String(index)
2540
+ const heading = trimmed.match(/^#{1,6}\s+(.*)$/)
2541
+ const bullet = trimmed.match(/^[-*+]\s+(.*)$/)
2542
+ const ordered = trimmed.match(/^\d+[.)]\s+(.*)$/)
2543
+ if (heading) {
2544
+ nodes.push(h('p', { key: key, className: 'dsuik-up-h' }, renderInline(heading[1], key)))
2545
+ } else if (bullet) {
2546
+ nodes.push(h('p', { key: key, className: 'dsuik-up-li' }, '· ', renderInline(bullet[1], key)))
2547
+ } else if (ordered) {
2548
+ nodes.push(h('p', { key: key, className: 'dsuik-up-li' }, trimmed.slice(0, trimmed.indexOf(' ')) + ' ', renderInline(ordered[1], key)))
2549
+ } else {
2550
+ nodes.push(h('p', { key: key, className: 'dsuik-up-p' }, renderInline(trimmed, key)))
2551
+ }
2552
+ })
2553
+ return nodes
2554
+ }
2555
+
2556
+ /* The Host runs the install itself: same guard rails as its own plugin
2557
+ * page (running agents block it), and it reports `restart-required` when
2558
+ * the change only lands at the next start. */
2559
+ async function runUpdate(name, target, onProgress) {
2560
+ const pm = pluginManager()
2561
+ if (!pm) throw new Error('the plugin manager is unavailable')
2562
+ if (typeof onProgress === 'function') {
2563
+ onProgress({ state: 'running', progress: { percent: null, detail: '' } })
2564
+ }
2565
+ const requestId = 'ui-optimize-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 7)
2566
+ const answer = await pm.updateBundle(name, target.version, { requestId: requestId })
2567
+ if (!answer || answer.ok !== true) {
2568
+ return {
2569
+ state: 'failed',
2570
+ failure: { code: 'UPDATE_REJECTED', message: failureMessage(answer && answer.error) },
2571
+ }
2572
+ }
2573
+ const update = answer.value || {}
2574
+ const change = update.result || {}
2575
+ if (change.application === 'cancelled') return { state: 'cancelled' }
2576
+ if (change.application === 'failed' || change.application === 'overridden') {
2577
+ return {
2578
+ state: 'failed',
2579
+ failure: {
2580
+ code: 'UPDATE_REJECTED',
2581
+ message: failureMessage(change.error) || change.application,
2582
+ },
2583
+ }
2584
+ }
2585
+ return {
2586
+ state: 'succeeded',
2587
+ installedVersion: update.to || target.version,
2588
+ restartRequired: change.application === 'restart-required',
2589
+ }
2590
+ }
2591
+
2592
+ function spinIcon(size) {
2593
+ const px = size || 13
2594
+ return h('svg', {
2595
+ className: 'dsuik-up-spin',
2596
+ viewBox: '0 0 16 16',
2597
+ width: px,
2598
+ height: px,
2599
+ 'aria-hidden': 'true',
2600
+ },
2601
+ h('circle', {
2602
+ cx: 8, cy: 8, r: 6,
2603
+ fill: 'none',
2604
+ stroke: 'currentColor',
2605
+ 'stroke-width': 2,
2606
+ 'stroke-linecap': 'round',
2607
+ 'stroke-dasharray': '26 12',
2608
+ }))
2609
+ }
2610
+
2611
+ function updateLabel(row) {
2612
+ if (row.state === 'running') return translate('updates.running')
2613
+ if (row.state === 'succeeded') return translate('updates.succeeded')
2614
+ if (row.state === 'failed') return translate('updates.failed')
2615
+ if (row.age === undefined) return translate('updates.readingAge')
2616
+ if (row.age === null) return translate('updates.unknownAge')
2617
+ if (row.age < FRESH_RELEASE_MS) return translate('updates.waiting')
2618
+ return ''
2619
+ }
2620
+
2621
+ /* The badge sits in the tab strip, outside this panel, so the count is kept
2622
+ * in a tiny module store: the label subscribes, the panel publishes. */
2623
+ const updateBadge = {
2624
+ count: 0,
2625
+ listeners: new Set(),
2626
+ set: function (next) {
2627
+ if (next === updateBadge.count) return
2628
+ updateBadge.count = next
2629
+ updateBadge.listeners.forEach(function (listener) {
2630
+ listener()
2631
+ })
2632
+ },
2633
+ }
2634
+
2635
+ let badgeScan = null
2636
+ /* One scan at start-up keeps the badge right before the tab is ever opened.
2637
+ * Same 24h rule as the panel, and the same "no age, not eligible" stance. */
2638
+ function refreshUpdateBadge() {
2639
+ if (store.state.updates === false) {
2640
+ updateBadge.set(0)
2641
+ return Promise.resolve(0)
2642
+ }
2643
+ if (badgeScan) return badgeScan
2644
+ badgeScan = (async function () {
2645
+ try {
2646
+ const scan = await collectUpdates()
2647
+ const fallbackOn = store.state.updatesFallback === true
2648
+ /* Same rule as the list: a fallback row counts only when the
2649
+ * previous release is actually newer than what is installed. */
2650
+ updateBadge.set(
2651
+ scan.rows.filter(function (row) {
2652
+ if (typeof row.age === 'number' && row.age >= FRESH_RELEASE_MS) return true
2653
+ if (!fallbackOn || !row.fallbackVersion) return false
2654
+ return compareVersions(row.fallbackVersion, row.installed) > 0
2655
+ }).length,
2656
+ )
2657
+ } catch (error) {
2658
+ updateBadge.set(0)
2659
+ }
2660
+ return updateBadge.count
2661
+ })()
2662
+ const settled = badgeScan.finally(function () {
2663
+ /* Release the guard: the badge has to be recomputable after an update,
2664
+ * a settings change, or a manual re-check. Keeping it cached forever
2665
+ * froze the number at its first scan. */
2666
+ badgeScan = null
2667
+ })
2668
+ badgeScan = settled
2669
+ return settled
2670
+ }
2671
+
2672
+ function useUpdateBadge() {
2673
+ const [count, setCount] = React.useState(updateBadge.count)
2674
+ React.useEffect(function () {
2675
+ function sync() {
2676
+ setCount(updateBadge.count)
2677
+ }
2678
+ updateBadge.listeners.add(sync)
2679
+ sync()
2680
+ return function () {
2681
+ updateBadge.listeners.delete(sync)
2682
+ }
2683
+ }, [])
2684
+ return count
2685
+ }
2686
+
2687
+ function UpdateBadge() {
2688
+ const count = useUpdateBadge()
2689
+ if (count <= 0) return null
2690
+ return h('span', { className: 'dsuik-up-badge' }, String(count))
2691
+ }
2692
+
2693
+ /* Progress lives outside the component: switching tabs unmounts it,
2694
+ * and an install that is still running must not vanish with the view. */
2695
+ const updateRun = {
2696
+ rows: [],
2697
+ checked: 0,
2698
+ busy: false,
2699
+ listeners: new Set(),
2700
+ snapshot: function () {
2701
+ return { rows: updateRun.rows, checked: updateRun.checked, busy: updateRun.busy }
2702
+ },
2703
+ set: function (changes) {
2704
+ if (changes.rows !== undefined) updateRun.rows = changes.rows
2705
+ if (changes.checked !== undefined) updateRun.checked = changes.checked
2706
+ if (changes.busy !== undefined) updateRun.busy = changes.busy
2707
+ const snap = updateRun.snapshot()
2708
+ updateRun.listeners.forEach(function (fn) { fn(snap) })
2709
+ },
2710
+ subscribe: function (fn) {
2711
+ updateRun.listeners.add(fn)
2712
+ return function () { updateRun.listeners.delete(fn) }
2713
+ }
2714
+ }
2715
+
2716
+ function UpdatesTab() {
2717
+ const [phase, setPhase] = React.useState(updateRun.busy ? 'ready' : 'loading')
2718
+ /* Mirror of `phase` for timers: reading a ref avoids calling one
2719
+ * setState from inside another setState's updater, which throws. */
2720
+ const phaseRef = React.useRef(updateRun.busy ? 'ready' : 'loading')
2721
+ function setPhaseSafe(next) {
2722
+ phaseRef.current = next
2723
+ setPhase(next)
2724
+ }
2725
+ const [run, setRun] = React.useState(updateRun.snapshot())
2726
+ const rows = run.rows
2727
+ const checked = run.checked
2728
+ const busy = run.busy
2729
+ function setRows(next) {
2730
+ updateRun.set({ rows: typeof next === 'function' ? next(updateRun.rows) : next })
2731
+ }
2732
+ function setChecked(next) { updateRun.set({ checked: next }) }
2733
+ function setBusy(next) { updateRun.set({ busy: next }) }
2734
+ const [message, setMessage] = React.useState('')
2735
+ const [open, setOpen] = React.useState({})
2736
+ const [notes, setNotes] = React.useState({})
2737
+ const [settings, setSettings] = React.useState(store.state)
2738
+ const [clock, setClock] = React.useState(0)
2739
+ const alive = React.useRef(true)
2740
+ const fallbackOn = settings.updatesFallback === true
2741
+
2742
+ React.useEffect(function () {
2743
+ return store.subscribe(function () {
2744
+ setSettings(store.state)
2745
+ })
2746
+ }, [])
2747
+
2748
+ React.useEffect(function () {
2749
+ return updateRun.subscribe(setRun)
2750
+ }, [])
2751
+
2752
+ React.useEffect(function () {
2753
+ alive.current = true
2754
+ /* Ticks once a second so a frozen main thread is visible on screen:
2755
+ * if this number stops moving, React is not re-rendering at all. */
2756
+ const ticker = setInterval(function () {
2757
+ if (phaseRef.current !== 'loading') return
2758
+ setClock(function (value) { return value + 1 })
2759
+ }, 1000)
2760
+ load().catch(function (err) {
2761
+ if (!alive.current) return
2762
+ phaseRef.current = 'error'
2763
+ console.warn('[dsh-ui-optimize] update scan failed', err)
2764
+ setMessage(translate('updates.loadFailed'))
2765
+ setPhaseSafe('error')
2766
+ })
2767
+ return function () {
2768
+ alive.current = false
2769
+ clearInterval(ticker)
2770
+ }
2771
+ }, [])
2772
+
2773
+ function patch(name, changes) {
2774
+ setRows(function (previous) {
2775
+ return previous.map(function (row) {
2776
+ return row.name === name ? Object.assign({}, row, changes) : row
2777
+ })
2778
+ })
2779
+ }
2780
+
2781
+ async function load(force) {
2782
+ /* "Check again" has to mean it: the cached scan would answer
2783
+ * instantly and the button would look broken. */
2784
+ if (force === true) {
2785
+ scanCache = { at: 0, value: null }
2786
+ registryCache.clear()
2787
+ }
2788
+ if (store.state.updates === false) {
2789
+ setPhaseSafe('off')
2790
+ return
2791
+ }
2792
+ /* A batch started from an earlier mount is still running: keep its
2793
+ * rows and progress instead of rescanning over the top of it. */
2794
+ if (updateRun.busy) {
2795
+ setPhaseSafe('ready')
2796
+ return
2797
+ }
2798
+ /* A warm scan is shown at once and then revalidated in the background:
2799
+ * opening the tab always re-checks, but never blanks the list or makes
2800
+ * the user press "Check again" to see current numbers. */
2801
+ const warm = scanCache.value && Date.now() - scanCache.at < SCAN_CACHE_MS ? scanCache.value : null
2802
+ const carried = updateRun.rows.filter(function (row) { return row.state === 'succeeded' })
2803
+ if (warm) {
2804
+ const merged = carried.slice()
2805
+ warm.rows.forEach(function (row) {
2806
+ if (carried.some(function (item) { return item.name === row.name })) return
2807
+ merged.push(row)
2808
+ })
2809
+ merged.sort(function (a, b) { return a.name.localeCompare(b.name) })
2810
+ setRows(merged)
2811
+ setChecked(warm.checked)
2812
+ phaseRef.current = 'ready'
2813
+ setPhaseSafe('ready')
2814
+ setMessage('')
2815
+ scanCache = { at: 0, value: null }
2816
+ } else {
2817
+ phaseRef.current = 'loading'
2818
+ setPhaseSafe('loading')
2819
+ setMessage('')
2820
+ /* Keep what this session already installed on screen: a rescan would
2821
+ * otherwise drop those rows the moment the batch finishes, taking
2822
+ * the only confirmation the user gets with them. */
2823
+ setRows(carried)
2824
+ }
2825
+ /* Rows appear as their registry answers arrive, so a slow package
2826
+ * never leaves the panel empty. */
2827
+ const scan = await collectUpdates(function (row) {
2828
+ if (!alive.current) return
2829
+ phaseRef.current = 'ready'
2830
+ setPhaseSafe('ready')
2831
+ setRows(function (previous) {
2832
+ const next = previous.filter(function (item) {
2833
+ return item.name !== row.name
2834
+ })
2835
+ next.push(row)
2836
+ next.sort(function (a, b) {
2837
+ return a.name.localeCompare(b.name)
2838
+ })
2839
+ return next
2840
+ })
2841
+ })
2842
+ if (!alive.current) return
2843
+ if (scan.supported === false) {
2844
+ if (scan.stalled === 'listBundles') {
2845
+ phaseRef.current = 'error'
2846
+ setPhaseSafe('error')
2847
+ setMessage(translate('updates.pmStalled'))
2848
+ return
2849
+ }
2850
+ setPhaseSafe('error')
2851
+ setMessage(translate('updates.pmStalled'))
2852
+ return
2853
+ }
2854
+ setChecked(scan.checked)
2855
+ /* Reconcile with the fresh scan: a warm list can hold rows that have
2856
+ * since been installed (here or elsewhere) and must not linger. */
2857
+ setRows(function (previous) {
2858
+ const kept = previous.filter(function (row) {
2859
+ return row.state === 'succeeded' || row.state === 'running'
2860
+ })
2861
+ const merged = kept.slice()
2862
+ scan.rows.forEach(function (row) {
2863
+ if (merged.some(function (item) { return item.name === row.name })) return
2864
+ merged.push(row)
2865
+ })
2866
+ merged.sort(function (a, b) { return a.name.localeCompare(b.name) })
2867
+ return merged
2868
+ })
2869
+ setMessage('')
2870
+ phaseRef.current = 'ready'
2871
+ if (scan.rows.length === 0 && scan.stats && scan.stats.tried > 0 && scan.stats.failed === scan.stats.tried) {
2872
+ /* The registry never answered: say so instead of claiming the
2873
+ * machine is fully up to date. */
2874
+ setPhaseSafe('error')
2875
+ setMessage(translate('updates.registryDown'))
2876
+ return
2877
+ }
2878
+ setPhaseSafe('ready')
2879
+ }
2880
+
2881
+ /* What this row would install, or null when the 24-hour rule (and the
2882
+ * optional fallback) leaves nothing safe to install. */
2883
+ function targetOf(row) {
2884
+ /* A release the running DSH cannot load is not an update target. */
2885
+ if (row.compat) return null
2886
+ if (typeof row.age === 'number' && row.age >= FRESH_RELEASE_MS) {
2887
+ return { version: row.latest, fallback: false }
2888
+ }
2889
+ /* The previous release is only useful when it is actually newer than
2890
+ * what is installed — otherwise "update" would be a no-op. */
2891
+ if (fallbackOn && row.fallbackVersion && compareVersions(row.fallbackVersion, row.installed) > 0) {
2892
+ return { version: row.fallbackVersion, fallback: true }
2893
+ }
2894
+ return null
2895
+ }
2896
+
2897
+ /* The version this row will actually end up on — the changelog range has
2898
+ * to stop there, otherwise a fallback row would list changes for a
2899
+ * release it is deliberately not installing today. */
2900
+ function targetVersion(row) {
2901
+ const target = targetOf(row)
2902
+ return target ? target.version : row.latest
2903
+ }
2904
+
2905
+ const eligible = rows.filter(function (row) {
2906
+ return row.state !== 'succeeded' && targetOf(row) !== null
2907
+ })
2908
+
2909
+ React.useEffect(function () {
2910
+ updateBadge.set(eligible.length)
2911
+ }, [eligible.length])
2912
+
2913
+ async function updateAll() {
2914
+ if (busy) return
2915
+ const targets = eligible.map(function (row) {
2916
+ return { name: row.name, from: row.installed, target: targetOf(row) }
2917
+ })
2918
+ if (targets.length === 0) return
2919
+ setBusy(true)
2920
+ setMessage('')
2921
+ let restarts = 0
2922
+ let refreshes = 0
2923
+ for (let index = 0; index < targets.length; index += 1) {
2924
+ const name = targets[index].name
2925
+ patch(name, { state: 'running', percent: null, detail: '' })
2926
+ try {
2927
+ const operation = await runUpdate(name, targets[index].target, function (next) {
2928
+ const progress = next && next.progress ? next.progress : null
2929
+ patch(name, {
2930
+ percent: progress && typeof progress.percent === 'number' ? progress.percent : null,
2931
+ detail: progress && progress.detail ? progress.detail : '',
2932
+ })
2933
+ })
2934
+ const ok = operation && operation.state === 'succeeded'
2935
+ /* How the update lands decides what the user has to do next:
2936
+ * a host-side change only applies at the next start, while a
2937
+ * client bundle is enough to reload the page for. */
2938
+ const needs = !ok ? '' : operation && operation.restartRequired ? 'restart' : 'refresh'
2939
+ if (needs === 'restart') restarts += 1
2940
+ else if (needs === 'refresh') refreshes += 1
2941
+ patch(name, {
2942
+ state: ok ? 'succeeded' : 'failed',
2943
+ needs: needs,
2944
+ percent: 100,
2945
+ done: ok
2946
+ ? { from: targets[index].from, to: (operation && operation.installedVersion) || targets[index].target.version }
2947
+ : undefined,
2948
+ detail: ok
2949
+ ? ''
2950
+ : operation && operation.failure
2951
+ ? operation.failure.code + ' — ' + operation.failure.message
2952
+ : (operation && operation.state) || 'failed',
2953
+ })
2954
+ } catch (err) {
2955
+ patch(name, { state: 'failed', percent: 100, detail: err.message })
2956
+ }
2957
+ }
2958
+ /* The batch may outlive this mount: write the result to the shared
2959
+ * run state unconditionally, or a remount would come back with the
2960
+ * button stuck on "busy" forever. */
2961
+ setBusy(false)
2962
+ if (alive.current) {
2963
+ setMessage(
2964
+ restarts > 0
2965
+ ? translate('updates.needRestartHint').replace('{n}', String(restarts))
2966
+ : refreshes > 0
2967
+ ? translate('updates.needRefreshHint')
2968
+ : translate('updates.reloadHint'),
2969
+ )
2970
+ }
2971
+ refreshUpdateBadge()
2972
+ }
2973
+
2974
+ const header = h(
2975
+ 'div',
2976
+ { className: 'dsuik-up-header' },
2977
+ h('div', { className: 'dsuik-up-headtext' },
2978
+ h('p', { className: 'dsuik-up-title' }, translate('updates.title')),
2979
+ h('p', { className: 'dsuik-up-sub' }, translate('updates.sub')),
2980
+ ),
2981
+ h('div', { className: 'dsuik-up-actions' },
2982
+ h('button', {
2983
+ type: 'button',
2984
+ className: 'dsuik-up-btn',
2985
+ disabled: busy || phase === 'loading',
2986
+ onClick: function () { load(true) },
2987
+ }, phase === 'loading'
2988
+ ? h('span', { className: 'dsuik-up-btnlabel' },
2989
+ spinIcon(),
2990
+ translate('updates.checking'))
2991
+ : translate('updates.check')),
2992
+ h('button', {
2993
+ type: 'button',
2994
+ className: 'dsuik-up-btn is-primary',
2995
+ disabled: busy || phase !== 'ready' || eligible.length === 0,
2996
+ onClick: updateAll,
2997
+ }, busy ? translate('updates.updating') : translate('updates.updateAll') + ' (' + String(eligible.length) + ')'),
2998
+ ),
2999
+ )
3000
+
3001
+ if (settings.updates === false && phase !== 'loading') {
3002
+ return h('div', { className: 'dsuik-up' },
3003
+ h('div', { className: 'dsuik-up-header' },
3004
+ h('div', { className: 'dsuik-up-headtext' },
3005
+ h('p', { className: 'dsuik-up-title' }, translate('updates.off')),
3006
+ h('p', { className: 'dsuik-up-sub' }, translate('updates.offHint')),
3007
+ ),
3008
+ ),
3009
+ )
3010
+ }
3011
+
3012
+ if (phase === 'unsupported') {
3013
+ return h('div', { className: 'dsuik-up' }, header,
3014
+ h('p', { className: 'dsuik-up-note' }, translate('updates.unsupported')))
3015
+ }
3016
+
3017
+ /* Warm the cache before the click lands: hover, focus and touch-down all
3018
+ * give us a head start on the GitHub round trip. */
3019
+ function prefetchNotes(row) {
3020
+ if (notes[row.name] || !row.repo) return
3021
+ setNotes(function (previous) {
3022
+ return previous[row.name] ? previous : Object.assign({}, previous, { [row.name]: { state: 'loading' } })
3023
+ })
3024
+ readChangelog(row.repo, targetVersion(row), row.installed).then(function (info) {
3025
+ if (!alive.current) return
3026
+ setNotes(function (previous) {
3027
+ return Object.assign({}, previous, { [row.name]: info })
3028
+ })
3029
+ }, function () {
3030
+ if (!alive.current) return
3031
+ setNotes(function (previous) {
3032
+ return Object.assign({}, previous, { [row.name]: { state: 'failed' } })
3033
+ })
3034
+ })
3035
+ }
3036
+
3037
+ function toggleNotes(row) {
3038
+ const isOpen = !!open[row.name]
3039
+ setOpen(function (previous) {
3040
+ const next = Object.assign({}, previous)
3041
+ next[row.name] = !isOpen
3042
+ return next
3043
+ })
3044
+ if (isOpen) return
3045
+ prefetchNotes(row)
3046
+ }
3047
+
3048
+ function notesView(name, row) {
3049
+ const note = notes[name] || { state: 'loading' }
3050
+ if (note.state === 'loading') return translate('updates.notesLoading')
3051
+ if (note.state === 'rate') return translate('updates.notesRate')
3052
+ if (note.state === 'failed') return translate('updates.notesFailed')
3053
+ if (note.state !== 'ready') return translate('updates.notesEmpty')
3054
+ const blocks = []
3055
+ note.groups.forEach(function (group, groupIndex) {
3056
+ const rendered = renderNotes(group.body, name + '-' + group.version)
3057
+ /* A version whose notes are English-only still gets its heading:
3058
+ * dropping the whole block made the list skip 1.73.16 and 1.73.15
3059
+ * and look as if the target version had no entry at all. */
3060
+ if (note.groups.length > 1) {
3061
+ blocks.push(h('p', { key: name + '-v' + String(groupIndex), className: 'dsuik-up-verhead' }, 'v' + group.version))
3062
+ }
3063
+ blocks.push(h('div', { key: name + '-g' + String(groupIndex), className: 'dsuik-up-group' },
3064
+ rendered.length === 0
3065
+ ? h('p', { className: 'dsuik-up-li is-empty' }, translate('updates.notesNoZhVersion'))
3066
+ : rendered))
3067
+ })
3068
+ if (blocks.length === 0) return translate('updates.notesNoZh')
3069
+ if (note.groups.length > 1) {
3070
+ blocks.unshift(h('p', { key: name + '-span', className: 'dsuik-up-span' },
3071
+ translate('updates.notesSpan').replace('{from}', String(row.installed || '?'))))
3072
+ }
3073
+ return blocks
3074
+ }
3075
+
3076
+ /* Every card is a disclosure: click the chip to fold the release notes
3077
+ * out underneath it, click again to fold them away. */
3078
+ function rowView(row, index, quiet) {
3079
+ const target = targetOf(row)
3080
+ /* Rows are created with state:'idle', not with an empty state —
3081
+ * `!row.state` was therefore never true and every row looked "busy",
3082
+ * which is what pushed the wait label back onto finished rows. */
3083
+ const idle = !row.state || row.state === 'idle'
3084
+ const usingFallback = !!target && target.fallback
3085
+ const fallbackShown = usingFallback ? target.version : ''
3086
+ /* A running or finished row speaks with its state, not with the plan:
3087
+ * the "previous release" tag belongs to a row that has not started yet,
3088
+ * otherwise 更新中 never gets a chance to show. */
3089
+ const label = idle ? (quiet || usingFallback ? '' : updateLabel(row)) : updateLabel(row)
3090
+ /* Nothing to install yet: say how far the nearest candidate is, so a
3091
+ * row that is "waiting" does not look like the plugin forgot it.
3092
+ * Only idle rows: a finished row must not read "已更新 · 剩余 5.1 小时". */
3093
+ const soon = idle && !usingFallback && typeof row.age === 'number' && row.age < FRESH_RELEASE_MS
3094
+ ? translate('updates.latestSoon')
3095
+ .replace('{hours}', String(Math.max(0.1, Math.ceil(((FRESH_RELEASE_MS - row.age) / 3600000) * 10) / 10)))
3096
+ : ''
3097
+ const isOpen = !!open[row.name]
3098
+ return h(
3099
+ 'li',
3100
+ {
3101
+ key: row.name,
3102
+ className: 'dsuik-up-row'
3103
+ + (row.state === 'running' ? ' is-running' : '')
3104
+ + (row.state === 'succeeded' ? ' is-ok' : '')
3105
+ + (row.state === 'failed' ? ' is-fail' : '')
3106
+ + (isOpen ? ' is-open' : ''),
3107
+ style: { animationDelay: String(Math.min(index, 12) * 18) + 'ms' },
3108
+ },
3109
+ h('button', {
3110
+ type: 'button',
3111
+ className: 'dsuik-up-head',
3112
+ 'aria-expanded': isOpen ? 'true' : 'false',
3113
+ title: translate('updates.notesToggle'),
3114
+ onMouseEnter: function () {
3115
+ prefetchNotes(row)
3116
+ },
3117
+ onFocus: function () {
3118
+ prefetchNotes(row)
3119
+ },
3120
+ onPointerDown: function () {
3121
+ prefetchNotes(row)
3122
+ },
3123
+ onClick: function () {
3124
+ toggleNotes(row)
3125
+ },
3126
+ },
3127
+ h('span', { className: 'dsuik-up-main' },
3128
+ h('span', { className: 'dsuik-up-name' }, row.name),
3129
+ h('span', { className: 'dsuik-up-ver' },
3130
+ String((row.done && row.done.from) || row.installed || '?') +
3131
+ ' → ' +
3132
+ String((row.done && row.done.to) || fallbackShown || row.latest || '?')),
3133
+ soon ? h('span', { className: 'dsuik-up-soon' }, soon) : null,
3134
+ label ? h('span', { className: 'dsuik-up-tag' }, label) : null,
3135
+ fallbackShown ? h('span', { className: 'dsuik-up-tag', title: translate('updates.fallbackWhy') }, translate('updates.fallbackTag')) : null,
3136
+ row.compat && !row.state
3137
+ ? h('span', { className: 'dsuik-up-tag is-warn', title: translate('updates.section.blockedHint') },
3138
+ translate('updates.compatTag').replace('{version}', String(row.compat.required || row.compat.runtime || '?')))
3139
+ : null,
3140
+ row.detail ? h('span', { className: 'dsuik-up-detail' }, row.detail) : null,
3141
+ ),
3142
+ h('span', { className: 'dsuik-up-chev', 'aria-hidden': 'true' }, isOpen ? '▾' : '▸'),
3143
+ ),
3144
+ row.state === 'running'
3145
+ ? (row.percent === null
3146
+ ? h('div', { className: 'dsuik-up-bar is-indef' }, h('i'))
3147
+ : h('div', { className: 'dsuik-up-bar' }, h('i', { style: { width: String(row.percent || 0) + '%' } })))
3148
+ : null,
3149
+ isOpen ? h('div', { className: 'dsuik-up-notes' }, notesView(row.name, row)) : null,
3150
+ )
3151
+ }
3152
+
3153
+ /* Two areas: everything the 24-hour rule lets us touch on top, the rest
3154
+ * below it, so the button above always matches the list above. */
3155
+ const groups = { ready: [], blocked: [], waiting: [] }
3156
+ rows.forEach(function (row) {
3157
+ const ready = row.state === 'succeeded' || targetOf(row) !== null
3158
+ if (ready) groups.ready.push(row)
3159
+ else if (row.compat && row.state !== 'succeeded') groups.blocked.push(row)
3160
+ else groups.waiting.push(row)
3161
+ })
3162
+ /* Soonest to unlock first: 25h old is 23h from being updateable, 4h old
3163
+ * is 20h away. Rows whose age could not be read go last — we cannot
3164
+ * promise a time for them. */
3165
+ groups.waiting.sort(function (a, b) {
3166
+ const left = function (row) {
3167
+ return typeof row.age === 'number' ? row.age : -Infinity
3168
+ }
3169
+ return left(b) - left(a)
3170
+ })
3171
+
3172
+ /* How many of the checked plugins simply have nothing newer. Without it,
3173
+ * "30 checked" next to ten visible rows reads like a failed scan. */
3174
+ const upToDate = Math.max(0, checked - rows.length)
3175
+
3176
+ function sectionArea(titleKey, items, muted, hintKey, always) {
3177
+ if (items.length === 0 && !always) return null
3178
+ return h(
3179
+ 'section',
3180
+ { className: 'dsuik-up-section' + (muted ? ' is-muted' : '') },
3181
+ h('div', { className: 'dsuik-up-section-head' },
3182
+ h('p', { className: 'dsuik-up-section-title' },
3183
+ translate(titleKey) + ' (' + String(items.length) + ')'),
3184
+ hintKey
3185
+ ? h('p', { className: 'dsuik-up-section-hint' },
3186
+ hintKey.indexOf('updates.') === 0 ? translate(hintKey) : hintKey)
3187
+ : null,
3188
+ ),
3189
+ items.length === 0
3190
+ ? null
3191
+ : h('ul', { className: 'dsuik-up-list' },
3192
+ items.map(function (row, index) { return rowView(row, index, muted) })),
3193
+ )
3194
+ }
3195
+
3196
+ return h(
3197
+ 'div',
3198
+ { className: 'dsuik-up' },
3199
+
3200
+ header,
3201
+ phase === 'error' ? h('p', { className: 'dsuik-up-note is-error' }, translate('updates.loadFailed') + ' — ' + message) : null,
3202
+ phase === 'loading'
3203
+ ? h('div', { className: 'dsuik-up-loading', role: 'status' },
3204
+ spinIcon(16),
3205
+ h('span', null,
3206
+ message ||
3207
+ (clock >= 13
3208
+ ? translate('updates.pmTimeout').replace('{ms}', String(clock))
3209
+ : clock >= 4
3210
+ ? translate('updates.pmWaiting')
3211
+ : translate('updates.loadingDetail'))))
3212
+ : null,
3213
+ phase === 'ready'
3214
+ ? h('p', { className: 'dsuik-up-note' },
3215
+ String(checked) + ' ' + translate('updates.checked') +
3216
+ (upToDate > 0 ? ' · ' + translate('updates.upToDate').replace('{n}', String(upToDate)) : ''))
3217
+ : null,
3218
+ /* The ready area stays on screen even when it is empty, so the page
3219
+ * always answers "is there anything for me?" instead of going blank. */
3220
+ phase === 'ready' ? sectionArea('updates.section.ready', groups.ready, false, null, true) : null,
3221
+ /* The closing hint belongs to the batch it talks about: right under the
3222
+ * rows you just updated, not after two unrelated sections. */
3223
+ phase === 'ready' && message ? h('p', { className: 'dsuik-up-note is-after-ready' }, message) : null,
3224
+ phase === 'ready' ? sectionArea('updates.section.waiting', groups.waiting, true, 'updates.section.waitingHint', false) : null,
3225
+ phase === 'ready'
3226
+ ? sectionArea(
3227
+ 'updates.section.blocked',
3228
+ groups.blocked,
3229
+ true,
3230
+ translate('updates.section.blockedHint').replace(
3231
+ '{runtime}',
3232
+ String((groups.blocked[0] && groups.blocked[0].compat && groups.blocked[0].compat.runtime) || ''),
3233
+ ),
3234
+ false,
3235
+ )
3236
+ : null,
3237
+ )
3238
+ }
3239
+
3240
+ const UPDATES_CSS = `
3241
+ .dsuik-up{display:flex;flex-direction:column;gap:14px;padding:4px 0 24px;font-size:14px;color:var(--dsw-alias-label-primary);}
3242
+ .dsuik-up-header{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;flex-wrap:wrap;}
3243
+ .dsuik-up-headtext{display:flex;flex-direction:column;gap:6px;min-width:240px;flex:1;}
3244
+ .dsuik-up-title{margin:0;font-size:16px;font-weight:600;line-height:1.4;}
3245
+ .dsuik-up-sub{margin:0;font-size:13px;line-height:1.65;color:var(--dsw-alias-label-secondary);}
3246
+ .dsuik-up-actions{display:flex;gap:8px;flex-shrink:0;}
3247
+ .dsuik-up-btn{font:inherit;font-size:13px;min-width:96px;padding:6px 12px;border-radius:8px;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:inherit;cursor:pointer;transition:border-color .16s ease,background .16s ease;}
3248
+ .dsuik-up-btn:hover:not(:disabled){border-color:var(--dsw-alias-border-l2);}
3249
+ .dsuik-up-btn:disabled{opacity:.5;cursor:default;}
3250
+ .dsuik-up-btn.is-primary{background:var(--dsw-alias-brand-primary);border-color:transparent;color:#fff;}
3251
+ .dsuik-up-note{margin:0;font-size:12.5px;line-height:1.6;color:var(--dsw-alias-label-secondary);}
3252
+ .dsuik-up-note.is-error{color:var(--dsw-alias-label-error, #c0392b);}
3253
+ @keyframes dsuik-up-rotate{to{transform:rotate(1turn)}}
3254
+ @keyframes dsuik-up-shimmer{0%{background-position:150% 0}100%{background-position:-50% 0}}
3255
+ @keyframes dsuik-up-in{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:none}}
3256
+ .dsuik-up-btnlabel{display:inline-flex;align-items:center;gap:6px;}
3257
+ .dsuik-up-spin{display:block;flex:0 0 auto;animation:dsuik-up-rotate .8s linear infinite;}
3258
+ .dsuik-up-section-head{display:flex;flex-direction:column;gap:2px;}
3259
+ .dsuik-up-section-hint{margin:0;font-size:12px;line-height:1.55;color:var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));}
3260
+ .dsuik-up-section{display:flex;flex-direction:column;gap:10px;animation:dsuik-up-in .26s cubic-bezier(.2,.8,.3,1) both;}
3261
+ .dsuik-up-section+.dsuik-up-section{margin-top:4px;padding-top:18px;border-top:1px solid var(--dsw-alias-border-l1);}
3262
+ .dsuik-up-section-title{margin:0;font-size:12.5px;font-weight:600;letter-spacing:.01em;color:var(--dsw-alias-label-primary);}
3263
+ .dsuik-up-section.is-muted .dsuik-up-row{opacity:.7;background:transparent;}
3264
+ .dsuik-up-note.is-after-ready{margin-top:-4px;}
3265
+ .dsuik-up-note.is-empty{padding:10px 12px;border:1px dashed var(--dsw-alias-border-l1);border-radius:10px;}
3266
+ .dsuik-up-loading{display:flex;align-items:center;justify-content:center;gap:8px;padding:34px 0 30px;font-size:13px;color:var(--dsw-alias-label-secondary);animation:dsuik-up-in .2s ease-out both;}
3267
+ @media (prefers-reduced-motion: reduce){.dsuik-up-section,.dsuik-up-row,.dsuik-up-loading{animation:none;}}
3268
+ .dsuik-up-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:10px;align-items:flex-start;}
3269
+ .dsuik-up-row{display:flex;flex-direction:column;gap:4px;width:auto;align-self:flex-start;padding:3px 10px;border:1px solid var(--dsw-alias-border-l1);border-radius:999px;background:var(--dsw-alias-bg-layer-1);animation:dsuik-up-in .24s cubic-bezier(.2,.8,.3,1) both;transition:border-color .2s ease,opacity .25s ease;}
3270
+ .dsuik-up-head{display:flex;align-items:center;flex-wrap:nowrap;gap:6px;margin:0;padding:0;border:0;background:none;font:inherit;color:inherit;cursor:pointer;text-align:left;}
3271
+ .dsuik-up-chev{font-size:10px;line-height:1;color:var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));}
3272
+ .dsuik-up-row.is-open{border-radius:12px;max-width:640px;}
3273
+ .dsuik-up-span{margin:0 0 6px;font-size:11.5px;color:var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));}
3274
+ .dsuik-up-verhead{margin:8px 0 2px;font-size:11.5px;font-weight:600;color:var(--dsw-alias-label-secondary);}
3275
+ .dsuik-up-group+.dsuik-up-group{margin-top:8px;padding-top:8px;border-top:1px dashed var(--dsw-alias-border-l1);}
3276
+ .dsuik-up-notes .dsuik-up-h{margin:6px 0 2px;font-weight:600;color:var(--dsw-alias-label-primary);}
3277
+ .dsuik-up-notes .dsuik-up-p{margin:2px 0;}
3278
+ .dsuik-up-notes .dsuik-up-li{margin:2px 0;padding-left:10px;text-indent:-10px;}
3279
+ .dsuik-up-notes .dsuik-up-li.is-empty{color:var(--dsw-alias-label-secondary);}
3280
+ .dsuik-up-notes code{padding:0 3px;border-radius:4px;background:var(--dsw-alias-bg-layer-2, rgba(0,0,0,.06));font-size:11.5px;}
3281
+ .dsuik-up-link{text-decoration:underline;}
3282
+ .dsuik-up-notes{margin-top:2px;padding-top:8px;border-top:1px dashed var(--dsw-alias-border-l1);font-size:12px;line-height:1.65;color:var(--dsw-alias-label-secondary);word-break:break-word;max-height:320px;overflow:auto;}
3283
+ .dsuik-up-row.is-running .dsuik-up-tag,.dsuik-up-row.is-ok .dsuik-up-tag,.dsuik-up-row.is-fail .dsuik-up-tag{background:transparent;}
3284
+ .dsuik-up-row.is-running{border-color:color-mix(in srgb, var(--dsw-alias-state-warn-primary) 55%, transparent);background:color-mix(in srgb, var(--dsw-alias-state-warn-primary) 12%, var(--dsw-alias-bg-layer-1));}
3285
+ .dsuik-up-row.is-ok{border-color:color-mix(in srgb, var(--dsw-alias-state-success-primary) 55%, transparent);background:color-mix(in srgb, var(--dsw-alias-state-success-primary) 12%, var(--dsw-alias-bg-layer-1));}
3286
+ .dsuik-up-row.is-fail{border-color:color-mix(in srgb, var(--dsw-alias-state-error-primary) 55%, transparent);background:color-mix(in srgb, var(--dsw-alias-state-error-primary) 12%, var(--dsw-alias-bg-layer-1));}
3287
+ .dsuik-up-main{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap;}
3288
+ .dsuik-up-name{font-weight:500;font-size:12.5px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
3289
+ .dsuik-up-ver{font-size:12.5px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;white-space:nowrap;}
3290
+ .dsuik-up-soon{font-size:12px;color:var(--dsw-alias-label-secondary);white-space:nowrap;flex:0 0 auto;}
3291
+ .dsuik-up-tag{font-size:12px;padding:1px 8px;border-radius:999px;background:var(--dsw-alias-bg-layer-2, rgba(0,0,0,.05));color:var(--dsw-alias-label-secondary);}
3292
+ .dsuik-up-detail{font-size:12px;color:var(--dsw-alias-label-secondary);flex-basis:100%;word-break:break-word;}
3293
+ .dsuik-up-bar{min-width:120px;height:4px;border-radius:999px;background:var(--dsw-alias-bg-layer-2, rgba(0,0,0,.07));overflow:hidden;}
3294
+ .dsuik-up-bar>i{display:block;height:100%;background:var(--dsw-alias-brand-primary);transition:width .3s ease;}
3295
+ .dsuik-up-tag.is-warn{color:var(--dsw-alias-state-error-primary, var(--dsw-alias-label-secondary));}
3296
+ .dsuik-up-row.is-running .dsuik-up-bar>i{background:var(--dsw-alias-state-warn-primary, var(--dsw-alias-brand-primary));}
3297
+ .dsuik-up-bar.is-indef>i{width:35%;animation:dsuik-up-slide 1.15s ease-in-out infinite;}
3298
+ @keyframes dsuik-up-slide{0%{transform:translateX(-60%)}100%{transform:translateX(300%)}}
3299
+ @media (prefers-reduced-motion: reduce){.dsuik-up-bar.is-indef>i{animation-duration:2.4s;}}
3300
+ .dsuik-up-tab{display:inline-flex;align-items:center;gap:5px;}
3301
+ .dsuik-up-badge{position:relative;top:-4px;min-width:15px;height:15px;padding:0 4px;box-sizing:border-box;border-radius:999px;display:inline-flex;align-items:center;justify-content:center;font-size:10px;font-weight:600;line-height:1;letter-spacing:0;font-variant-numeric:tabular-nums;color:var(--dsw-alias-state-business-primary);background:color-mix(in srgb, var(--dsw-alias-state-business-primary) 14%, transparent);}
3302
+ `
3303
+
3304
+ ctx.slots.inject('plugins.tab', function () {
3305
+ return ctx.slots.register(
3306
+ {
3307
+ name: 'plugins.tab',
3308
+ id: 'ui-optimize-updates',
3309
+ order: 100,
3310
+ label: function () {
3311
+ return h(
3312
+ 'span',
3313
+ { className: 'dsuik-up-tab' },
3314
+ translate('updates.tab'),
3315
+ h(UpdateBadge),
3316
+ )
3317
+ },
3318
+ },
3319
+ UpdatesTab,
3320
+ )
3321
+ })
3322
+
3323
+ /* The tab label renders outside the panel, so the badge styles cannot ride
3324
+ * on the panel's own markup — they have to be registered with the run. */
3325
+ ctx.effect(function () {
3326
+ const style = document.createElement('style')
3327
+ style.setAttribute('data-dsh-ui-optimize', 'updates')
3328
+ style.textContent = UPDATES_CSS
3329
+ document.head.appendChild(style)
3330
+ return function () {
3331
+ style.remove()
3332
+ }
3333
+ }, 'dsh-ui-optimize: update styles')
3334
+
3335
+ ctx.effect(function () {
3336
+ refreshUpdateBadge()
3337
+ })
3338
+
2005
3339
  ctx.slots.inject('settings.section', function () {
2006
3340
  return ctx.slots.register(
2007
3341
  {