dsh-aupdate 0.8.3 → 0.8.5

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 +31 -2
  2. package/client.js +46 -13
  3. package/index.js +28 -1
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -140,6 +140,11 @@ mtime 为准:那是磁盘事实。会话目录整个读不到时返回「不
140
140
  额外入口是插件页顶栏「版本管理」里的「设置」按钮。升级后第一次打开会弹一张一次性提示卡告诉你入口搬到哪了。
141
141
  读写走 `/api/dsh-aupdate/{state,run,rollback,logs}`。
142
142
 
143
+ 保存走覆盖层:只有这里改过的键才写进 `~/.dsh/aupdate-settings.json`,其余沿用默认值。
144
+ 后端对每个键都有校验分支(布尔键只认布尔、数字键按范围夹紧、`registryMode` 认四种模式、
145
+ `registryUrl` 只认 `http(s)`),**没有分支的键会被丢掉**;所以保存之后界面会拿服务端返回的
146
+ 快照和刚才提交的值比对,没存下来的键会直接写「这些没存下来:…」而不是「已保存」。
147
+
143
148
  版面按 `dsh-cost-meter` 的设置页组织:一栏一栏的分区卡片、小号分区标题、浅一档的说明
144
149
  文字,主/次两级小按钮;「上一次」不再是一串用 `·` 拼起来的句子,而是三张统计卡
145
150
  (上次检查 / 检查包数 / 可更新)加一个状态徽标。颜色与边框全部取自宿主主题变量
@@ -219,7 +224,17 @@ stargazers)与「分享」(复制项目地址到剪贴板,任何环境都
219
224
 
220
225
  这一页还把 aupdate 自己的设置嵌了进来(工具条上的「设置」),改完不用切回设置页。
221
226
 
222
- 工具条从左到右:搜索、检查更新(绕过缓存)、一键升级、升级选中 N 个、注册表、复制诊断、设置。
227
+ 工具条从左到右:搜索、主按钮、一键升级、升级选中 N 个、注册表、复制诊断、设置。
228
+
229
+ 主按钮的名字跟着「自动安装新版本」走:开着时叫**检查并安装**(重新查一遍 registry,查到就装),
230
+ 关掉时叫**只检查**(查到只列出来,不动手)。它以前一律叫「检查更新」、一律只查不装,于是开着
231
+ 自动安装的人点完发现什么都没装,只能再去点「一键升级」——现在名字和动作对上了。
232
+
233
+ **一键升级**永远真的装:它带 `force`,不受「自动安装」这个开关限制(那个开关管的是定时轮次,
234
+ 不是人按下的按钮),并且复用 10 分钟内的查询结果,点了就动手、不重查。
235
+
236
+ 「自动安装」关掉时,查到的可更新插件会**排到列表最上面**:这时「看得见」就等于「要不要动手」,
237
+ 埋在一屏之外等于没查到。开着自动安装时不需要这个排序。
223
238
  顶部三个数字分别是**需处理**(已装版本声明的 DSH 范围不满足,或者读不到已装版本——这些包很可能
224
239
  根本没被加载,升级救不了它们)、**可升级**、**已装**。
225
240
 
@@ -514,7 +529,21 @@ first paint: fetching packuments for a whole page of packages is unusably slow o
514
529
  This page also embeds aupdate's own settings (the **Settings** button in the toolbar), so there is
515
530
  no need to switch back to the settings page.
516
531
 
517
- The toolbar is: search, Check now (bypasses the cache), Upgrade all, Upgrade the N selected,
532
+ The toolbar is: search, the primary button, Upgrade all, Upgrade the N selected, Registries,
533
+ Copy diagnostics, Settings.
534
+
535
+ The primary button follows **Install new versions**: when that is on it reads **Check and install**
536
+ (re-queries the registry and installs what it finds); when it is off it reads **Check only** (lists
537
+ what is newer, touches nothing). It used to be called "Check now" and always ran a check-only pass,
538
+ so anyone with auto-install on saw nothing installed and had to press Upgrade all afterwards.
539
+
540
+ **Upgrade all** always installs: it sends `force`, so the auto-install switch does not gate it (that
541
+ switch governs scheduled cycles, not a button someone pressed), and it reuses a lookup less than 10
542
+ minutes old instead of re-querying.
543
+
544
+ With auto-install off, plugins that can update are sorted to the top of the list: seeing them is the
545
+ decision, and burying them below the fold is the same as not finding them. With auto-install on the
546
+ sort is unnecessary, so the list stays alphabetical.
518
547
  Registries, Copy diagnostics, Settings. The three numbers on top are **Needs attention** (the
519
548
  installed version declares a DSH range this host does not satisfy, or the installed version is
520
549
  unreadable — those bundles are likely not loaded at all, and upgrading cannot fix them),
package/client.js CHANGED
@@ -77,6 +77,7 @@ window.__ModuleLoader__.load({
77
77
  saving: '保存中…',
78
78
  saved: '已保存',
79
79
  savedHint: '新设置立即生效,不用重启',
80
+ saveIgnored: '这些没存下来:{keys}(后端没有对应处理)',
80
81
  failed: '保存失败',
81
82
  runNow: '立刻检查',
82
83
  running: '正在检查…',
@@ -163,7 +164,8 @@ window.__ModuleLoader__.load({
163
164
  versionsNoop: '已经是这一版',
164
165
  versionsFail: '切换失败',
165
166
  versionsTotal: '共 {n} 个版本',
166
- versionsChecks: '检查更新',
167
+ versionsCheckInstall: '检查并安装',
168
+ versionsCheckOnly: '只检查',
167
169
  versionsUpgradeAll: '一键升级',
168
170
  versionsUpgradePicked: '升级选中 {n}',
169
171
  versionsSources: '注册表',
@@ -281,6 +283,7 @@ window.__ModuleLoader__.load({
281
283
  saving: 'Saving…',
282
284
  saved: 'Saved',
283
285
  savedHint: 'Takes effect immediately, no restart',
286
+ saveIgnored: 'Not stored: {keys} (no backend handling)',
284
287
  failed: 'Save failed',
285
288
  runNow: 'Check now',
286
289
  running: 'Checking…',
@@ -367,7 +370,8 @@ window.__ModuleLoader__.load({
367
370
  versionsNoop: 'Already on this version',
368
371
  versionsFail: 'Switch failed',
369
372
  versionsTotal: '{n} versions',
370
- versionsChecks: 'Check now',
373
+ versionsCheckInstall: 'Check and install',
374
+ versionsCheckOnly: 'Check only',
371
375
  versionsUpgradeAll: 'Upgrade all',
372
376
  versionsUpgradePicked: 'Upgrade {n}',
373
377
  versionsSources: 'Registries',
@@ -1161,7 +1165,14 @@ window.__ModuleLoader__.load({
1161
1165
  // 只换 state(lastRun、history 这些由服务端算),不回灌草稿:
1162
1166
  // 草稿里可能已经有比这份响应更新的输入。
1163
1167
  setState(next)
1164
- setSaveHint(T.saved + ' · ' + T.savedHint)
1168
+ // 服务端对「不认识 / 校验不过」的键会静默丢掉,接口却仍然回 200。
1169
+ // 拿回来的快照和刚才提交的值比一下:没变的就是没存进去,别报「已保存」。
1170
+ // exclude 由服务端重排过,不比;它的顺序不影响语义。
1171
+ const ignored = Object.keys(batch).filter((key) => key !== 'exclude' &&
1172
+ JSON.stringify(next?.settings?.[key]) !== JSON.stringify(batch[key]))
1173
+ setSaveHint(ignored.length > 0
1174
+ ? T.saveIgnored.replace('{keys}', ignored.join(', '))
1175
+ : T.saved + ' · ' + T.savedHint)
1165
1176
  } catch {
1166
1177
  // 失败的键补回队列,下次改动会一起重试,不静默吞掉用户的设置。
1167
1178
  pendingRef.current = { ...batch, ...pendingRef.current }
@@ -1983,10 +1994,6 @@ window.__ModuleLoader__.load({
1983
1994
  }, [])
1984
1995
 
1985
1996
  const packages = useMemo(() => (Array.isArray(state?.packages) ? state.packages : []), [state])
1986
- const rows = useMemo(() => {
1987
- const needle = query.trim().toLowerCase()
1988
- return needle === '' ? packages : packages.filter((item) => String(item.name).toLowerCase().includes(needle))
1989
- }, [packages, query])
1990
1997
 
1991
1998
  // 最近一轮里「查到的可更新版本」和「镜像落后」:都用名字索引,行上直接查。
1992
1999
  const updatable = useMemo(() => {
@@ -2007,6 +2014,23 @@ window.__ModuleLoader__.load({
2007
2014
  return mark
2008
2015
  }, [state])
2009
2016
 
2017
+ // 「自动安装」关掉时,把查到的可更新项顶到最上面:这时「看得见」就等于「要不要动手」,
2018
+ // 埋在一屏之外的长列表里等于没查到。开着自动安装时它们会被装掉,不需要这个排序。
2019
+ const autoApply = state?.settings?.autoApply !== false
2020
+ const ordered = useMemo(() => {
2021
+ const filtered = (() => {
2022
+ const needle = query.trim().toLowerCase()
2023
+ return needle === '' ? packages : packages.filter((item) => String(item.name).toLowerCase().includes(needle))
2024
+ })()
2025
+ if (autoApply) return filtered
2026
+ return filtered.slice().sort((a, b) => {
2027
+ const ua = updatable.has(a.name) ? 0 : 1
2028
+ const ub = updatable.has(b.name) ? 0 : 1
2029
+ if (ua !== ub) return ua - ub
2030
+ return a.name < b.name ? -1 : a.name > b.name ? 1 : 0
2031
+ })
2032
+ }, [packages, query, autoApply, updatable])
2033
+
2010
2034
  const attention = useMemo(() => packages.filter((item) => item.ok === false || item.version === ''), [packages])
2011
2035
  const pickedNames = useMemo(() => packages.filter((item) => picked[item.name] === true).map((item) => item.name), [packages, picked])
2012
2036
 
@@ -2073,11 +2097,11 @@ window.__ModuleLoader__.load({
2073
2097
  await reload()
2074
2098
  }, [busy, post, reload])
2075
2099
 
2076
- const runCycle = useCallback(async (mode, names, fresh) => {
2100
+ const runCycle = useCallback(async (mode, names, fresh, force) => {
2077
2101
  if (busy !== '') return
2078
2102
  setBusy('cycle')
2079
2103
  setHint('')
2080
- const { ok, payload } = await post('run', { mode, names: names ?? [], fresh: fresh === true })
2104
+ const { ok, payload } = await post('run', { mode, names: names ?? [], fresh: fresh === true, force: force === true })
2081
2105
  if (!ok) setHint(T.versionsFail)
2082
2106
  else if (payload?.started === false) setHint(payload?.reason || T.running)
2083
2107
  else setHint(T.runDone)
@@ -2159,8 +2183,17 @@ window.__ModuleLoader__.load({
2159
2183
  style: { flex: '1 1 200px' },
2160
2184
  }),
2161
2185
  h('div', { className: S.actions },
2162
- h('button', { type: 'button', className: S.btn, disabled: busy !== '', onClick: () => void runCycle('check', [], true) }, T.versionsChecks),
2163
- h('button', { type: 'button', className: S.btnPrimary, disabled: busy !== '', onClick: () => void runCycle('update', [], true) }, T.versionsUpgradeAll),
2186
+ // 主按钮的语义跟着设置走:开着自动安装时它就是「检查并安装」(查到就装),
2187
+ // 关掉时退化成「只检查」。名字必须跟着变,否则「检查更新」不装东西会像 bug。
2188
+ h('button', {
2189
+ type: 'button',
2190
+ className: S.btn,
2191
+ disabled: busy !== '',
2192
+ onClick: () => void runCycle(autoApply ? 'update' : 'check', [], true, autoApply),
2193
+ }, autoApply ? T.versionsCheckInstall : T.versionsCheckOnly),
2194
+ // 「一键升级」永远真的装:force 让它不被「自动安装」开关挡住,
2195
+ // 但复用 10 分钟内的查询结果(fresh=false),点了就动手、不重查。
2196
+ h('button', { type: 'button', className: S.btnPrimary, disabled: busy !== '', onClick: () => void runCycle('update', [], false, true) }, T.versionsUpgradeAll),
2164
2197
  h('button', { type: 'button', className: S.btn, disabled: busy !== '' || pickedNames.length === 0, onClick: () => void runCycle('update', pickedNames, false) }, T.versionsUpgradePicked.replace('{n}', String(pickedNames.length))),
2165
2198
  h('button', { type: 'button', className: S.btn, onClick: () => setShowSources((v) => !v) }, T.versionsSources),
2166
2199
  h('button', { type: 'button', className: S.btn, onClick: () => void copyDiagnostics() }, T.versionsDiagnostics),
@@ -2221,10 +2254,10 @@ window.__ModuleLoader__.load({
2221
2254
  : null,
2222
2255
  // 包列表:勾选 → 升级选中;展开 → 全部版本 → 切过去。
2223
2256
  h('div', { className: S.card },
2224
- rows.length === 0
2257
+ ordered.length === 0
2225
2258
  ? h('span', { className: S.status }, T.versionsEmpty)
2226
2259
  : h('div', { className: S.scrollList },
2227
- rows.map((item) => {
2260
+ ordered.map((item) => {
2228
2261
  const listed = lists[item.name]
2229
2262
  const expanded = openName === item.name
2230
2263
  const behind = lagged.get(item.name)
package/index.js CHANGED
@@ -241,6 +241,9 @@ function makeLogTemplates(lang) {
241
241
  ? `${name} 镜像落后:镜像 ${mirror},官方 ${upstream}`
242
242
  : `${name} mirror lag: mirror ${mirror}, upstream ${upstream}`),
243
243
  registryPicked: (source) => (zh ? `安装源:${source}` : `Registry: ${source}`),
244
+ settingsDropped: (keys) => (zh
245
+ ? `这些设置没存下来(没有对应的校验分支):${keys.join(', ')}`
246
+ : `These settings were not stored (no validation branch): ${keys.join(', ')}`),
244
247
  switching: (name, from, to) => (zh
245
248
  ? '切换版本:' + name + ' ' + from + ' → ' + to
246
249
  : 'Switching: ' + name + ' ' + from + ' → ' + to),
@@ -651,6 +654,20 @@ function writeOverrides(patch) {
651
654
  if (LANG_CHOICES.includes(text)) next[key] = text
652
655
  continue
653
656
  }
657
+ // 安装源。这两个键是字符串,而下面的兜底只认布尔——0.7.5 到 0.8.3 它们就是
658
+ // 这样「保存成功、文件里没有」的:POST 返回 200、日志记了 settingsChanged,
659
+ // 界面上却又弹回默认值。凡是新增字符串键,都必须在这里有一支,没有就被丢掉。
660
+ if (key === 'registryMode') {
661
+ const text = typeof raw === 'string' ? raw.trim().toLowerCase() : ''
662
+ if (REGISTRY_MODES.includes(text)) next[key] = text
663
+ continue
664
+ }
665
+ if (key === 'registryUrl') {
666
+ const text = typeof raw === 'string' ? raw.trim().replace(/\/+$/u, '') : ''
667
+ // 空串是合法值(清空自定义地址并退回跟随 pnpm);非空必须是 http(s)。
668
+ if (text === '' || /^https?:\/\/[^\s]+$/iu.test(text)) next[key] = text
669
+ continue
670
+ }
654
671
  const bounds = NUMBER_BOUNDS[key]
655
672
  if (bounds !== undefined) {
656
673
  const value = typeof raw === 'number' ? raw : Number(raw)
@@ -661,6 +678,13 @@ function writeOverrides(patch) {
661
678
  if (typeof raw === 'boolean') next[key] = raw
662
679
  else if (raw === 'true' || raw === 'false') next[key] = raw === 'true'
663
680
  }
681
+ // 传了、也是可覆盖的键,但一个都没落下来:记一条,别再静默成功。
682
+ // 上面那类「字符串键没有分支」的 bug 只有日志能提前暴露。
683
+ const asked = Object.keys(patch ?? {})
684
+ const landed = asked.filter((key) => OVERRIDEABLE.includes(key) && next[key] !== undefined)
685
+ if (asked.length > 0 && landed.length === 0) {
686
+ writeLog('settingsDropped', [asked])
687
+ }
664
688
  const file = settingsPath()
665
689
  try {
666
690
  mkdirSync(dirname(file), { recursive: true })
@@ -2225,7 +2249,9 @@ async function runCycle(mode, ctxRef, options = {}) {
2225
2249
  report.updates = report.updates.slice(0, settings.maxPerCycle)
2226
2250
  writeLog('capped', [settings.maxPerCycle, deferred])
2227
2251
  }
2228
- if (mode === 'check' || !settings.autoApply) {
2252
+ // 手动「一键升级」传 force:用户当场点了装,就不该被「自动安装」这个开关挡住——
2253
+ // 那个开关管的是定时轮次,不是人按下的按钮。
2254
+ if (mode === 'check' || (!settings.autoApply && options.force !== true)) {
2229
2255
  report.reason = { code: 'checkOnly' }
2230
2256
  return report
2231
2257
  }
@@ -2844,6 +2870,7 @@ function registerRoutes(scope, ctxRef) {
2844
2870
  const report = await beginningRun(mode, ctxRef, {
2845
2871
  names: Array.isArray(body?.names) ? body.names : [],
2846
2872
  fresh: body?.fresh === true,
2873
+ force: body?.force === true,
2847
2874
  })
2848
2875
  if (report === null) {
2849
2876
  sendJson(res, 200, { started: false, reason: renderReason({ code: 'alreadyRunning' }, url.searchParams.get('lang')) })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aupdate",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "type": "module",
5
5
  "description": "定时检查 DSH 插件更新,串行安装后就地生效,不重启;支持多种调度节奏、失败抑制、按包回滚,并在动手前留快照、忙时自动让开;不更新/只更新哪些插件改成勾选,发现更新在右下角提醒,日志最新在最上面,并在「设置 → 插件更新」里有独立一页。",
6
6
  "license": "MIT",