@moonsand/dsh-ui-optimize 0.9.30 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +11 -3
  2. package/README.zh.md +11 -3
  3. package/client.js +1289 -32
  4. package/package.json +5 -2
package/client.js CHANGED
@@ -85,8 +85,56 @@ window.__ModuleLoader__.load({
85
85
  'desktop.restartSwitch': 'Show the Restart app button',
86
86
  'desktop.restartSwitchHint': 'Sidebar foot. Restarts the whole app including its Host; the current conversation is interrupted. Desktop app only',
87
87
  'desktop.restartNotDesktop': 'This is a browser session, so restart is unavailable — clicking it would only reload the page. The feature works only inside the desktop app.',
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.',
88
89
  'legacy.title': '@moonsand/dsh-desktop-restart is still installed',
89
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.updating': 'Updating…',
115
+ 'updates.none': 'Nothing to update.',
116
+ 'updates.upToDate': '{n} already up to date',
117
+ 'updates.fallbackWhy': 'The latest release is under 24 hours old, so this installs the newest release that is already old enough.',
118
+ 'updates.latestSoon': '{hours}h left',
119
+ 'updates.idle': 'Not checked yet.',
120
+ 'updates.unsupported': 'This host exposes no plugin manager, so updates cannot be checked here. Installed plugins still work.',
121
+ 'updates.registryDown': 'The npm registry did not answer, so the release dates are unknown. Public plugins stay listed as unchecked.',
122
+ 'updates.pmTimeout': 'The host plugin manager did not answer within {ms}s (remote={remote}).',
123
+ 'updates.pmWaiting': 'Waiting for the host plugin manager… (remote={remote})',
124
+ 'updates.pmStalled': 'Listing the installed plugins never answered (8s). Namespaces seen: {names}',
125
+ 'updates.loadFailed': 'The check failed',
126
+ 'updates.waiting': 'Published under a day ago — skipped until it is 24 hours old',
127
+ 'updates.unknownAge': 'Publish time could not be read — skipped, since the 24-hour rule cannot be confirmed',
128
+ 'updates.readingAge': 'Reading the publish time…',
129
+ 'updates.section.ready': 'Ready to update',
130
+ 'updates.section.waiting': 'Not yet',
131
+ 'updates.section.waitingHint': 'Published less than 24 hours ago.',
132
+ 'updates.queued': 'Queued',
133
+ 'updates.running': 'Updating',
134
+ 'updates.succeeded': 'Updated',
135
+ 'updates.failed': 'Failed',
136
+ 'updates.checked': 'installed plugins checked',
137
+ 'updates.reloadHint': 'Reload the page after a plugin update — the new client half only loads on a fresh page.',
90
138
  storageNote: 'Storage unavailable — the choice lasts until this page reloads.',
91
139
  },
92
140
  zh: {
@@ -142,8 +190,56 @@ window.__ModuleLoader__.load({
142
190
  'desktop.restartSwitch': '显示「重启应用」按钮',
143
191
  'desktop.restartSwitchHint': '侧栏底部。重启整个应用(含 Host),当前对话会中断;仅桌面端可用',
144
192
  'desktop.restartNotDesktop': '当前是网页端,重启不可用——点了只会刷新页面。此功能仅在桌面应用里有效。',
193
+ 'desktop.reloadNotDesktop': '当前是网页端,刷新按钮不提供——这个外壳已经自带刷新入口。此开关仅在桌面应用里可开。',
145
194
  'legacy.title': '检测到 @moonsand/dsh-desktop-restart 仍在安装',
146
195
  'legacy.body': '两个插件都会提供刷新/重启按钮,侧栏底部会出现两套。请到「设置 → 插件」卸载 dsh-desktop-restart,只保留本插件。',
196
+ 'updates.tab': '更新',
197
+ 'updates.title': '插件更新',
198
+ 'updates.sub': '一键更新所有「最新版发布满 24 小时」的已装插件;更年轻的版本先跳过——刚发几小时的版本还可能被撤回或补丁。',
199
+ 'section.updates': '更新',
200
+ 'updates.switch': '「更新」页签',
201
+ 'updates.switchHint': '在插件页加一个「更新」页签(一键更新 + 数量徽章)。关掉后本插件不再做任何更新检查。',
202
+ 'updates.fallbackSwitch': '退回次新版',
203
+ 'updates.fallbackSwitchHint': '最新版发布不足 24 小时时,改装「已经满一天的最新版本」,而不是干等。',
204
+ 'updates.fallbackTag': '次新版',
205
+ 'updates.off': '更新功能已关闭',
206
+ 'updates.offHint': '到「设置 → 界面优化」打开「更新页签」即可恢复。',
207
+ 'updates.check': '重新检查',
208
+ 'updates.checking': '检查中…',
209
+ 'updates.loadingDetail': '正在读取已装插件和它们的发布时间…',
210
+ 'updates.notesLoading': '正在读取更新说明…',
211
+ 'updates.notesEmpty': '这个版本没有更新说明。',
212
+ 'updates.notesRate': 'GitHub 的匿名请求被限流了,过几分钟再试。',
213
+ 'updates.notesFailed': '更新说明读取失败。',
214
+ 'updates.notesToggle': '展开或收起更新说明',
215
+ 'updates.notesNoZh': '这些版本没有中文更新说明。',
216
+ 'updates.notesNoZhVersion': '该版本没有中文说明。',
217
+ 'updates.notesSpan': '自 {from} 以来的改动',
218
+ 'updates.updateAll': '一键更新',
219
+ 'updates.updating': '更新中…',
220
+ 'updates.none': '没有可更新的插件。',
221
+ 'updates.upToDate': '其余 {n} 个已是最新版',
222
+ 'updates.fallbackWhy': '最新版发布不足 24 小时,这一版装的是已满 24 小时的最新版本。',
223
+ 'updates.latestSoon': '剩余 {hours} 小时',
224
+ 'updates.idle': '还没检查。',
225
+ 'updates.unsupported': '这台宿主没有可用的插件管理服务,所以这里查不了更新(已装插件不受影响)。',
226
+ 'updates.registryDown': 'npm registry 没有回应,读不到发布时间。公开插件暂时按「未检查」处理。',
227
+ 'updates.pmTimeout': '宿主的插件管理服务 {ms} 秒没有响应(remote={remote})。',
228
+ 'updates.pmWaiting': '正在等宿主插件管理服务应答…(remote={remote})',
229
+ 'updates.pmStalled': '读取已装插件 8 秒没有回应(看到的命名空间:{names})',
230
+ 'updates.loadFailed': '检查失败',
231
+ 'updates.waiting': '发布不足 24 小时 —— 等满一天再更新',
232
+ 'updates.unknownAge': '读不到发布时间 —— 无法确认是否满 24 小时,先跳过',
233
+ 'updates.readingAge': '正在读取发布时间…',
234
+ 'updates.section.ready': '可更新',
235
+ 'updates.section.waiting': '暂不可更新',
236
+ 'updates.section.waitingHint': '发布不足 24 小时',
237
+ 'updates.queued': '排队中',
238
+ 'updates.running': '更新中',
239
+ 'updates.succeeded': '已更新',
240
+ 'updates.failed': '失败',
241
+ 'updates.checked': '个已装插件已检查',
242
+ 'updates.reloadHint': '插件更新完成后刷新页面,新的客户端代码才会加载。',
147
243
  storageNote: '浏览器存储不可用——选择的主题只在本次页面加载内有效。',
148
244
  },
149
245
  }
@@ -401,7 +497,7 @@ window.__ModuleLoader__.load({
401
497
  * ------------------------------------------------------------------ */
402
498
 
403
499
  function defaultState() {
404
- return { version: 4, theme: null, reload: true, restart: true, sidebar: false }
500
+ return { version: 5, theme: null, reload: true, restart: true, sidebar: false, updates: true, updatesFallback: false }
405
501
  }
406
502
 
407
503
  function normalize(stored) {
@@ -413,6 +509,8 @@ window.__ModuleLoader__.load({
413
509
  if (typeof stored.reload === 'boolean') out.reload = stored.reload
414
510
  if (typeof stored.restart === 'boolean') out.restart = stored.restart
415
511
  if (typeof stored.sidebar === 'boolean') out.sidebar = stored.sidebar
512
+ if (typeof stored.updates === 'boolean') out.updates = stored.updates
513
+ if (typeof stored.updatesFallback === 'boolean') out.updatesFallback = stored.updatesFallback
416
514
  return out
417
515
  }
418
516
 
@@ -458,7 +556,10 @@ window.__ModuleLoader__.load({
458
556
  * each switch inventing its own check. */
459
557
  const FEATURES = {
460
558
  theme: { envs: ['desktop', 'web'] },
461
- reload: { envs: ['desktop', 'web'] },
559
+ /* The fnOS shell has its own reload and restart entries, so these two stay
560
+ * desktop-only: in a browser session they would duplicate what the shell
561
+ * already offers, and the switch must not be turnable on there. */
562
+ reload: { envs: ['desktop'], reason: 'desktop.reloadNotDesktop' },
462
563
  restart: { envs: ['desktop'], reason: 'desktop.restartNotDesktop' },
463
564
  sidebar: { envs: ['desktop', 'web'], reason: 'sidebar.unavailable' },
464
565
  }
@@ -506,7 +607,22 @@ window.__ModuleLoader__.load({
506
607
  if (value !== 'desktop' && value !== 'web') return
507
608
  if (store.env === value) return
508
609
  store.env = value
509
- store.notify()
610
+ /* Anything this shell cannot run is forced off the moment the probe
611
+ * answers: a `true` stored by a desktop session must not survive into a
612
+ * browser session, where `setFlag` refuses to turn the switch back on
613
+ * and the stored value would otherwise keep the button visible. */
614
+ const next = Object.assign({}, store.state, { version: 3 })
615
+ let dirty = false
616
+ const names = Object.keys(FEATURES)
617
+ for (let i = 0; i < names.length; i += 1) {
618
+ const name = names[i]
619
+ if (next[name] === true && !featureGate(name, value).available) {
620
+ next[name] = false
621
+ dirty = true
622
+ }
623
+ }
624
+ if (dirty) publish(next)
625
+ else store.notify()
510
626
  },
511
627
  setTheme(key) {
512
628
  publish(
@@ -722,6 +838,7 @@ body:not([data-ds-dark-theme]) .dsuik-mc > .dsuik-mc-b{display:none;}
722
838
  const [state, setState] = React.useState(store.state)
723
839
  const [legacyPresent, setLegacyPresent] = React.useState(false)
724
840
  const env = store.env
841
+ const reloadGate = featureGate('reload', env)
725
842
  const restartGate = featureGate('restart', env)
726
843
  /* The shelf also needs the slot API: without it the switch stays off and
727
844
  * says why, instead of offering something that cannot work. */
@@ -743,9 +860,7 @@ body:not([data-ds-dark-theme]) .dsuik-mc > .dsuik-mc-b{display:none;}
743
860
  let alive = true
744
861
  void readStatus().then(function (status) {
745
862
  if (!alive) return
746
- if (status && typeof status.desktop === 'boolean') {
747
- store.setEnv(status.desktop === true ? 'desktop' : 'web')
748
- }
863
+ store.setEnv(shellEnv(status))
749
864
  })
750
865
  return function () {
751
866
  alive = false
@@ -835,10 +950,18 @@ body:not([data-ds-dark-theme]) .dsuik-mc > .dsuik-mc-b{display:none;}
835
950
  'div',
836
951
  { className: 'dsuik-rowtext' },
837
952
  h('span', { className: 'dsuik-rowname' }, translate('desktop.reloadSwitch')),
838
- h('span', { className: 'dsuik-rowhint' }, translate('desktop.reloadSwitchHint')),
953
+ h(
954
+ 'span',
955
+ { className: 'dsuik-rowhint' + (reloadGate.available ? '' : ' is-warn') },
956
+ reloadGate.available
957
+ ? translate('desktop.reloadSwitchHint')
958
+ : reloadGate.reason,
959
+ ),
839
960
  ),
840
961
  h(Switch, {
841
962
  checked: state.reload === true,
963
+ disabled: !reloadGate.available,
964
+ title: reloadGate.reason,
842
965
  label: translate('desktop.reloadSwitch'),
843
966
  onChange: function (next) {
844
967
  store.setFlag('reload', next)
@@ -901,6 +1024,49 @@ body:not([data-ds-dark-theme]) .dsuik-mc > .dsuik-mc-b{display:none;}
901
1024
  }),
902
1025
  ),
903
1026
  ),
1027
+ h(
1028
+ 'div',
1029
+ { className: 'dsuik-section' },
1030
+ h('p', { className: 'dsuik-sectiontitle' }, translate('section.updates')),
1031
+ h(
1032
+ 'div',
1033
+ { className: 'dsuik-row' },
1034
+ h(
1035
+ 'div',
1036
+ { className: 'dsuik-rowtext' },
1037
+ h('span', { className: 'dsuik-rowname' }, translate('updates.switch')),
1038
+ h('span', { className: 'dsuik-rowhint' }, translate('updates.switchHint')),
1039
+ ),
1040
+ h(Switch, {
1041
+ checked: state.updates !== false,
1042
+ label: translate('updates.switch'),
1043
+ onChange: function (next) {
1044
+ store.setFlag('updates', next)
1045
+ if (!next) updateBadge.set(0)
1046
+ else refreshUpdateBadge()
1047
+ },
1048
+ }),
1049
+ ),
1050
+ h(
1051
+ 'div',
1052
+ { className: 'dsuik-row' },
1053
+ h(
1054
+ 'div',
1055
+ { className: 'dsuik-rowtext' },
1056
+ h('span', { className: 'dsuik-rowname' }, translate('updates.fallbackSwitch')),
1057
+ h('span', { className: 'dsuik-rowhint' }, translate('updates.fallbackSwitchHint')),
1058
+ ),
1059
+ h(Switch, {
1060
+ checked: state.updatesFallback === true,
1061
+ disabled: state.updates === false,
1062
+ label: translate('updates.fallbackSwitch'),
1063
+ onChange: function (next) {
1064
+ store.setFlag('updatesFallback', next)
1065
+ if (state.updates !== false) refreshUpdateBadge()
1066
+ },
1067
+ }),
1068
+ ),
1069
+ ),
904
1070
  surface.controller && !surface.controller.active()
905
1071
  ? h(
906
1072
  'p',
@@ -1035,20 +1201,52 @@ body:not([data-ds-dark-theme]) .dsuik-mc > .dsuik-mc-b{display:none;}
1035
1201
  )
1036
1202
  }
1037
1203
 
1204
+ /* The Host route lives on the DSH web server, but a shell may serve the page
1205
+ * under a path prefix and answer every other path with a text body (fnOS
1206
+ * answers `invalid token` with HTTP 200) — so a successful status still has
1207
+ * to be JSON carrying `desktop` before it counts. Try the page-relative URL
1208
+ * first, then the root. */
1038
1209
  async function readStatus() {
1210
+ const candidates = []
1039
1211
  try {
1040
- const response = await fetch('/ui-optimize/desktop/status', {
1041
- method: 'GET',
1042
- headers: { accept: 'application/json' },
1043
- credentials: 'same-origin',
1044
- cache: 'no-store',
1045
- signal: AbortSignal.timeout(6000),
1046
- })
1047
- if (!response.ok) return undefined
1048
- return await response.json()
1212
+ candidates.push(new URL('ui-optimize/desktop/status', document.baseURI).href)
1049
1213
  } catch (err) {
1050
- return undefined
1214
+ /* malformed baseURI: fall through to the root-relative URL */
1215
+ }
1216
+ candidates.push('/ui-optimize/desktop/status')
1217
+ for (let i = 0; i < candidates.length; i += 1) {
1218
+ try {
1219
+ const response = await fetch(candidates[i], {
1220
+ method: 'GET',
1221
+ headers: { accept: 'application/json' },
1222
+ credentials: 'same-origin',
1223
+ cache: 'no-store',
1224
+ signal: AbortSignal.timeout(6000),
1225
+ })
1226
+ if (!response.ok) continue
1227
+ const data = await response.json()
1228
+ if (data && typeof data.desktop === 'boolean') return data
1229
+ } catch (err) {
1230
+ /* try the next candidate */
1231
+ }
1051
1232
  }
1233
+ return undefined
1234
+ }
1235
+
1236
+ /* Which shell this is. The Host probe is authoritative. When it cannot be
1237
+ * read at all, the user agent still separates the Electron desktop app from
1238
+ * any browser, and anything unrecognised counts as web: a browser session
1239
+ * must never be offered a button it cannot honour. */
1240
+ function shellEnv(status) {
1241
+ if (status && typeof status.desktop === 'boolean') {
1242
+ return status.desktop === true ? 'desktop' : 'web'
1243
+ }
1244
+ try {
1245
+ if (/electron/i.test(navigator.userAgent || '')) return 'desktop'
1246
+ } catch (err) {
1247
+ /* no navigator: treat as web */
1248
+ }
1249
+ return 'web'
1052
1250
  }
1053
1251
 
1054
1252
  /**
@@ -1305,21 +1503,19 @@ body:not([data-ds-dark-theme]) .dsuik-mc > .dsuik-mc-b{display:none;}
1305
1503
  })
1306
1504
  }, [])
1307
1505
  const wide = props.wide !== false
1308
- const showReload = state.reload === true
1309
- const showRestart = state.restart === true
1506
+ const reloadGate = featureGate('reload', store.env)
1310
1507
  const restartGate = featureGate('restart', store.env)
1508
+ /* The stored preference and the shell's ability are two different things:
1509
+ * a browser session must not draw a button it cannot honour, whatever the
1510
+ * preference says. */
1511
+ const showReload = state.reload === true && reloadGate.available
1512
+ const showRestart = state.restart === true && restartGate.available
1311
1513
  if (!showReload && !showRestart) return null
1312
1514
  return h(
1313
1515
  'div',
1314
1516
  { className: 'dsuik-dsr-group' },
1315
1517
  showReload ? h(RefreshButton, { wide: wide }) : null,
1316
- showRestart
1317
- ? h(RestartButton, {
1318
- wide: wide,
1319
- unavailable: !restartGate.available,
1320
- reason: restartGate.reason,
1321
- })
1322
- : null,
1518
+ showRestart ? h(RestartButton, { wide: wide }) : null,
1323
1519
  )
1324
1520
  }
1325
1521
 
@@ -1679,8 +1875,13 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
1679
1875
  function openMore() {
1680
1876
  const button = moreRef.current
1681
1877
  if (!button) return
1682
- const x = pos ? pos.left : 12
1683
- const y = pos ? pos.top : 120
1878
+ /* Measure the row right now. The cached `pos` is computed when the card
1879
+ * opens and goes stale as soon as the sidebar re-lays out (collapse,
1880
+ * resize, a panel switching tabs) — which parked the shell menu in the
1881
+ * corner, outside the panel, until a reload. */
1882
+ const rect = button.getBoundingClientRect()
1883
+ const x = rect.width > 0 ? rect.left : (pos ? pos.left : 12)
1884
+ const y = rect.width > 0 ? rect.bottom : (pos ? pos.top : 120)
1684
1885
  try {
1685
1886
  const style = document.documentElement.style
1686
1887
  style.setProperty('--muik-more-x', x + 'px')
@@ -1808,7 +2009,9 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
1808
2009
  * ------------------------------------------------------------------ */
1809
2010
 
1810
2011
  return {
1811
- inject: ['slots'],
2012
+ /* `remote` is the Host's plugin-manager bridge; cordis refuses to hand out
2013
+ * `ctx.remote` at all unless the plugin declares it here first. */
2014
+ inject: ['slots', 'remote', 'remote.pluginManager'],
1812
2015
  apply(ctx) {
1813
2016
  try {
1814
2017
  const locale = typeof ctx.get === 'function' ? ctx.get('locale') : undefined
@@ -1838,9 +2041,7 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
1838
2041
  let alive = true
1839
2042
  void readStatus().then(function (status) {
1840
2043
  if (!alive) return
1841
- if (status && typeof status.desktop === 'boolean') {
1842
- store.setEnv(status.desktop === true ? 'desktop' : 'web')
1843
- }
2044
+ store.setEnv(shellEnv(status))
1844
2045
  })
1845
2046
  return function () {
1846
2047
  alive = false
@@ -1947,6 +2148,1062 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
1947
2148
  })
1948
2149
  }
1949
2150
 
2151
+ /* ------------------------------------------------------------------ *
2152
+ * Updates tab
2153
+ *
2154
+ * The official plugin page exposes exactly one slot we can use without
2155
+ * touching its DOM: `plugins.tab`. Everything in it talks to the market's
2156
+ * public update API (v1) rather than driving pnpm ourselves, so the market
2157
+ * keeps ownership of installs, rollbacks and its fresh-release wait — and
2158
+ * a host without that market simply reports that it cannot check here.
2159
+ * ------------------------------------------------------------------ */
2160
+
2161
+ const FRESH_RELEASE_MS = 24 * 60 * 60 * 1000
2162
+ const UPDATE_REGISTRY = 'https://registry.npmjs.org/'
2163
+
2164
+ /* Everything this tab needs comes from two sources that exist on every
2165
+ * host: the Host's own plugin manager (what is installed) and the npm
2166
+ * registry (what exists and how old it is). No marketplace plugin is
2167
+ * involved, so it keeps working when dshmarket is absent. */
2168
+ function pluginManager() {
2169
+ const remote = ctx.remote || (typeof ctx.get === 'function' ? ctx.get('remote') : null)
2170
+ const pm = remote && remote.pluginManager
2171
+ return pm && typeof pm.listBundles === 'function' ? pm : null
2172
+ }
2173
+
2174
+ /* Which remote namespaces the page actually got. Printed in the failure
2175
+ * text so a missing or renamed namespace is visible without DevTools. */
2176
+ function remoteNamespaces() {
2177
+ try {
2178
+ const remote = ctx.remote || (typeof ctx.get === 'function' ? ctx.get('remote') : null)
2179
+ if (!remote) return 'none'
2180
+ const keys = Object.keys(remote)
2181
+ if (keys.length === 0) return 'empty'
2182
+ return keys.slice(0, 10).join('|')
2183
+ } catch (err) {
2184
+ return 'error'
2185
+ }
2186
+ }
2187
+
2188
+ function withTimeout(promise, ms) {
2189
+ return new Promise(function (resolve) {
2190
+ const timer = setTimeout(function () {
2191
+ resolve({ timedOut: true })
2192
+ }, ms)
2193
+ Promise.resolve(promise).then(
2194
+ function (value) {
2195
+ clearTimeout(timer)
2196
+ resolve({ timedOut: false, value: value })
2197
+ },
2198
+ function (error) {
2199
+ clearTimeout(timer)
2200
+ resolve({ timedOut: false, error: error })
2201
+ }
2202
+ )
2203
+ })
2204
+ }
2205
+
2206
+ function failureMessage(error) {
2207
+ if (!error) return ''
2208
+ if (typeof error === 'string') return error
2209
+ return String(error.message || error.code || error.kind || '')
2210
+ }
2211
+
2212
+ /* The market tells us which releases are due; only the registry can tell us
2213
+ * how old the newest one is, and the age is the user's actual rule here. */
2214
+ /* "Second newest" for the fallback switch: the highest release at or below
2215
+ * `version` that is already past the 24-hour rule. */
2216
+ function previousMatureVersion(time, version) {
2217
+ if (!time || typeof time !== 'object') return null
2218
+ const names = Object.keys(time)
2219
+ let best = null
2220
+ for (let i = 0; i < names.length; i += 1) {
2221
+ const name = names[i]
2222
+ if (name === 'created' || name === 'modified' || !time[name]) continue
2223
+ if (compareVersions(name, version) >= 0) continue
2224
+ const stamp = Date.parse(time[name])
2225
+ if (!Number.isFinite(stamp)) continue
2226
+ const age = Date.now() - stamp
2227
+ if (age < FRESH_RELEASE_MS) continue
2228
+ if (best === null || compareVersions(name, best.version) > 0) best = { version: name, age: age }
2229
+ }
2230
+ return best
2231
+ }
2232
+
2233
+ const REGISTRY_TIMEOUT_MS = 8000
2234
+ const REGISTRY_CONCURRENCY = 4
2235
+
2236
+ async function readRegistry(name) {
2237
+ const controller = typeof AbortController === 'function' ? new AbortController() : null
2238
+ const timer = controller
2239
+ ? setTimeout(function () {
2240
+ controller.abort()
2241
+ }, REGISTRY_TIMEOUT_MS)
2242
+ : null
2243
+ try {
2244
+ const path = encodeURIComponent(name).replace(/^%40/, '@')
2245
+ const res = await fetch(UPDATE_REGISTRY + path, {
2246
+ /* The abbreviated (install-v1) document has no `time` table at all,
2247
+ * so asking for it first meant every package looked undated. */
2248
+ headers: { accept: 'application/json' },
2249
+ signal: controller ? controller.signal : undefined,
2250
+ })
2251
+ if (!res.ok) return null
2252
+ const doc = await res.json()
2253
+ const time = (doc && doc.time) || {}
2254
+ const tags = (doc && doc['dist-tags']) || {}
2255
+ return {
2256
+ latest: typeof tags.latest === 'string' ? tags.latest : '',
2257
+ time: time,
2258
+ repo: readRepo(doc),
2259
+ }
2260
+ } catch (err) {
2261
+ return null
2262
+ } finally {
2263
+ if (timer) clearTimeout(timer)
2264
+ }
2265
+ }
2266
+
2267
+ /* Whether the running DSH version accepts this exact release. The Host
2268
+ * answers authoritatively: `listVersions` marks a version `incompatible`
2269
+ * when its `engines.dsh` (or a DSH peer) rejects the running build, and
2270
+ * it already honours `compatibility.json` exemptions. */
2271
+ async function readCompat(pm, name, version) {
2272
+ try {
2273
+ const answer = await withTimeout(pm.listVersions(name), 8000)
2274
+ if (!answer || answer.timedOut || answer.error !== undefined) return null
2275
+ const result = answer.value
2276
+ if (!result || result.ok !== true) return null
2277
+ const value = result.value
2278
+ if (!value || value.status !== 'listed' || !Array.isArray(value.versions)) return null
2279
+ const hit = value.versions.find(function (entry) {
2280
+ return entry && entry.version === version
2281
+ })
2282
+ if (!hit || !hit.incompatible) return null
2283
+ const requirements = hit.incompatible.requirements || {}
2284
+ const listed = Object.keys(requirements).map(function (key) {
2285
+ return key + ' ' + requirements[key]
2286
+ })
2287
+ return {
2288
+ runtime: hit.incompatible.runtimeVersion || '',
2289
+ required: requirements['engines.dsh'] || listed.join(', '),
2290
+ }
2291
+ } catch (err) {
2292
+ return null
2293
+ }
2294
+ }
2295
+
2296
+ /* One scan, one truth: which installed plugins have a newer release, how
2297
+ * old that release is, and what the fallback would be. The list, the
2298
+ * section split, the count and the badge all derive from this. */
2299
+ async function collectUpdates(onRow) {
2300
+ const pm = pluginManager()
2301
+ if (!pm) return { supported: false, checked: 0, rows: [] }
2302
+ let listed = null
2303
+ const answer = await withTimeout(pm.listBundles(), 8000)
2304
+ if (answer.timedOut) {
2305
+ return { supported: false, checked: 0, rows: [], stalled: 'listBundles', names: remoteNamespaces() }
2306
+ }
2307
+ if (answer.error !== undefined) return { supported: false, checked: 0, rows: [] }
2308
+ listed = answer.value
2309
+ if (!listed || listed.ok !== true) return { supported: false, checked: 0, rows: [] }
2310
+ const installed = (listed.value || []).filter(function (item) {
2311
+ return item && item.installed === true
2312
+ })
2313
+ /* `updatable` is the Host's own verdict: a registry dependency saved
2314
+ * under its own name with a semver version. Links and local paths are
2315
+ * excluded for us — updating those would overwrite the checkout. */
2316
+ const candidates = installed.filter(function (item) {
2317
+ return item.updatable === true && typeof item.version === 'string' && item.version !== ''
2318
+ })
2319
+ const found = []
2320
+ const stats = { tried: 0, failed: 0 }
2321
+ let cursor = 0
2322
+ /* Four at a time: the public registry throttles a burst of thirty, and
2323
+ * one stalled request used to hold the whole panel in "loading". */
2324
+ async function worker() {
2325
+ while (cursor < candidates.length) {
2326
+ const item = candidates[cursor]
2327
+ cursor += 1
2328
+ stats.tried += 1
2329
+ const doc = await readRegistry(item.name)
2330
+ if (!doc || !doc.latest) {
2331
+ stats.failed += 1
2332
+ continue
2333
+ }
2334
+ if (compareVersions(doc.latest, item.version) <= 0) continue
2335
+ const published = doc.time[doc.latest]
2336
+ const stamp = published === undefined ? NaN : Date.parse(published)
2337
+ const age = Number.isFinite(stamp) ? Date.now() - stamp : null
2338
+ const fallback = previousMatureVersion(doc.time, doc.latest)
2339
+ const compat = await readCompat(pm, item.name, doc.latest)
2340
+ const row = {
2341
+ compat: compat,
2342
+ name: item.name,
2343
+ installed: item.version,
2344
+ latest: doc.latest,
2345
+ age: age,
2346
+ repo: doc.repo,
2347
+ fallbackVersion: fallback ? fallback.version : '',
2348
+ fallbackAge: fallback ? fallback.age : null,
2349
+ state: 'idle',
2350
+ percent: 0,
2351
+ detail: '',
2352
+ }
2353
+ found.push(row)
2354
+ if (typeof onRow === 'function') onRow(row)
2355
+ }
2356
+ }
2357
+ const lanes = []
2358
+ for (let i = 0; i < Math.min(REGISTRY_CONCURRENCY, candidates.length); i += 1) lanes.push(worker())
2359
+ await Promise.all(lanes)
2360
+ found.sort(function (a, b) {
2361
+ return a.name.localeCompare(b.name)
2362
+ })
2363
+ return { supported: true, checked: installed.length, rows: found, stats: stats }
2364
+ }
2365
+
2366
+ /* The packument's repository field is the only place that knows where the
2367
+ * changelog lives, so it travels with the age read. */
2368
+ function readRepo(doc) {
2369
+ const raw = doc && (doc.repository && (doc.repository.url || doc.repository))
2370
+ if (typeof raw !== 'string') return ''
2371
+ const hit = raw.match(/github\.com[:/]+([^/]+)\/([^/#?]+)/i)
2372
+ if (!hit) return ''
2373
+ return hit[1] + '/' + hit[2].replace(/\.git$/i, '')
2374
+ }
2375
+
2376
+ /* Panels remount on every tab switch, so the parsed notes survive in a
2377
+ * module-level map: the second open is instant, not another 2-3s round trip. */
2378
+ const changelogCache = new Map()
2379
+
2380
+ /* Loose semver compare: enough to tell 1.10.0 from 1.9.4 and to bound the
2381
+ * range of versions a single click should explain. */
2382
+ function versionParts(text) {
2383
+ return String(text || '')
2384
+ .replace(/^v/i, '')
2385
+ .split(/[.\-+]/)
2386
+ .map(function (piece) {
2387
+ const n = parseInt(piece, 10)
2388
+ return Number.isFinite(n) ? n : 0
2389
+ })
2390
+ }
2391
+
2392
+ function compareVersions(a, b) {
2393
+ const left = versionParts(a)
2394
+ const right = versionParts(b)
2395
+ const size = Math.max(left.length, right.length)
2396
+ for (let i = 0; i < size; i += 1) {
2397
+ const diff = (left[i] || 0) - (right[i] || 0)
2398
+ if (diff !== 0) return diff > 0 ? 1 : -1
2399
+ }
2400
+ return 0
2401
+ }
2402
+
2403
+ /* Cross-version updates deserve cross-version notes, so the whole release
2404
+ * list is read once and then narrowed to (installed, latest]. */
2405
+ async function readChangelog(repo, upperBound, installed) {
2406
+ if (!repo) return { state: 'empty' }
2407
+ const cacheKey = repo + '|' + String(installed || '') + '|' + String(upperBound || '')
2408
+ if (changelogCache.has(cacheKey)) return changelogCache.get(cacheKey)
2409
+ const base = 'https://api.github.com/repos/' + repo
2410
+ let res
2411
+ try {
2412
+ res = await fetch(base + '/releases?per_page=60', {
2413
+ headers: { accept: 'application/vnd.github+json' },
2414
+ })
2415
+ } catch (err) {
2416
+ return { state: 'failed' }
2417
+ }
2418
+ if (res.status === 403) return { state: 'rate' }
2419
+ if (!res.ok) return { state: 'failed' }
2420
+ const list = await res.json().catch(function () {
2421
+ return null
2422
+ })
2423
+ if (!Array.isArray(list)) return { state: 'failed' }
2424
+
2425
+ const releases = list
2426
+ .filter(function (item) {
2427
+ return item && !item.draft && typeof item.body === 'string' && item.body.trim() !== ''
2428
+ })
2429
+ .map(function (item) {
2430
+ return {
2431
+ version: String(item.tag_name || item.name || '').replace(/^v/i, ''),
2432
+ body: String(item.body || ''),
2433
+ }
2434
+ })
2435
+ .filter(function (item) {
2436
+ return item.version !== ''
2437
+ })
2438
+ .sort(function (a, b) {
2439
+ return compareVersions(b.version, a.version)
2440
+ })
2441
+
2442
+ const upper = String(upperBound || '')
2443
+ const lower = String(installed || '')
2444
+ let picked = releases.filter(function (item) {
2445
+ if (compareVersions(item.version, upper) > 0) return false
2446
+ if (lower && compareVersions(item.version, lower) <= 0) return false
2447
+ return true
2448
+ })
2449
+ if (picked.length === 0) {
2450
+ picked = releases.filter(function (item) {
2451
+ return compareVersions(item.version, upper) === 0
2452
+ })
2453
+ }
2454
+ /* A long gap could mean twenty releases; the newest eight is plenty. */
2455
+ const result = picked.length === 0
2456
+ ? { state: 'empty' }
2457
+ : { state: 'ready', groups: picked.slice(0, 8).map(function (item) { return item }) }
2458
+ changelogCache.set(cacheKey, result)
2459
+ return result
2460
+ }
2461
+
2462
+ /* The notes are shown in Chinese, so drop the blocks that carry no CJK at
2463
+ * all and keep everything else in its original order. */
2464
+ function chineseBlocks(text) {
2465
+ const cjk = /[\u3400-\u9fff\u3000-\u303f\uff00-\uffef]/
2466
+ return String(text || '')
2467
+ .split(/\r?\n/)
2468
+ .filter(function (line) {
2469
+ return cjk.test(line)
2470
+ })
2471
+ }
2472
+
2473
+ /* A deliberately tiny Markdown reader: headings, list items, bold, inline
2474
+ * code and links — enough for release notes, small enough to stay here. */
2475
+ function renderInline(text, keyPrefix) {
2476
+ const out = []
2477
+ const pattern = /(\*\*[^*]+\*\*|`[^`]+`|\[[^\]]+\]\([^)]+\))/g
2478
+ let cursor = 0
2479
+ let match = pattern.exec(text)
2480
+ let index = 0
2481
+ while (match) {
2482
+ if (match.index > cursor) out.push(text.slice(cursor, match.index))
2483
+ const token = match[0]
2484
+ index += 1
2485
+ if (token.startsWith('**')) {
2486
+ out.push(h('strong', { key: keyPrefix + '-b' + String(index) }, token.slice(2, -2)))
2487
+ } else if (token.startsWith('`')) {
2488
+ out.push(h('code', { key: keyPrefix + '-c' + String(index) }, token.slice(1, -1)))
2489
+ } else {
2490
+ const label = token.slice(1, token.indexOf(']'))
2491
+ out.push(h('span', { key: keyPrefix + '-l' + String(index), className: 'dsuik-up-link' }, label))
2492
+ }
2493
+ cursor = match.index + token.length
2494
+ match = pattern.exec(text)
2495
+ }
2496
+ if (cursor < text.length) out.push(text.slice(cursor))
2497
+ return out
2498
+ }
2499
+
2500
+ function renderNotes(text, keyPrefix) {
2501
+ const lines = chineseBlocks(text)
2502
+ const nodes = []
2503
+ lines.forEach(function (line, index) {
2504
+ const trimmed = line.trim()
2505
+ if (trimmed === '') return
2506
+ const key = keyPrefix + '-' + String(index)
2507
+ const heading = trimmed.match(/^#{1,6}\s+(.*)$/)
2508
+ const bullet = trimmed.match(/^[-*+]\s+(.*)$/)
2509
+ const ordered = trimmed.match(/^\d+[.)]\s+(.*)$/)
2510
+ if (heading) {
2511
+ nodes.push(h('p', { key: key, className: 'dsuik-up-h' }, renderInline(heading[1], key)))
2512
+ } else if (bullet) {
2513
+ nodes.push(h('p', { key: key, className: 'dsuik-up-li' }, '· ', renderInline(bullet[1], key)))
2514
+ } else if (ordered) {
2515
+ nodes.push(h('p', { key: key, className: 'dsuik-up-li' }, trimmed.slice(0, trimmed.indexOf(' ')) + ' ', renderInline(ordered[1], key)))
2516
+ } else {
2517
+ nodes.push(h('p', { key: key, className: 'dsuik-up-p' }, renderInline(trimmed, key)))
2518
+ }
2519
+ })
2520
+ return nodes
2521
+ }
2522
+
2523
+ /* The Host runs the install itself: same guard rails as its own plugin
2524
+ * page (running agents block it), and it reports `restart-required` when
2525
+ * the change only lands at the next start. */
2526
+ async function runUpdate(name, target, onProgress) {
2527
+ const pm = pluginManager()
2528
+ if (!pm) throw new Error('the plugin manager is unavailable')
2529
+ if (typeof onProgress === 'function') {
2530
+ onProgress({ state: 'running', progress: { percent: null, detail: '' } })
2531
+ }
2532
+ const requestId = 'ui-optimize-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 7)
2533
+ const answer = await pm.updateBundle(name, target.version, { requestId: requestId })
2534
+ if (!answer || answer.ok !== true) {
2535
+ return {
2536
+ state: 'failed',
2537
+ failure: { code: 'UPDATE_REJECTED', message: failureMessage(answer && answer.error) },
2538
+ }
2539
+ }
2540
+ const update = answer.value || {}
2541
+ const change = update.result || {}
2542
+ if (change.application === 'cancelled') return { state: 'cancelled' }
2543
+ if (change.application === 'failed' || change.application === 'overridden') {
2544
+ return {
2545
+ state: 'failed',
2546
+ failure: {
2547
+ code: 'UPDATE_REJECTED',
2548
+ message: failureMessage(change.error) || change.application,
2549
+ },
2550
+ }
2551
+ }
2552
+ return {
2553
+ state: 'succeeded',
2554
+ installedVersion: update.to || target.version,
2555
+ restartRequired: change.application === 'restart-required',
2556
+ }
2557
+ }
2558
+
2559
+ function spinIcon(size) {
2560
+ const px = size || 13
2561
+ return h('svg', {
2562
+ className: 'dsuik-up-spin',
2563
+ viewBox: '0 0 16 16',
2564
+ width: px,
2565
+ height: px,
2566
+ 'aria-hidden': 'true',
2567
+ },
2568
+ h('circle', {
2569
+ cx: 8, cy: 8, r: 6,
2570
+ fill: 'none',
2571
+ stroke: 'currentColor',
2572
+ 'stroke-width': 2,
2573
+ 'stroke-linecap': 'round',
2574
+ 'stroke-dasharray': '26 12',
2575
+ }))
2576
+ }
2577
+
2578
+ function updateLabel(row) {
2579
+ if (row.state === 'running') return translate('updates.running')
2580
+ if (row.state === 'succeeded') return translate('updates.succeeded')
2581
+ if (row.state === 'failed') return translate('updates.failed')
2582
+ if (row.age === undefined) return translate('updates.readingAge')
2583
+ if (row.age === null) return translate('updates.unknownAge')
2584
+ if (row.age < FRESH_RELEASE_MS) return translate('updates.waiting')
2585
+ return ''
2586
+ }
2587
+
2588
+ /* The badge sits in the tab strip, outside this panel, so the count is kept
2589
+ * in a tiny module store: the label subscribes, the panel publishes. */
2590
+ const updateBadge = {
2591
+ count: 0,
2592
+ listeners: new Set(),
2593
+ set: function (next) {
2594
+ if (next === updateBadge.count) return
2595
+ updateBadge.count = next
2596
+ updateBadge.listeners.forEach(function (listener) {
2597
+ listener()
2598
+ })
2599
+ },
2600
+ }
2601
+
2602
+ let badgeScan = null
2603
+ /* One scan at start-up keeps the badge right before the tab is ever opened.
2604
+ * Same 24h rule as the panel, and the same "no age, not eligible" stance. */
2605
+ function refreshUpdateBadge() {
2606
+ if (store.state.updates === false) {
2607
+ updateBadge.set(0)
2608
+ return Promise.resolve(0)
2609
+ }
2610
+ if (badgeScan) return badgeScan
2611
+ badgeScan = (async function () {
2612
+ try {
2613
+ const scan = await collectUpdates()
2614
+ const fallbackOn = store.state.updatesFallback === true
2615
+ /* Same rule as the list: a fallback row counts only when the
2616
+ * previous release is actually newer than what is installed. */
2617
+ updateBadge.set(
2618
+ scan.rows.filter(function (row) {
2619
+ if (typeof row.age === 'number' && row.age >= FRESH_RELEASE_MS) return true
2620
+ if (!fallbackOn || !row.fallbackVersion) return false
2621
+ return compareVersions(row.fallbackVersion, row.installed) > 0
2622
+ }).length,
2623
+ )
2624
+ } catch (error) {
2625
+ updateBadge.set(0)
2626
+ }
2627
+ return updateBadge.count
2628
+ })()
2629
+ const settled = badgeScan.finally(function () {
2630
+ /* Release the guard: the badge has to be recomputable after an update,
2631
+ * a settings change, or a manual re-check. Keeping it cached forever
2632
+ * froze the number at its first scan. */
2633
+ badgeScan = null
2634
+ })
2635
+ badgeScan = settled
2636
+ return settled
2637
+ }
2638
+
2639
+ function useUpdateBadge() {
2640
+ const [count, setCount] = React.useState(updateBadge.count)
2641
+ React.useEffect(function () {
2642
+ function sync() {
2643
+ setCount(updateBadge.count)
2644
+ }
2645
+ updateBadge.listeners.add(sync)
2646
+ sync()
2647
+ return function () {
2648
+ updateBadge.listeners.delete(sync)
2649
+ }
2650
+ }, [])
2651
+ return count
2652
+ }
2653
+
2654
+ function UpdateBadge() {
2655
+ const count = useUpdateBadge()
2656
+ if (count <= 0) return null
2657
+ return h('span', { className: 'dsuik-up-badge' }, String(count))
2658
+ }
2659
+
2660
+ function UpdatesTab() {
2661
+ const [phase, setPhase] = React.useState('loading')
2662
+ /* Mirror of `phase` for timers: reading a ref avoids calling one
2663
+ * setState from inside another setState's updater, which throws. */
2664
+ const phaseRef = React.useRef('loading')
2665
+ function setPhaseSafe(next) {
2666
+ phaseRef.current = next
2667
+ setPhase(next)
2668
+ }
2669
+ const [rows, setRows] = React.useState([])
2670
+ const [checked, setChecked] = React.useState(0)
2671
+ const [message, setMessage] = React.useState('')
2672
+ const [busy, setBusy] = React.useState(false)
2673
+ const [open, setOpen] = React.useState({})
2674
+ const [notes, setNotes] = React.useState({})
2675
+ const [settings, setSettings] = React.useState(store.state)
2676
+ const [clock, setClock] = React.useState(0)
2677
+ const alive = React.useRef(true)
2678
+ const fallbackOn = settings.updatesFallback === true
2679
+
2680
+ React.useEffect(function () {
2681
+ return store.subscribe(function () {
2682
+ setSettings(store.state)
2683
+ })
2684
+ }, [])
2685
+
2686
+ React.useEffect(function () {
2687
+ alive.current = true
2688
+ /* Ticks once a second so a frozen main thread is visible on screen:
2689
+ * if this number stops moving, React is not re-rendering at all. */
2690
+ const ticker = setInterval(function () {
2691
+ if (phaseRef.current !== 'loading') return
2692
+ setClock(function (value) { return value + 1 })
2693
+ }, 1000)
2694
+ load().catch(function (err) {
2695
+ if (!alive.current) return
2696
+ phaseRef.current = 'error'
2697
+ setMessage('load() threw: ' + String((err && err.message) || err))
2698
+ setPhaseSafe('error')
2699
+ })
2700
+ return function () {
2701
+ alive.current = false
2702
+ clearInterval(ticker)
2703
+ }
2704
+ }, [])
2705
+
2706
+ function patch(name, changes) {
2707
+ if (!alive.current) return
2708
+ setRows(function (previous) {
2709
+ return previous.map(function (row) {
2710
+ return row.name === name ? Object.assign({}, row, changes) : row
2711
+ })
2712
+ })
2713
+ }
2714
+
2715
+ async function load() {
2716
+ if (store.state.updates === false) {
2717
+ setPhaseSafe('off')
2718
+ return
2719
+ }
2720
+ phaseRef.current = 'loading'
2721
+ setPhaseSafe('loading')
2722
+ setMessage('')
2723
+ setRows([])
2724
+ /* Rows appear as their registry answers arrive, so a slow package
2725
+ * never leaves the panel empty. */
2726
+ const scan = await collectUpdates(function (row) {
2727
+ if (!alive.current) return
2728
+ phaseRef.current = 'ready'
2729
+ setPhaseSafe('ready')
2730
+ setRows(function (previous) {
2731
+ const next = previous.filter(function (item) {
2732
+ return item.name !== row.name
2733
+ })
2734
+ next.push(row)
2735
+ next.sort(function (a, b) {
2736
+ return a.name.localeCompare(b.name)
2737
+ })
2738
+ return next
2739
+ })
2740
+ })
2741
+ if (!alive.current) return
2742
+ if (scan.supported === false) {
2743
+ if (scan.stalled === 'listBundles') {
2744
+ phaseRef.current = 'error'
2745
+ setPhaseSafe('error')
2746
+ setMessage(
2747
+ translate('updates.pmStalled')
2748
+ .replace('{names}', String(scan.names || 'none'))
2749
+ )
2750
+ return
2751
+ }
2752
+ setPhaseSafe('unsupported')
2753
+ return
2754
+ }
2755
+ setChecked(scan.checked)
2756
+ setMessage('')
2757
+ phaseRef.current = 'ready'
2758
+ if (scan.rows.length === 0 && scan.stats && scan.stats.tried > 0 && scan.stats.failed === scan.stats.tried) {
2759
+ /* The registry never answered: say so instead of claiming the
2760
+ * machine is fully up to date. */
2761
+ setPhaseSafe('error')
2762
+ setMessage(translate('updates.registryDown'))
2763
+ return
2764
+ }
2765
+ setPhaseSafe('ready')
2766
+ }
2767
+
2768
+ /* What this row would install, or null when the 24-hour rule (and the
2769
+ * optional fallback) leaves nothing safe to install. */
2770
+ function targetOf(row) {
2771
+ /* A release the running DSH cannot load is not an update target. */
2772
+ if (row.compat) return null
2773
+ if (typeof row.age === 'number' && row.age >= FRESH_RELEASE_MS) {
2774
+ return { version: row.latest, fallback: false }
2775
+ }
2776
+ /* The previous release is only useful when it is actually newer than
2777
+ * what is installed — otherwise "update" would be a no-op. */
2778
+ if (fallbackOn && row.fallbackVersion && compareVersions(row.fallbackVersion, row.installed) > 0) {
2779
+ return { version: row.fallbackVersion, fallback: true }
2780
+ }
2781
+ return null
2782
+ }
2783
+
2784
+ /* The version this row will actually end up on — the changelog range has
2785
+ * to stop there, otherwise a fallback row would list changes for a
2786
+ * release it is deliberately not installing today. */
2787
+ function targetVersion(row) {
2788
+ const target = targetOf(row)
2789
+ return target ? target.version : row.latest
2790
+ }
2791
+
2792
+ const eligible = rows.filter(function (row) {
2793
+ return row.state !== 'succeeded' && targetOf(row) !== null
2794
+ })
2795
+
2796
+ React.useEffect(function () {
2797
+ updateBadge.set(eligible.length)
2798
+ }, [eligible.length])
2799
+
2800
+ async function updateAll() {
2801
+ if (busy) return
2802
+ const targets = eligible.map(function (row) {
2803
+ return { name: row.name, from: row.installed, target: targetOf(row) }
2804
+ })
2805
+ if (targets.length === 0) return
2806
+ setBusy(true)
2807
+ setMessage('')
2808
+ for (let index = 0; index < targets.length; index += 1) {
2809
+ const name = targets[index].name
2810
+ patch(name, { state: 'running', percent: null, detail: '' })
2811
+ try {
2812
+ const operation = await runUpdate(name, targets[index].target, function (next) {
2813
+ const progress = next && next.progress ? next.progress : null
2814
+ patch(name, {
2815
+ percent: progress && typeof progress.percent === 'number' ? progress.percent : null,
2816
+ detail: progress && progress.detail ? progress.detail : '',
2817
+ })
2818
+ })
2819
+ const ok = operation && operation.state === 'succeeded'
2820
+ patch(name, {
2821
+ state: ok ? 'succeeded' : 'failed',
2822
+ percent: 100,
2823
+ done: ok
2824
+ ? { from: targets[index].from, to: (operation && operation.installedVersion) || targets[index].target.version }
2825
+ : undefined,
2826
+ detail: ok
2827
+ ? ''
2828
+ : operation && operation.failure
2829
+ ? operation.failure.code + ' — ' + operation.failure.message
2830
+ : (operation && operation.state) || 'failed',
2831
+ })
2832
+ } catch (err) {
2833
+ patch(name, { state: 'failed', percent: 100, detail: err.message })
2834
+ }
2835
+ }
2836
+ if (alive.current) {
2837
+ setBusy(false)
2838
+ setMessage(translate('updates.reloadHint'))
2839
+ }
2840
+ refreshUpdateBadge()
2841
+ }
2842
+
2843
+ const header = h(
2844
+ 'div',
2845
+ { className: 'dsuik-up-header' },
2846
+ h('div', { className: 'dsuik-up-headtext' },
2847
+ h('p', { className: 'dsuik-up-title' }, translate('updates.title')),
2848
+ h('p', { className: 'dsuik-up-sub' }, translate('updates.sub')),
2849
+ ),
2850
+ h('div', { className: 'dsuik-up-actions' },
2851
+ h('button', {
2852
+ type: 'button',
2853
+ className: 'dsuik-up-btn',
2854
+ disabled: busy || phase === 'loading',
2855
+ onClick: load,
2856
+ }, phase === 'loading'
2857
+ ? h('span', { className: 'dsuik-up-btnlabel' },
2858
+ spinIcon(),
2859
+ translate('updates.checking'))
2860
+ : translate('updates.check')),
2861
+ h('button', {
2862
+ type: 'button',
2863
+ className: 'dsuik-up-btn is-primary',
2864
+ disabled: busy || phase !== 'ready' || eligible.length === 0,
2865
+ onClick: updateAll,
2866
+ }, busy ? translate('updates.updating') : translate('updates.updateAll') + ' (' + String(eligible.length) + ')'),
2867
+ ),
2868
+ )
2869
+
2870
+ if (settings.updates === false && phase !== 'loading') {
2871
+ return h('div', { className: 'dsuik-up' },
2872
+ h('div', { className: 'dsuik-up-header' },
2873
+ h('div', { className: 'dsuik-up-headtext' },
2874
+ h('p', { className: 'dsuik-up-title' }, translate('updates.off')),
2875
+ h('p', { className: 'dsuik-up-sub' }, translate('updates.offHint')),
2876
+ ),
2877
+ ),
2878
+ )
2879
+ }
2880
+
2881
+ if (phase === 'unsupported') {
2882
+ return h('div', { className: 'dsuik-up' }, header,
2883
+ h('p', { className: 'dsuik-up-note' }, translate('updates.unsupported')))
2884
+ }
2885
+
2886
+ /* Warm the cache before the click lands: hover, focus and touch-down all
2887
+ * give us a head start on the GitHub round trip. */
2888
+ function prefetchNotes(row) {
2889
+ if (notes[row.name] || !row.repo) return
2890
+ setNotes(function (previous) {
2891
+ return previous[row.name] ? previous : Object.assign({}, previous, { [row.name]: { state: 'loading' } })
2892
+ })
2893
+ readChangelog(row.repo, targetVersion(row), row.installed).then(function (info) {
2894
+ if (!alive.current) return
2895
+ setNotes(function (previous) {
2896
+ return Object.assign({}, previous, { [row.name]: info })
2897
+ })
2898
+ }, function () {
2899
+ if (!alive.current) return
2900
+ setNotes(function (previous) {
2901
+ return Object.assign({}, previous, { [row.name]: { state: 'failed' } })
2902
+ })
2903
+ })
2904
+ }
2905
+
2906
+ function toggleNotes(row) {
2907
+ const isOpen = !!open[row.name]
2908
+ setOpen(function (previous) {
2909
+ const next = Object.assign({}, previous)
2910
+ next[row.name] = !isOpen
2911
+ return next
2912
+ })
2913
+ if (isOpen) return
2914
+ prefetchNotes(row)
2915
+ }
2916
+
2917
+ function notesView(name, row) {
2918
+ const note = notes[name] || { state: 'loading' }
2919
+ if (note.state === 'loading') return translate('updates.notesLoading')
2920
+ if (note.state === 'rate') return translate('updates.notesRate')
2921
+ if (note.state === 'failed') return translate('updates.notesFailed')
2922
+ if (note.state !== 'ready') return translate('updates.notesEmpty')
2923
+ const blocks = []
2924
+ note.groups.forEach(function (group, groupIndex) {
2925
+ const rendered = renderNotes(group.body, name + '-' + group.version)
2926
+ /* A version whose notes are English-only still gets its heading:
2927
+ * dropping the whole block made the list skip 1.73.16 and 1.73.15
2928
+ * and look as if the target version had no entry at all. */
2929
+ if (note.groups.length > 1) {
2930
+ blocks.push(h('p', { key: name + '-v' + String(groupIndex), className: 'dsuik-up-verhead' }, 'v' + group.version))
2931
+ }
2932
+ blocks.push(h('div', { key: name + '-g' + String(groupIndex), className: 'dsuik-up-group' },
2933
+ rendered.length === 0
2934
+ ? h('p', { className: 'dsuik-up-li is-empty' }, translate('updates.notesNoZhVersion'))
2935
+ : rendered))
2936
+ })
2937
+ if (blocks.length === 0) return translate('updates.notesNoZh')
2938
+ if (note.groups.length > 1) {
2939
+ blocks.unshift(h('p', { key: name + '-span', className: 'dsuik-up-span' },
2940
+ translate('updates.notesSpan').replace('{from}', String(row.installed || '?'))))
2941
+ }
2942
+ return blocks
2943
+ }
2944
+
2945
+ /* Every card is a disclosure: click the chip to fold the release notes
2946
+ * out underneath it, click again to fold them away. */
2947
+ function rowView(row, index, quiet) {
2948
+ const target = targetOf(row)
2949
+ /* Rows are created with state:'idle', not with an empty state —
2950
+ * `!row.state` was therefore never true and every row looked "busy",
2951
+ * which is what pushed the wait label back onto finished rows. */
2952
+ const idle = !row.state || row.state === 'idle'
2953
+ const usingFallback = !!target && target.fallback
2954
+ const fallbackShown = usingFallback ? target.version : ''
2955
+ /* A running or finished row speaks with its state, not with the plan:
2956
+ * the "previous release" tag belongs to a row that has not started yet,
2957
+ * otherwise 更新中 never gets a chance to show. */
2958
+ const label = idle ? (quiet || usingFallback ? '' : updateLabel(row)) : updateLabel(row)
2959
+ /* Nothing to install yet: say how far the nearest candidate is, so a
2960
+ * row that is "waiting" does not look like the plugin forgot it.
2961
+ * Only idle rows: a finished row must not read "已更新 · 剩余 5.1 小时". */
2962
+ const soon = idle && !usingFallback && typeof row.age === 'number' && row.age < FRESH_RELEASE_MS
2963
+ ? translate('updates.latestSoon')
2964
+ .replace('{hours}', String(Math.max(0.1, Math.ceil(((FRESH_RELEASE_MS - row.age) / 3600000) * 10) / 10)))
2965
+ : ''
2966
+ const isOpen = !!open[row.name]
2967
+ return h(
2968
+ 'li',
2969
+ {
2970
+ key: row.name,
2971
+ className: 'dsuik-up-row'
2972
+ + (row.state === 'running' ? ' is-running' : '')
2973
+ + (row.state === 'succeeded' ? ' is-ok' : '')
2974
+ + (row.state === 'failed' ? ' is-fail' : '')
2975
+ + (isOpen ? ' is-open' : ''),
2976
+ style: { animationDelay: String(Math.min(index, 12) * 18) + 'ms' },
2977
+ },
2978
+ h('button', {
2979
+ type: 'button',
2980
+ className: 'dsuik-up-head',
2981
+ 'aria-expanded': isOpen ? 'true' : 'false',
2982
+ title: translate('updates.notesToggle'),
2983
+ onMouseEnter: function () {
2984
+ prefetchNotes(row)
2985
+ },
2986
+ onFocus: function () {
2987
+ prefetchNotes(row)
2988
+ },
2989
+ onPointerDown: function () {
2990
+ prefetchNotes(row)
2991
+ },
2992
+ onClick: function () {
2993
+ toggleNotes(row)
2994
+ },
2995
+ },
2996
+ h('span', { className: 'dsuik-up-main' },
2997
+ h('span', { className: 'dsuik-up-name' }, row.name),
2998
+ h('span', { className: 'dsuik-up-ver' },
2999
+ String((row.done && row.done.from) || row.installed || '?') +
3000
+ ' → ' +
3001
+ String((row.done && row.done.to) || fallbackShown || row.latest || '?')),
3002
+ soon ? h('span', { className: 'dsuik-up-soon' }, soon) : null,
3003
+ label ? h('span', { className: 'dsuik-up-tag' }, label) : null,
3004
+ fallbackShown ? h('span', { className: 'dsuik-up-tag', title: translate('updates.fallbackWhy') }, translate('updates.fallbackTag')) : null,
3005
+ row.compat && !row.state
3006
+ ? h('span', { className: 'dsuik-up-tag is-warn', title: translate('updates.section.blockedHint') },
3007
+ translate('updates.compatTag').replace('{version}', String(row.compat.required || row.compat.runtime || '?')))
3008
+ : null,
3009
+ row.detail ? h('span', { className: 'dsuik-up-detail' }, row.detail) : null,
3010
+ ),
3011
+ h('span', { className: 'dsuik-up-chev', 'aria-hidden': 'true' }, isOpen ? '▾' : '▸'),
3012
+ ),
3013
+ row.state === 'running'
3014
+ ? (row.percent === null
3015
+ ? h('div', { className: 'dsuik-up-bar is-indef' }, h('i'))
3016
+ : h('div', { className: 'dsuik-up-bar' }, h('i', { style: { width: String(row.percent || 0) + '%' } })))
3017
+ : null,
3018
+ isOpen ? h('div', { className: 'dsuik-up-notes' }, notesView(row.name, row)) : null,
3019
+ )
3020
+ }
3021
+
3022
+ /* Two areas: everything the 24-hour rule lets us touch on top, the rest
3023
+ * below it, so the button above always matches the list above. */
3024
+ const groups = { ready: [], blocked: [], waiting: [] }
3025
+ rows.forEach(function (row) {
3026
+ const ready = row.state === 'succeeded' || targetOf(row) !== null
3027
+ if (ready) groups.ready.push(row)
3028
+ else if (row.compat && row.state !== 'succeeded') groups.blocked.push(row)
3029
+ else groups.waiting.push(row)
3030
+ })
3031
+ /* Soonest to unlock first: 25h old is 23h from being updateable, 4h old
3032
+ * is 20h away. Rows whose age could not be read go last — we cannot
3033
+ * promise a time for them. */
3034
+ groups.waiting.sort(function (a, b) {
3035
+ const left = function (row) {
3036
+ return typeof row.age === 'number' ? row.age : -Infinity
3037
+ }
3038
+ return left(b) - left(a)
3039
+ })
3040
+
3041
+ /* How many of the checked plugins simply have nothing newer. Without it,
3042
+ * "30 checked" next to ten visible rows reads like a failed scan. */
3043
+ const upToDate = Math.max(0, checked - rows.length)
3044
+
3045
+ function sectionArea(titleKey, items, muted, hintKey, always) {
3046
+ if (items.length === 0 && !always) return null
3047
+ return h(
3048
+ 'section',
3049
+ { className: 'dsuik-up-section' + (muted ? ' is-muted' : '') },
3050
+ h('div', { className: 'dsuik-up-section-head' },
3051
+ h('p', { className: 'dsuik-up-section-title' },
3052
+ translate(titleKey) + ' (' + String(items.length) + ')'),
3053
+ hintKey
3054
+ ? h('p', { className: 'dsuik-up-section-hint' },
3055
+ hintKey.indexOf('updates.') === 0 ? translate(hintKey) : hintKey)
3056
+ : null,
3057
+ ),
3058
+ items.length === 0
3059
+ ? null
3060
+ : h('ul', { className: 'dsuik-up-list' },
3061
+ items.map(function (row, index) { return rowView(row, index, muted) })),
3062
+ )
3063
+ }
3064
+
3065
+ return h(
3066
+ 'div',
3067
+ { className: 'dsuik-up' },
3068
+
3069
+ header,
3070
+ phase === 'error' ? h('p', { className: 'dsuik-up-note is-error' }, translate('updates.loadFailed') + ' — ' + message) : null,
3071
+ phase === 'loading'
3072
+ ? h('div', { className: 'dsuik-up-loading', role: 'status' },
3073
+ spinIcon(16),
3074
+ h('span', null,
3075
+ message ||
3076
+ (clock >= 13
3077
+ ? translate('updates.pmTimeout')
3078
+ .replace('{remote}', pluginManager() ? 'yes' : 'no')
3079
+ .replace('{ms}', String(clock))
3080
+ : clock >= 4
3081
+ ? translate('updates.pmWaiting').replace('{remote}', pluginManager() ? 'yes' : 'no')
3082
+ : translate('updates.loadingDetail'))))
3083
+ : null,
3084
+ phase === 'ready'
3085
+ ? h('p', { className: 'dsuik-up-note' },
3086
+ String(checked) + ' ' + translate('updates.checked') +
3087
+ (upToDate > 0 ? ' · ' + translate('updates.upToDate').replace('{n}', String(upToDate)) : ''))
3088
+ : null,
3089
+ /* The ready area stays on screen even when it is empty, so the page
3090
+ * always answers "is there anything for me?" instead of going blank. */
3091
+ phase === 'ready' ? sectionArea('updates.section.ready', groups.ready, false, null, true) : null,
3092
+ phase === 'ready' ? sectionArea('updates.section.waiting', groups.waiting, true, 'updates.section.waitingHint', false) : null,
3093
+ phase === 'ready'
3094
+ ? sectionArea(
3095
+ 'updates.section.blocked',
3096
+ groups.blocked,
3097
+ true,
3098
+ translate('updates.section.blockedHint').replace(
3099
+ '{runtime}',
3100
+ String((groups.blocked[0] && groups.blocked[0].compat && groups.blocked[0].compat.runtime) || ''),
3101
+ ),
3102
+ false,
3103
+ )
3104
+ : null,
3105
+ message && phase !== 'error' ? h('p', { className: 'dsuik-up-note' }, message) : null,
3106
+ )
3107
+ }
3108
+
3109
+ const UPDATES_CSS = `
3110
+ .dsuik-up{display:flex;flex-direction:column;gap:14px;padding:4px 0 24px;font-size:14px;color:var(--dsw-alias-label-primary);}
3111
+ .dsuik-up-header{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;flex-wrap:wrap;}
3112
+ .dsuik-up-headtext{display:flex;flex-direction:column;gap:6px;min-width:240px;flex:1;}
3113
+ .dsuik-up-title{margin:0;font-size:16px;font-weight:600;line-height:1.4;}
3114
+ .dsuik-up-sub{margin:0;font-size:13px;line-height:1.65;color:var(--dsw-alias-label-secondary);}
3115
+ .dsuik-up-actions{display:flex;gap:8px;flex-shrink:0;}
3116
+ .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;}
3117
+ .dsuik-up-btn:hover:not(:disabled){border-color:var(--dsw-alias-border-l2);}
3118
+ .dsuik-up-btn:disabled{opacity:.5;cursor:default;}
3119
+ .dsuik-up-btn.is-primary{background:var(--dsw-alias-brand-primary);border-color:transparent;color:#fff;}
3120
+ .dsuik-up-note{margin:0;font-size:12.5px;line-height:1.6;color:var(--dsw-alias-label-secondary);}
3121
+ .dsuik-up-note.is-error{color:var(--dsw-alias-label-error, #c0392b);}
3122
+ @keyframes dsuik-up-rotate{to{transform:rotate(1turn)}}
3123
+ @keyframes dsuik-up-shimmer{0%{background-position:150% 0}100%{background-position:-50% 0}}
3124
+ @keyframes dsuik-up-in{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:none}}
3125
+ .dsuik-up-btnlabel{display:inline-flex;align-items:center;gap:6px;}
3126
+ .dsuik-up-spin{display:block;flex:0 0 auto;animation:dsuik-up-rotate .8s linear infinite;}
3127
+ .dsuik-up-section-head{display:flex;flex-direction:column;gap:2px;}
3128
+ .dsuik-up-section-hint{margin:0;font-size:12px;line-height:1.55;color:var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));}
3129
+ .dsuik-up-section{display:flex;flex-direction:column;gap:10px;animation:dsuik-up-in .26s cubic-bezier(.2,.8,.3,1) both;}
3130
+ .dsuik-up-section+.dsuik-up-section{margin-top:4px;padding-top:18px;border-top:1px solid var(--dsw-alias-border-l1);}
3131
+ .dsuik-up-section-title{margin:0;font-size:12.5px;font-weight:600;letter-spacing:.01em;color:var(--dsw-alias-label-primary);}
3132
+ .dsuik-up-section.is-muted .dsuik-up-row{opacity:.7;background:transparent;}
3133
+ .dsuik-up-note.is-empty{padding:10px 12px;border:1px dashed var(--dsw-alias-border-l1);border-radius:10px;}
3134
+ .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;}
3135
+ @media (prefers-reduced-motion: reduce){.dsuik-up-section,.dsuik-up-row,.dsuik-up-loading{animation:none;}}
3136
+ .dsuik-up-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:10px;align-items:flex-start;}
3137
+ .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;}
3138
+ .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;}
3139
+ .dsuik-up-chev{font-size:10px;line-height:1;color:var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));}
3140
+ .dsuik-up-row.is-open{border-radius:12px;max-width:640px;}
3141
+ .dsuik-up-span{margin:0 0 6px;font-size:11.5px;color:var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));}
3142
+ .dsuik-up-verhead{margin:8px 0 2px;font-size:11.5px;font-weight:600;color:var(--dsw-alias-label-secondary);}
3143
+ .dsuik-up-group+.dsuik-up-group{margin-top:8px;padding-top:8px;border-top:1px dashed var(--dsw-alias-border-l1);}
3144
+ .dsuik-up-notes .dsuik-up-h{margin:6px 0 2px;font-weight:600;color:var(--dsw-alias-label-primary);}
3145
+ .dsuik-up-notes .dsuik-up-p{margin:2px 0;}
3146
+ .dsuik-up-notes .dsuik-up-li{margin:2px 0;padding-left:10px;text-indent:-10px;}
3147
+ .dsuik-up-notes .dsuik-up-li.is-empty{color:var(--dsw-alias-label-secondary);}
3148
+ .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;}
3149
+ .dsuik-up-link{text-decoration:underline;}
3150
+ .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;}
3151
+ .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;}
3152
+ .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));}
3153
+ .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));}
3154
+ .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));}
3155
+ .dsuik-up-main{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap;}
3156
+ .dsuik-up-name{font-weight:500;font-size:12.5px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
3157
+ .dsuik-up-ver{font-size:12.5px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;white-space:nowrap;}
3158
+ .dsuik-up-soon{font-size:12px;color:var(--dsw-alias-label-secondary);white-space:nowrap;flex:0 0 auto;}
3159
+ .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);}
3160
+ .dsuik-up-detail{font-size:12px;color:var(--dsw-alias-label-secondary);flex-basis:100%;word-break:break-word;}
3161
+ .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;}
3162
+ .dsuik-up-bar>i{display:block;height:100%;background:var(--dsw-alias-brand-primary);transition:width .3s ease;}
3163
+ .dsuik-up-tag.is-warn{color:var(--dsw-alias-state-error-primary, var(--dsw-alias-label-secondary));}
3164
+ .dsuik-up-row.is-running .dsuik-up-bar>i{background:var(--dsw-alias-state-warn-primary, var(--dsw-alias-brand-primary));}
3165
+ .dsuik-up-bar.is-indef>i{width:35%;animation:dsuik-up-slide 1.15s ease-in-out infinite;}
3166
+ @keyframes dsuik-up-slide{0%{transform:translateX(-60%)}100%{transform:translateX(300%)}}
3167
+ @media (prefers-reduced-motion: reduce){.dsuik-up-bar.is-indef>i{animation-duration:2.4s;}}
3168
+ .dsuik-up-tab{display:inline-flex;align-items:center;gap:5px;}
3169
+ .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);}
3170
+ `
3171
+
3172
+ ctx.slots.inject('plugins.tab', function () {
3173
+ return ctx.slots.register(
3174
+ {
3175
+ name: 'plugins.tab',
3176
+ id: 'ui-optimize-updates',
3177
+ order: 100,
3178
+ label: function () {
3179
+ return h(
3180
+ 'span',
3181
+ { className: 'dsuik-up-tab' },
3182
+ translate('updates.tab'),
3183
+ h(UpdateBadge),
3184
+ )
3185
+ },
3186
+ },
3187
+ UpdatesTab,
3188
+ )
3189
+ })
3190
+
3191
+ /* The tab label renders outside the panel, so the badge styles cannot ride
3192
+ * on the panel's own markup — they have to be registered with the run. */
3193
+ ctx.effect(function () {
3194
+ const style = document.createElement('style')
3195
+ style.setAttribute('data-dsh-ui-optimize', 'updates')
3196
+ style.textContent = UPDATES_CSS
3197
+ document.head.appendChild(style)
3198
+ return function () {
3199
+ style.remove()
3200
+ }
3201
+ }, 'dsh-ui-optimize: update styles')
3202
+
3203
+ ctx.effect(function () {
3204
+ refreshUpdateBadge()
3205
+ })
3206
+
1950
3207
  ctx.slots.inject('settings.section', function () {
1951
3208
  return ctx.slots.register(
1952
3209
  {