dsh-aupdate 0.5.0 → 0.6.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 +44 -16
  2. package/client.js +100 -31
  3. package/index.js +136 -57
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -55,8 +55,7 @@ https://github.com/CalmSun/dsh-aupdate
55
55
 
56
56
  | 设置 | 默认 | 说明 |
57
57
  |---|---|---|
58
- | `allow` | `[]` | 只更新这些包;留空表示全部 |
59
- | `exclude` | `[]` | 不更新的包,优先级高于 `allow` |
58
+ | `exclude` | `[]` | 不更新的包;填了就一直不参与自动更新 |
60
59
  | `allowMajor` | `true` | 关掉后只在同一主版本内升级 |
61
60
  | `allowPrerelease` | `false` | 关掉后不装预发布;`next` 标签不受影响 |
62
61
  | `idleOnly` | `true` | 忙的时候不动手(见下节) |
@@ -87,6 +86,9 @@ mtime 为准:那是磁盘事实。会话目录整个读不到时返回「不
87
86
  `~/.dsh/aupdate-history.json`,设置页里能直接看到,并对最近一次更新点「回滚」
88
87
  把旧版本装回去。回滚只针对本插件自己装上去的那一次。
89
88
 
89
+ 记录栏固定高度、在自己的框里滚动:堆到上百条也只是这一栏变长,不会把整页顶到几屏
90
+ 之外,按钮也不会被挤到看不见的地方。
91
+
90
92
  同一个包的 `from → to` 完全相同、且都不是回滚记录时只留最新一条:
91
93
  否则同一行失败记录会一轮一条堆满历史,真正要回的那个点反而找不到了。
92
94
  `1.0 → 1.1` 和 `1.0 → 1.2` 是两件事,不会合并。
@@ -124,19 +126,33 @@ mtime 为准:那是磁盘事实。会话目录整个读不到时返回「不
124
126
 
125
127
  ### 勾选插件,而不是手写包名
126
128
 
127
- `exclude` / `allow` 原来要一行一个包名地敲。现在整页里是两张勾选清单,直接列出
128
- 这个 profile 实际装着的插件和各自的已装版本:
129
+ `exclude` 原来要一行一个包名地敲。现在整页里是一张勾选清单,直接列出这个 profile
130
+ 实际装着的插件和各自的已装版本:
129
131
 
130
132
  - **不自动更新的包**:勾上的永远不参与自动更新
131
- - **只更新这些包**:勾上后只更新勾中的;一个都不勾表示不启用这条白名单
132
- - 能按名字搜索,`/state` 里带着 `packages`(名字、版本、当前是否被排除/在白名单里)
133
+ - 能按名字搜索,`/state` 里带着 `packages`(名字、版本、当前是否被排除)
133
134
  - 「全选 / 清空」只作用于当前筛选出来的行——搜完再点全选,意思是把搜到的都勾上
134
- - 白名单里留着已卸载的包名时照样列出来并标「未安装」,否则那条规则再也删不掉
135
+ - 这个 profile 里装着的插件都会列出来,列表本身就是「能勾什么」的全部答案
136
+
137
+ ### 「上一次」不会再被重启清空
138
+
139
+ 最近一轮的结果(时间、查了多少个、几个可更新、装成几个、失败原因)现在落在
140
+ `~/.dsh/aupdate-lastrun.json`,DSH 重启后照旧显示。以前它是纯内存的,重启一次就回到
141
+ 「还没跑过」,看着像这一轮根本没跑过。读的时候逐字段校验,坏文件只会让这张卡缺席,
142
+ 不会让插件加载失败。
143
+
144
+ ### 显示语言
145
+
146
+ 设置页顶部有「显示语言」:跟随系统 / 中文 / English。切换立即生效,不用等保存往返;
147
+ 选择会存进 `~/.dsh/aupdate-settings.json`(键 `lang`),换个浏览器或换台机器打开设置页
148
+ 还是同一个语言。只影响文案,不改插件的更新行为。
135
149
 
136
- 整页最下面是**运行日志**卡片,直接看插件最近写了什么,不用再去翻文件:
150
+ 整页最下面是**运行日志**卡片,直接看插件最近写了什么,不用再去翻文件。日志正文用中文写,
151
+ 一行一件事(检查了多少个、装哪个、为什么跳过),状态词也翻成人话;
137
152
 
138
153
  - 可选显示最近 100 / 200 / 500 / 1000 行,默认 200
139
154
  - **最新的在最上面**:按时间倒序渲染,刚装了什么不用滚到底
155
+ - 时间只到「月-日 时:分:秒」并等宽对齐,省下的宽度留给正文
140
156
  - 打开「自动刷新」后每 5 秒拉一次,正在排查时开着;关掉就完全不动
141
157
  - 读之前会先把待写队列刷下去,所以刚点完检查,那几行马上就在里面
142
158
  - 时间戳按本地时区显示,文件超过 1MB 轮转给一句提示,另附总行数
@@ -260,8 +276,7 @@ A successful install clears the record.
260
276
 
261
277
  | Setting | Default | Meaning |
262
278
  |---|---|---|
263
- | `allow` | `[]` | Only update these packages; empty means all |
264
- | `exclude` | `[]` | Never update these; takes priority over `allow` |
279
+ | `exclude` | `[]` | Never update these; whatever is listed stays out of auto-updates |
265
280
  | `allowMajor` | `true` | When off, stay within the same major version |
266
281
  | `allowPrerelease` | `false` | When off, skip prereleases; the `next` tag is unaffected |
267
282
  | `idleOnly` | `true` | Hold off while anything is busy (see below) |
@@ -323,6 +338,9 @@ the new version, and a timestamp, in `~/.dsh/aupdate-history.json`. The settings
323
338
  page lists them and can roll the most recent update back to its previous version.
324
339
  A rollback applies once: the same downgrade cannot be replayed.
325
340
 
341
+ The list keeps a fixed height and scrolls inside its own box, so a hundred entries make
342
+ that one card longer instead of pushing the whole page down.
343
+
326
344
  Repeated rows for the same package with an identical `from → to`, where neither is
327
345
  a rollback, collapse into the newest one. Otherwise a single failing version would
328
346
  pile up one row per cycle and bury the entry you actually want to return to.
@@ -334,12 +352,22 @@ The row in the plugins page shows a summary and a full page; saving re-schedules
334
352
  immediately without a restart. The same UI is also its own page under
335
353
  **Settings → Plugin updates**, so it is not buried in the plugins page.
336
354
 
337
- `exclude` and `allow` are checkbox lists of the plugins actually installed in this
338
- profile, with their installed versions, instead of two textareas you had to type
339
- package names into. Search narrows the list; Select all / Clear only touch the rows
340
- currently shown, so "search, then select all" means what you expect. A name left in the
341
- allow-list after its package was uninstalled still appears, labelled "not installed",
342
- because otherwise that rule could never be removed.
355
+ `exclude` is a checkbox list of the plugins actually installed in this profile, with
356
+ their installed versions, instead of a textarea you had to type package names into.
357
+ Search narrows the list; Select all / Clear only touch the rows currently shown, so
358
+ "search, then select all" means what you expect.
359
+
360
+ The last run's outcome (when, how many checked, how many updatable, how many installed,
361
+ why it failed) is persisted to `~/.dsh/aupdate-lastrun.json` and survives a restart. It
362
+ used to live in memory only, so every restart reset the card to "never run" and looked
363
+ like nothing had happened.
364
+
365
+ ### Display language
366
+
367
+ The page offers **Display language**: follow the system, 中文, or English. The switch
368
+ applies immediately without a save round-trip, and the choice is stored in
369
+ `~/.dsh/aupdate-settings.json` (key `lang`), so another browser or machine opens the page
370
+ in the same language. Wording only — it changes no update behaviour.
343
371
 
344
372
  ### Update notices
345
373
 
package/client.js CHANGED
@@ -60,7 +60,6 @@ window.__ModuleLoader__.load({
60
60
  firstDelayHint: '分钟,0 表示立刻',
61
61
  exclude: '不自动更新的包',
62
62
  excludeHint: '每行一个包名',
63
- allow: '只更新这些包',
64
63
  allowHint: '每行一个包名;留空表示全部包都参与',
65
64
  allowMajor: '允许跨大版本',
66
65
  allowMajorHint: '关闭后只在同一主版本内升级(0.x 插件多半会因此长期不动)',
@@ -88,8 +87,6 @@ window.__ModuleLoader__.load({
88
87
  notifyHint: '在界面右下角弹一条提醒,列出可更新的插件和「当前 → 新」版本;同一批更新只提醒一次',
89
88
  pkgsExclude: '不自动更新的包',
90
89
  pkgsExcludeHint: '勾上的插件永远不自动更新;一个都不勾表示全部参与自动更新',
91
- pkgsAllow: '只更新这些包',
92
- pkgsAllowHint: '勾上后只更新勾选的插件;一个都不勾表示不启用这条白名单',
93
90
  pkgsSearch: '搜索插件名',
94
91
  pkgsAll: '全选',
95
92
  pkgsNone: '清空',
@@ -98,6 +95,11 @@ window.__ModuleLoader__.load({
98
95
  pkgsNotInstalled: '未安装',
99
96
  pkgsNoMatch: '没有匹配的插件',
100
97
  pageLabel: '插件更新',
98
+ language: '显示语言',
99
+ languageHint: '只换这个设置页和提醒的文案,不改插件的更新行为',
100
+ langAuto: '跟随系统',
101
+ langZh: '中文',
102
+ langEn: 'English',
101
103
  toastTitle: '{n} 个插件可以更新',
102
104
  toastMore: '还有 {n} 个',
103
105
  toastDismiss: '知道了',
@@ -163,7 +165,6 @@ window.__ModuleLoader__.load({
163
165
  firstDelayHint: 'minutes, 0 means immediately',
164
166
  exclude: 'Never auto-update',
165
167
  excludeHint: 'one package name per line',
166
- allow: 'Only update these',
167
168
  allowHint: 'one package name per line; empty means every package',
168
169
  allowMajor: 'Allow major upgrades',
169
170
  allowMajorHint: 'Off keeps upgrades inside one major; 0.x plugins would rarely move',
@@ -191,8 +192,6 @@ window.__ModuleLoader__.load({
191
192
  notifyHint: 'Pops a notice in the bottom-right corner listing the plugins that can update and their current → new versions; each batch is announced once',
192
193
  pkgsExclude: 'Never auto-update',
193
194
  pkgsExcludeHint: 'Checked plugins are never updated automatically; nothing checked means everything takes part',
194
- pkgsAllow: 'Only update these',
195
- pkgsAllowHint: 'When anything is checked, only those plugins update; nothing checked disables this allow-list',
196
195
  pkgsSearch: 'Search plugin names',
197
196
  pkgsAll: 'All',
198
197
  pkgsNone: 'None',
@@ -201,6 +200,11 @@ window.__ModuleLoader__.load({
201
200
  pkgsNotInstalled: 'not installed',
202
201
  pkgsNoMatch: 'Nothing matches',
203
202
  pageLabel: 'Plugin updates',
203
+ language: 'Display language',
204
+ languageHint: 'Changes the wording of this page and its notices, not what the plugin updates',
205
+ langAuto: 'Follow the system',
206
+ langZh: '中文',
207
+ langEn: 'English',
204
208
  toastTitle: '{n} plugin(s) can update',
205
209
  toastMore: 'and {n} more',
206
210
  toastDismiss: 'Got it',
@@ -228,9 +232,50 @@ window.__ModuleLoader__.load({
228
232
  }
229
233
  }
230
234
 
231
- const IS_ZH = detectZh()
232
- const T = IS_ZH ? COPY.zh : COPY.en
233
- const LOCALE = IS_ZH ? 'zh-CN' : 'en-US'
235
+ /**
236
+ * 显示语言。
237
+ *
238
+ * 原来在模块加载时算一次就定死了:中文系统永远中文、英文系统永远英文,用户在
239
+ * 设置页里改不了。现在语言是可变状态——applyLang 换掉 T 并通知所有订阅者重渲染,
240
+ * 选择本身存进设置覆盖层(settings.lang),换个浏览器打开也还是这个选择。
241
+ */
242
+ const AUTOLANG = detectZh() ? 'zh' : 'en'
243
+ const LANG_CHOICES = ['auto', 'zh', 'en']
244
+ let LANG = AUTOLANG
245
+ let LOCALE = LANG === 'zh' ? 'zh-CN' : 'en-US'
246
+ let T = COPY[LANG]
247
+ const langListeners = new Set()
248
+
249
+ /** 把 auto / zh / en 落成实际语言;认不出的值一律当 auto。 */
250
+ function resolveLang(choice) {
251
+ return choice === 'zh' || choice === 'en' ? choice : AUTOLANG
252
+ }
253
+
254
+ function applyLang(choice) {
255
+ const next = resolveLang(choice)
256
+ if (next === LANG) return
257
+ LANG = next
258
+ LOCALE = LANG === 'zh' ? 'zh-CN' : 'en-US'
259
+ T = COPY[LANG]
260
+ for (const listener of langListeners) {
261
+ try { listener() } catch {}
262
+ }
263
+ }
264
+
265
+ /**
266
+ * 订阅语言变化。
267
+ *
268
+ * 每个直接渲染 T 的组件都要调一次:否则切换时只有拿到新状态的组件更新,其余部分
269
+ * 停在旧语言上——一页里中英混排,比不支持切换更难看。
270
+ */
271
+ function useLang() {
272
+ const [, force] = useState(0)
273
+ useEffect(() => {
274
+ const listener = () => force((n) => n + 1)
275
+ langListeners.add(listener)
276
+ return () => { langListeners.delete(listener) }
277
+ }, [])
278
+ }
234
279
 
235
280
  /**
236
281
  * 时间必须先转成浏览器本地时区再显示。
@@ -256,17 +301,31 @@ window.__ModuleLoader__.load({
256
301
  }
257
302
  }
258
303
 
304
+ /**
305
+ * 日志行的时间只到 月-日 时:分:秒。
306
+ *
307
+ * 整条「2026-11-24 09:14:13」占掉一行近四分之一宽度,而日志的重点是内容,
308
+ * 年份在同一个文件里几乎不可能变。缩成短格式后一行能放进更多正文。
309
+ */
310
+ function formatLogWhen(iso) {
311
+ const when = new Date(iso)
312
+ if (Number.isNaN(when.getTime())) return String(iso ?? '')
313
+ const pad = (n) => String(n).padStart(2, '0')
314
+ return pad(when.getMonth() + 1) + '-' + pad(when.getDate()) +
315
+ ' ' + pad(when.getHours()) + ':' + pad(when.getMinutes()) + ':' + pad(when.getSeconds())
316
+ }
317
+
259
318
  /** 「上一次」的光看绝对时间不好判断新鲜度,补一句相对时间。 */
260
319
  function relativeWhen(iso) {
261
320
  const when = new Date(iso)
262
321
  if (Number.isNaN(when.getTime())) return ''
263
322
  const minutes = Math.floor((Date.now() - when.getTime()) / 60000)
264
- if (minutes < 1) return IS_ZH ? '刚刚' : 'just now'
265
- if (minutes < 60) return IS_ZH ? minutes + ' 分钟前' : minutes + ' min ago'
323
+ if (minutes < 1) return LANG === 'zh' ? '刚刚' : 'just now'
324
+ if (minutes < 60) return LANG === 'zh' ? minutes + ' 分钟前' : minutes + ' min ago'
266
325
  const hours = Math.floor(minutes / 60)
267
- if (hours < 24) return IS_ZH ? hours + ' 小时前' : hours + ' h ago'
326
+ if (hours < 24) return LANG === 'zh' ? hours + ' 小时前' : hours + ' h ago'
268
327
  const days = Math.floor(hours / 24)
269
- return IS_ZH ? days + ' 天前' : days + ' d ago'
328
+ return LANG === 'zh' ? days + ' 天前' : days + ' d ago'
270
329
  }
271
330
 
272
331
  function endpoint(name) {
@@ -348,9 +407,11 @@ window.__ModuleLoader__.load({
348
407
  meta: { display: 'flex', gap: '14px', flexWrap: 'wrap', fontSize: '12px', opacity: 0.7 },
349
408
  // 等宽 + 可滚动:日志要能对齐看时间戳,也不能把整页顶长。
350
409
  logBox: { margin: 0, padding: '8px 10px', borderRadius: '6px', border: '1px solid rgba(128,128,128,0.22)', background: 'rgba(128,128,128,0.06)', fontSize: '11.5px', lineHeight: 1.55, fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace', maxHeight: '260px', overflow: 'auto', whiteSpace: 'pre-wrap', wordBreak: 'break-word' },
351
- logTime: { opacity: 0.5 },
410
+ logTime: { opacity: 0.5, flexShrink: 0, fontVariantNumeric: 'tabular-nums' },
352
411
  logText: {},
353
412
  // 勾选清单:包名可能很长(@scope/name),要能截断,版本靠右对齐。
413
+ // 更新记录可能上百条,不封高度会把整页顶到几屏之外,滚动条交还给这一栏。
414
+ scrollList: { display: 'flex', flexDirection: 'column', gap: '8px', maxHeight: '260px', overflowY: 'auto', paddingRight: '4px' },
354
415
  pkgList: { display: 'flex', flexDirection: 'column', gap: '1px', maxHeight: '240px', overflow: 'auto', border: '1px solid rgba(128,128,128,0.22)', borderRadius: '6px', padding: '4px' },
355
416
  pkgRow: { display: 'flex', alignItems: 'center', gap: '8px', padding: '2px 4px', borderRadius: '4px', cursor: 'pointer' },
356
417
  pkgName: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
@@ -477,6 +538,7 @@ window.__ModuleLoader__.load({
477
538
  * 自己填的到底是不是想排除的那个。改成从 /state 拿到的已装清单直接勾。
478
539
  */
479
540
  function PackagePicker(props) {
541
+ useLang()
480
542
  const { packages, selected, onChange } = props
481
543
  const [query, setQuery] = useState('')
482
544
  const chosen = useMemo(() => new Set(Array.isArray(selected) ? selected : []), [selected])
@@ -537,6 +599,7 @@ window.__ModuleLoader__.load({
537
599
  }
538
600
 
539
601
  function AutoUpdateCard() {
602
+ useLang()
540
603
  const [state, setState] = useState(null)
541
604
  const [draft, setDraft] = useState(null)
542
605
  const [phase, setPhase] = useState('loading') // loading | ready | error
@@ -552,6 +615,8 @@ window.__ModuleLoader__.load({
552
615
  setPhase('loading')
553
616
  try {
554
617
  const next = await getState()
618
+ // 语言先落地再渲染:否则第一屏会先按系统语言画一次,再跳成用户选的。
619
+ applyLang(next?.settings?.lang)
555
620
  setState(next)
556
621
  setDraft(next.settings)
557
622
  setPhase('ready')
@@ -569,13 +634,11 @@ window.__ModuleLoader__.load({
569
634
 
570
635
  const dirty = useMemo(() => {
571
636
  if (state === null || draft === null) return false
572
- const keys = ['enabled', 'autoApply', 'hotReload', 'checkOnStart', 'idleOnly', 'notify', 'intervalMinutes', 'firstDelayMinutes', 'allowMajor', 'allowPrerelease', 'scheduleMode', 'dailyAt', 'everyHours', 'everyDays', 'suppressHours', 'maxPerCycle', 'sessionIdleMinutes']
637
+ const keys = ['lang', 'enabled', 'autoApply', 'hotReload', 'checkOnStart', 'idleOnly', 'notify', 'intervalMinutes', 'firstDelayMinutes', 'allowMajor', 'allowPrerelease', 'scheduleMode', 'dailyAt', 'everyHours', 'everyDays', 'suppressHours', 'maxPerCycle', 'sessionIdleMinutes']
573
638
  for (const key of keys) {
574
639
  if (draft[key] !== state.settings[key]) return true
575
640
  }
576
- for (const listKey of ['exclude', 'allow']) {
577
- if (String((draft[listKey] || []).join('\n')) !== String((state.settings[listKey] || []).join('\n'))) return true
578
- }
641
+ if (String((draft.exclude || []).join('\n')) !== String((state.settings.exclude || []).join('\n'))) return true
579
642
  return false
580
643
  }, [state, draft])
581
644
 
@@ -585,6 +648,7 @@ window.__ModuleLoader__.load({
585
648
  setSaveHint('')
586
649
  try {
587
650
  const next = await saveState({
651
+ lang: draft.lang,
588
652
  enabled: draft.enabled,
589
653
  autoApply: draft.autoApply,
590
654
  hotReload: draft.hotReload,
@@ -594,7 +658,6 @@ window.__ModuleLoader__.load({
594
658
  intervalMinutes: draft.intervalMinutes,
595
659
  firstDelayMinutes: draft.firstDelayMinutes,
596
660
  exclude: draft.exclude,
597
- allow: draft.allow,
598
661
  allowMajor: draft.allowMajor,
599
662
  allowPrerelease: draft.allowPrerelease,
600
663
  scheduleMode: draft.scheduleMode,
@@ -605,6 +668,7 @@ window.__ModuleLoader__.load({
605
668
  maxPerCycle: draft.maxPerCycle,
606
669
  sessionIdleMinutes: draft.sessionIdleMinutes,
607
670
  })
671
+ applyLang(next?.settings?.lang)
608
672
  setState(next)
609
673
  setDraft(next.settings)
610
674
  setSaveHint(T.saved + ' · ' + T.savedHint)
@@ -684,6 +748,18 @@ window.__ModuleLoader__.load({
684
748
  h('p', { style: S.sub }, T.subtitle),
685
749
  ),
686
750
  h('div', { style: S.card },
751
+ h(SelectRow, {
752
+ label: T.language,
753
+ hint: T.languageHint,
754
+ value: draft.lang ?? 'auto',
755
+ // 先切文案再落盘:切换要立刻看得见,不能等保存往返。
756
+ onChange: (v) => { patch('lang', v); applyLang(v) },
757
+ options: [
758
+ { value: 'auto', label: T.langAuto },
759
+ { value: 'zh', label: T.langZh },
760
+ { value: 'en', label: T.langEn },
761
+ ],
762
+ }),
687
763
  h(SwitchRow, { label: T.enabled, hint: T.enabledHint, value: draft.enabled, onChange: (v) => patch('enabled', v) }),
688
764
  h(SwitchRow, { label: T.autoApply, hint: T.autoApplyHint, value: draft.autoApply, onChange: (v) => patch('autoApply', v), disabled: !draft.enabled }),
689
765
  h(SwitchRow, { label: T.hotReload, hint: T.hotReloadHint, value: draft.hotReload, onChange: (v) => patch('hotReload', v), disabled: !draft.enabled }),
@@ -733,20 +809,11 @@ window.__ModuleLoader__.load({
733
809
  onChange: (list) => patch('exclude', list),
734
810
  }),
735
811
  ),
736
- // 策略与范围:白名单 / 预发布 / 跨大版本,决定「什么算可以装」。
812
+ // 策略:预发布 / 跨大版本,决定「什么算可以装」。
737
813
  h('div', { style: S.card },
738
814
  h('span', { style: S.label }, T.policy),
739
815
  h(SwitchRow, { label: T.allowMajor, hint: T.allowMajorHint, value: draft.allowMajor, onChange: (v) => patch('allowMajor', v) }),
740
816
  h(SwitchRow, { label: T.allowPrerelease, hint: T.allowPrereleaseHint, value: draft.allowPrerelease, onChange: (v) => patch('allowPrerelease', v) }),
741
- h('div', { style: S.labelBox },
742
- h('span', { style: S.label }, T.pkgsAllow),
743
- h('span', { style: S.hint }, T.pkgsAllowHint),
744
- ),
745
- h(PackagePicker, {
746
- packages: state?.packages,
747
- selected: draft.allow,
748
- onChange: (list) => patch('allow', list),
749
- }),
750
817
  ),
751
818
  h('div', { style: S.actions },
752
819
  h('button', { type: 'button', style: dirty ? S.btnPrimary : S.btn, disabled: !dirty || saving, onClick: () => void save() }, saving ? T.saving : T.save),
@@ -772,7 +839,7 @@ window.__ModuleLoader__.load({
772
839
  h('span', { style: S.label }, T.history),
773
840
  (state?.history?.length ?? 0) === 0
774
841
  ? h('span', { style: S.status }, T.historyEmpty)
775
- : h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
842
+ : h('div', { style: S.scrollList },
776
843
  state.history.map((row, index) => h('div', {
777
844
  key: row.name + '@' + row.at + ':' + index,
778
845
  style: { display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: '10px' },
@@ -807,6 +874,7 @@ window.__ModuleLoader__.load({
807
874
  * 每 5 秒重渲染自己,不该把整张设置卡片连同输入框一起重渲染——那样光标会跳。
808
875
  */
809
876
  function LogCard() {
877
+ useLang()
810
878
  const [lines, setLines] = useState(200)
811
879
  const [data, setData] = useState(null)
812
880
  const [phase, setPhase] = useState('loading') // loading | ready | missing
@@ -861,7 +929,7 @@ window.__ModuleLoader__.load({
861
929
  ? h('span', { style: S.status }, T.logsEmpty)
862
930
  : h('pre', { style: S.logBox, title: data?.path || '' },
863
931
  rows.map((row, index) => h('div', { key: index },
864
- row.at ? h('span', { style: S.logTime }, formatWhen(row.at) + ' ') : null,
932
+ row.at ? h('span', { style: S.logTime }, formatLogWhen(row.at) + ' ') : null,
865
933
  h('span', { style: S.logText }, row.text),
866
934
  )),
867
935
  ),
@@ -879,6 +947,7 @@ window.__ModuleLoader__.load({
879
947
  * summary 只报最关键的一件事——上次检查的结果,别把整页塞进一行。
880
948
  */
881
949
  function AutoUpdateSummary() {
950
+ useLang()
882
951
  const [state, setState] = useState(null)
883
952
  useEffect(() => {
884
953
  let alive = true
package/index.js CHANGED
@@ -32,7 +32,10 @@ const SESSION_IDLE_MINUTES = 2
32
32
  /** 跨进程的安装锁:同一 profile 同时跑两个 pnpm 会抢锁失败。 */
33
33
  const LOCK_STALE_MS = 30 * 60 * 1000
34
34
 
35
- let lastRun = null
35
+ // 上一次运行结果从磁盘恢复。原来是纯内存的,DSH 一重启就没了:设置页明明刚装过
36
+ // 东西,却显示「还没跑过」——那是真的没记住,不是没跑。注意这是在模块加载期调用,
37
+ // 所以只能依赖函数声明(readLastRun/readJson 都提升),不能依赖下面的 const。
38
+ let lastRun = readLastRun()
36
39
  let running = null
37
40
 
38
41
  function oneLine(value, limit = 2000) {
@@ -88,6 +91,31 @@ function flushLog() {
88
91
  }
89
92
  }
90
93
 
94
+ /** 日志里的状态词翻译成人话——面板是给人看的,不留英文状态码。 */
95
+ const STATUS_TEXT = { done: '完成', blocked: '已让开', failed: '失败', skipped: '已跳过', none: '无', ok: '成功' }
96
+
97
+ function statusText(value) {
98
+ return STATUS_TEXT[String(value ?? '')] ?? String(value ?? '')
99
+ }
100
+
101
+ /** 设置页提交的键名,日志里不该出现 enabled,autoApply 这种字面量。 */
102
+ const FIELD_LABELS = {
103
+ enabled: '定时检查', autoApply: '自动安装', hotReload: '就地生效', checkOnStart: '启动先查',
104
+ idleOnly: '忙时不动手', notify: '更新提醒', intervalMinutes: '检查间隔',
105
+ firstDelayMinutes: '首次延迟', exclude: '不更新的包', allowMajor: '跨大版本',
106
+ allowPrerelease: '预发布', scheduleMode: '调度方式', dailyAt: '每天时刻',
107
+ everyHours: '每几小时', everyDays: '每几天', suppressHours: '失败抑制',
108
+ maxPerCycle: '单轮上限', sessionIdleMinutes: '会话静默',
109
+ }
110
+
111
+ function fieldLabel(key) {
112
+ return FIELD_LABELS[key] ?? String(key)
113
+ }
114
+
115
+ function yesNo(value) {
116
+ return value === true ? '开' : '关'
117
+ }
118
+
91
119
  function writeLog(message) {
92
120
  try {
93
121
  console.log('[dsh-aupdate] ' + oneLine(message, 400))
@@ -221,11 +249,13 @@ function settingsPath() {
221
249
  const OVERRIDEABLE = [
222
250
  'enabled', 'autoApply', 'hotReload', 'checkOnStart', 'idleOnly', 'notify',
223
251
  'intervalMinutes', 'firstDelayMinutes', 'exclude',
224
- 'allow', 'allowMajor', 'allowPrerelease',
252
+ 'allowMajor', 'allowPrerelease',
225
253
  // 调度:四种节奏 + 失败抑制时长。这些键不写进 Config schema,
226
254
  // 只活在覆盖层里——Config 的字段类型是宿主校验的,加错一个类型
227
255
  // 会在加载期直接抛错,而覆盖层是我们自己的文件,改坏了只影响这一项。
228
256
  'scheduleMode', 'dailyAt', 'everyHours', 'everyDays', 'suppressHours',
257
+ // 界面显示语言。存这里而不是浏览器里:换台机器、换个浏览器打开,选择还在。
258
+ 'lang',
229
259
  // 效率闸门:一轮最多装几个、会话多静才算闲。
230
260
  'maxPerCycle', 'sessionIdleMinutes',
231
261
  ]
@@ -233,6 +263,19 @@ const OVERRIDEABLE = [
233
263
  /** 四种调度模式。minutes 是原来的「间隔 N 分钟」,其余照抄竞品。 */
234
264
  const SCHEDULE_MODES = ['minutes', 'hours', 'days', 'daily']
235
265
 
266
+ /**
267
+ * 界面语言。auto = 跟随系统(中文环境给中文,其余给英文)。
268
+ *
269
+ * 之所以要存到设置层而不是只留在 localStorage:这个值决定整页文案,
270
+ * 换个浏览器或换台机器打开设置页时,用户不该再选一次。
271
+ */
272
+ const LANG_CHOICES = ['auto', 'zh', 'en']
273
+
274
+ function langOf(config) {
275
+ const text = typeof config?.lang === 'string' ? config.lang.trim().toLowerCase() : ''
276
+ return LANG_CHOICES.includes(text) ? text : 'auto'
277
+ }
278
+
236
279
  /** 数值型覆盖项的边界:写坏了钳进范围,而不是让设置页把插件配废。 */
237
280
  const NUMBER_BOUNDS = {
238
281
  intervalMinutes: [10, 10080],
@@ -278,7 +321,7 @@ function writeOverrides(patch) {
278
321
  for (const key of OVERRIDEABLE) {
279
322
  if (patch === null || typeof patch !== 'object' || patch[key] === undefined) continue
280
323
  const raw = patch[key]
281
- if (key === 'exclude' || key === 'allow') {
324
+ if (key === 'exclude') {
282
325
  next[key] = stringList(raw)
283
326
  continue
284
327
  }
@@ -294,6 +337,11 @@ function writeOverrides(patch) {
294
337
  if (SCHEDULE_MODES.includes(text)) next[key] = text
295
338
  continue
296
339
  }
340
+ if (key === 'lang') {
341
+ const text = typeof raw === 'string' ? raw.trim().toLowerCase() : ''
342
+ if (LANG_CHOICES.includes(text)) next[key] = text
343
+ continue
344
+ }
297
345
  const bounds = NUMBER_BOUNDS[key]
298
346
  if (bounds !== undefined) {
299
347
  const value = typeof raw === 'number' ? raw : Number(raw)
@@ -379,7 +427,6 @@ function settingsOf(config) {
379
427
  intervalMinutes: numberSetting(config, 'intervalMinutes', 1440, 10, 10080),
380
428
  firstDelayMinutes: numberSetting(config, 'firstDelayMinutes', 5, 0, 1440),
381
429
  exclude: stringList(config?.exclude),
382
- allow: stringList(config?.allow),
383
430
  // 默认允许跨大版本:这些都是 0.x 插件,按 semver 卡大版本等于几乎不更新。
384
431
  allowMajor: booleanSetting(config, 'allowMajor', true),
385
432
  // 默认不装预发布。注意:走 next 标签的包(@deepseek-ai/dsh-*)是显式选择,
@@ -387,6 +434,7 @@ function settingsOf(config) {
387
434
  allowPrerelease: booleanSetting(config, 'allowPrerelease', false),
388
435
  // 调度模式:intervalMinutes 只在 minutes 模式下生效,
389
436
  // 其余三种各有自己的参数,切模式不丢原来的值。
437
+ lang: langOf(config),
390
438
  scheduleMode: scheduleModeOf(config),
391
439
  dailyAt: clockOf(config, 'dailyAt', '03:00'),
392
440
  everyHours: numberSetting(config, 'everyHours', 6, 1, 168),
@@ -413,7 +461,6 @@ const FIELDS = {
413
461
  intervalMinutes: { type: 'number', meta: { default: 1440, description: '检查间隔(分钟)' } },
414
462
  firstDelayMinutes: { type: 'number', meta: { default: 5, description: '启动后多久开始第一次' } },
415
463
  exclude: { type: 'array', meta: { default: [], description: '不要自动更新的包' } },
416
- allow: { type: 'array', meta: { default: [], description: '只更新这些包(留空表示全部)' } },
417
464
  allowMajor: { type: 'boolean', meta: { default: true, description: '允许跨大版本更新' } },
418
465
  allowPrerelease: { type: 'boolean', meta: { default: false, description: '允许安装预发布版本' } },
419
466
  }
@@ -421,7 +468,7 @@ const FIELDS = {
421
468
  const DICT = {
422
469
  enabled: 1, autoApply: 2, hotReload: 3, checkOnStart: 4, idleOnly: 5,
423
470
  intervalMinutes: 6, firstDelayMinutes: 7, exclude: 8,
424
- allow: 11, allowMajor: 12, allowPrerelease: 13,
471
+ allowMajor: 12, allowPrerelease: 13,
425
472
  }
426
473
 
427
474
  export const Config = {
@@ -435,7 +482,6 @@ export const Config = {
435
482
  6: FIELDS.intervalMinutes,
436
483
  7: FIELDS.firstDelayMinutes,
437
484
  8: FIELDS.exclude,
438
- 11: FIELDS.allow,
439
485
  12: FIELDS.allowMajor,
440
486
  13: FIELDS.allowPrerelease,
441
487
  10: { type: 'object', meta: { default: {} }, dict: DICT },
@@ -469,6 +515,52 @@ function historyPath() {
469
515
  return join(dirname(settingsPath()), 'aupdate-history.json')
470
516
  }
471
517
 
518
+ /**
519
+ * 上一次运行结果落盘。
520
+ *
521
+ * 「上一次」这张卡是设置页最有用的东西——它告诉你最近一轮什么时候跑、查了多少个、
522
+ * 装成了几个。但它是纯内存状态,DSH 一重启就归零,页面显示「还没跑过」,而磁盘上
523
+ * 明明有刚装好的包。所以照历史表的做法落一份在 ~/.dsh 下。
524
+ *
525
+ * 读的时候按字段逐个校验:这个文件可能是别的版本写的,缺字段就当默认值,
526
+ * 绝不因为一个坏文件让插件加载失败。
527
+ */
528
+ function lastRunPath() {
529
+ return join(dirname(settingsPath()), 'aupdate-lastrun.json')
530
+ }
531
+
532
+ function readLastRun() {
533
+ let raw = null
534
+ try {
535
+ raw = readJson(lastRunPath())
536
+ } catch {
537
+ return null
538
+ }
539
+ if (raw === null || typeof raw !== 'object') return null
540
+ if (typeof raw.at !== 'string' || raw.at === '') return null
541
+ const textList = (value) => (Array.isArray(value) ? value.filter((item) => typeof item === 'string') : [])
542
+ return {
543
+ status: typeof raw.status === 'string' ? raw.status : 'unknown',
544
+ at: raw.at,
545
+ checked: Number.isFinite(raw.checked) ? raw.checked : 0,
546
+ updates: textList(raw.updates),
547
+ installed: textList(raw.installed),
548
+ reload: typeof raw.reload === 'string' ? raw.reload : 'none',
549
+ reason: typeof raw.reason === 'string' ? raw.reason : '',
550
+ snapshot: typeof raw.snapshot === 'string' ? raw.snapshot : '',
551
+ }
552
+ }
553
+
554
+ function saveLastRun(value) {
555
+ try {
556
+ const file = lastRunPath()
557
+ mkdirSync(dirname(file), { recursive: true })
558
+ writeFileSync(file, JSON.stringify(value, null, 2) + '\n', 'utf8')
559
+ } catch {
560
+ // 记不住也不要紧,最坏的结果就是下次重启又显示「还没跑过」,不该影响更新本身。
561
+ }
562
+ }
563
+
472
564
  // 和失败表一样按 mtime+size 判新旧:这个文件也在 ~/.dsh 下跨 profile 共用,
473
565
  // 读到一次就永久缓存会让另一个进程刚写的记录在这边看不见。
474
566
  let historyCache = { stamp: null, value: [] }
@@ -699,19 +791,16 @@ function readJson(file) {
699
791
  }
700
792
 
701
793
  /** 要被检查的依赖:dependencies 里非 link/file 的那些。 */
702
- function dependencyList(profileDir, exclude, allow = []) {
794
+ function dependencyList(profileDir, exclude) {
703
795
  const manifest = readJson(join(profileDir, 'package.json'))
704
796
  const deps = manifest?.dependencies
705
797
  if (deps === null || typeof deps !== 'object') return []
706
798
  const skip = new Set(exclude)
707
- // 白名单非空时就是「只更新这些」;空数组表示不启用白名单。
708
- const only = new Set(allow)
709
799
  const rows = []
710
800
  for (const [pkgName, spec] of Object.entries(deps)) {
711
801
  if (typeof spec !== 'string') continue
712
802
  if (/^(link|file|workspace|portal):/iu.test(spec)) continue
713
803
  if (!NPM_NAME_RE.test(pkgName) || skip.has(pkgName)) continue
714
- if (only.size > 0 && !only.has(pkgName)) continue
715
804
  rows.push({ name: pkgName, spec })
716
805
  }
717
806
  return rows
@@ -720,38 +809,27 @@ function dependencyList(profileDir, exclude, allow = []) {
720
809
  /**
721
810
  * 设置页的勾选清单。
722
811
  *
723
- * dependencyList 会按 exclude/allow 过滤,而那正是勾选框要展示的东西——被排除的包
812
+ * dependencyList 会按 exclude 过滤,而那正是勾选框要展示的东西——被排除的包
724
813
  * 也必须出现在列表里,否则一旦勾上就再也取消不掉。所以这里不过滤,只给每一项
725
- * 标注「当前是否被排除 / 是否在白名单里」,让页面自己决定勾没勾。
726
- *
727
- * 白名单里还可能留着已经卸载的包名(改过 dependencies 之后就会这样)。它们没有
728
- * 对应的勾选项,但不能悄悄丢掉,否则用户再也没有入口删掉这条规则。
814
+ * 标注「当前是否被排除」,让页面自己决定勾没勾。
729
815
  */
730
816
  function packageChoices(profileDir, settings) {
731
817
  const manifest = readJson(join(profileDir, 'package.json'))
732
818
  const deps = manifest?.dependencies
733
819
  if (deps === null || typeof deps !== 'object') return []
734
820
  const skip = new Set(settings.exclude)
735
- const only = new Set(settings.allow)
736
- const known = new Set()
737
821
  const rows = []
738
822
  for (const [name, spec] of Object.entries(deps)) {
739
823
  if (typeof spec !== 'string') continue
740
824
  if (/^(link|file|workspace|portal):/iu.test(spec)) continue
741
825
  if (!NPM_NAME_RE.test(name)) continue
742
- known.add(name)
743
826
  const version = installedVersion(profileDir, name, spec)
744
827
  rows.push({
745
828
  name,
746
829
  version: typeof version === 'string' ? version : '',
747
830
  excluded: skip.has(name),
748
- allowed: only.has(name),
749
831
  })
750
832
  }
751
- for (const name of only) {
752
- if (known.has(name)) continue
753
- rows.push({ name, version: '', excluded: skip.has(name), allowed: true })
754
- }
755
833
  // 不能直接用 localeCompare:它的结果跟着系统区域变,同一个 profile 在不同机器上
756
834
  // 排出来的顺序会不一样,页面顺序跳来跳去会让人以为列表变了。
757
835
  rows.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
@@ -1059,7 +1137,7 @@ function snapshotProfile(profileDir, now) {
1059
1137
  return { dir, files: saved }
1060
1138
  } catch (error) {
1061
1139
  // 留底失败不该拦住更新本身:它只是事后证据,不是前置条件。
1062
- writeLog('snapshot failed: ' + oneLine(error?.message ?? error, 200))
1140
+ writeLog('留快照失败:' + oneLine(error?.message ?? error, 200))
1063
1141
  return null
1064
1142
  }
1065
1143
  }
@@ -1118,7 +1196,7 @@ function takeProfileLock(profileDir, now) {
1118
1196
  } catch {}
1119
1197
  try {
1120
1198
  writeFileSync(file, stamp + '\n', { encoding: 'utf8', flag: 'wx' })
1121
- writeLog('took over a stale install lock (' + ageMinutes + ' min old)')
1199
+ writeLog('接管了一个已挂 ' + ageMinutes + ' 分钟的安装锁')
1122
1200
  return { ok: true, file }
1123
1201
  } catch (error) {
1124
1202
  return { ok: false, reason: '抢锁失败:' + oneLine(error?.message ?? error, 160) }
@@ -1240,7 +1318,7 @@ async function runCycle(mode, ctxRef) {
1240
1318
  try {
1241
1319
  const profileDir = profileDirOf(ctxRef.ctx)
1242
1320
  const profileName = basename(profileDir)
1243
- const deps = dependencyList(profileDir, settings.exclude, settings.allow)
1321
+ const deps = dependencyList(profileDir, settings.exclude)
1244
1322
  report.checked = deps.length
1245
1323
  if (deps.length === 0) {
1246
1324
  report.reason = '这个 profile 里没有可检查的依赖'
@@ -1288,7 +1366,7 @@ async function runCycle(mode, ctxRef) {
1288
1366
  else report.skipped.push(answer)
1289
1367
  }
1290
1368
  }
1291
- writeLog('checked ' + report.checked + ' package(s), ' + report.updates.length + ' update(s) available')
1369
+ writeLog('检查 ' + report.checked + ' 个插件,' + report.updates.length + ' 个可更新')
1292
1370
  if (report.updates.length === 0) {
1293
1371
  report.reason = '没有可更新的插件'
1294
1372
  return report
@@ -1298,7 +1376,7 @@ async function runCycle(mode, ctxRef) {
1298
1376
  const deferred = settings.maxPerCycle > 0 ? report.updates.length - settings.maxPerCycle : 0
1299
1377
  if (deferred > 0) {
1300
1378
  report.updates = report.updates.slice(0, settings.maxPerCycle)
1301
- writeLog('capped this cycle at ' + settings.maxPerCycle + ', ' + deferred + ' left for next round')
1379
+ writeLog('本轮限量装 ' + settings.maxPerCycle + ' 个,剩下 ' + deferred + ' 个下一轮再装')
1302
1380
  }
1303
1381
  if (mode === 'check' || !settings.autoApply) {
1304
1382
  report.reason = '只查不装'
@@ -1313,7 +1391,7 @@ async function runCycle(mode, ctxRef) {
1313
1391
  if (why.length > 0) {
1314
1392
  report.status = 'blocked'
1315
1393
  report.reason = why.join(';') + ',这一轮不安装'
1316
- writeLog('apply skipped: ' + why.join('; '))
1394
+ writeLog('跳过安装:' + why.join(';'))
1317
1395
  return report
1318
1396
  }
1319
1397
  }
@@ -1328,7 +1406,7 @@ async function runCycle(mode, ctxRef) {
1328
1406
  if (!lock.ok) {
1329
1407
  report.status = 'blocked'
1330
1408
  report.reason = lock.reason
1331
- writeLog('apply skipped: ' + lock.reason)
1409
+ writeLog('跳过安装:' + lock.reason)
1332
1410
  return report
1333
1411
  }
1334
1412
  try {
@@ -1336,7 +1414,7 @@ async function runCycle(mode, ctxRef) {
1336
1414
  const snapshot = snapshotProfile(profileDir, new Date())
1337
1415
  if (snapshot !== null) {
1338
1416
  report.snapshot = snapshot.dir
1339
- writeLog('snapshot -> ' + snapshot.dir + ' (' + snapshot.files.join(',') + ')')
1417
+ writeLog('已留快照 ' + snapshot.dir + '(' + snapshot.files.join('、') + ')')
1340
1418
  }
1341
1419
  return await applyUpdates(ctxRef, report, settings, runner, profileDir, profileName)
1342
1420
  } finally {
@@ -1345,7 +1423,7 @@ async function runCycle(mode, ctxRef) {
1345
1423
  } catch (error) {
1346
1424
  report.status = 'failed'
1347
1425
  report.reason = oneLine(error?.message ?? error, 400)
1348
- writeLog('cycle failed: ' + report.reason)
1426
+ writeLog('本轮失败:' + report.reason)
1349
1427
  return report
1350
1428
  } finally {
1351
1429
  report.finishedAt = new Date().toISOString()
@@ -1359,6 +1437,7 @@ async function runCycle(mode, ctxRef) {
1359
1437
  reason: report.reason,
1360
1438
  snapshot: report.snapshot,
1361
1439
  }
1440
+ saveLastRun(lastRun)
1362
1441
  }
1363
1442
  }
1364
1443
 
@@ -1373,7 +1452,7 @@ async function applyUpdates(ctxRef, report, settings, runner, profileDir, profil
1373
1452
  for (const update of ordered) {
1374
1453
  const outcome = await installOne(runner, profileName, profileDir, update.name, update.target)
1375
1454
  report.installed.push(outcome)
1376
- writeLog('install ' + update.name + '@' + update.target + ' -> ' + (outcome.ok ? 'ok' : 'failed: ' + outcome.detail))
1455
+ writeLog('安装 ' + update.name + '@' + update.target + ' → ' + (outcome.ok ? '成功' : '失败:' + outcome.detail))
1377
1456
  if (outcome.ok) {
1378
1457
  clearFailure(update.name, update.target)
1379
1458
  appendHistory({
@@ -1410,7 +1489,7 @@ async function applyUpdates(ctxRef, report, settings, runner, profileDir, profil
1410
1489
  return report
1411
1490
  }
1412
1491
  report.reload = await hotApply(ctxRef.ctx, requiredBefore)
1413
- writeLog('hot apply -> ' + report.reload.status + (report.reload.reason ? ': ' + report.reload.reason : ''))
1492
+ writeLog('就地生效 → ' + statusText(report.reload.status) + (report.reload.reason ? ':' + report.reload.reason : ''))
1414
1493
  report.reason = '已安装 ' + okCount + ' 个;' + (report.reload.reason ?? '')
1415
1494
  if (report.reload.status === 'failed') report.status = 'failed'
1416
1495
  else if (report.reload.status === 'blocked' || report.reload.status === 'restart') report.status = 'partial'
@@ -1473,7 +1552,7 @@ async function rollbackOne(ctxRef, entryName) {
1473
1552
  } finally {
1474
1553
  releaseProfileLock(lock)
1475
1554
  }
1476
- writeLog('rollback ' + row.name + ' ' + row.to + ' -> ' + row.from + ' -> ' + (outcome.ok ? 'ok' : 'failed: ' + outcome.detail))
1555
+ writeLog('回滚 ' + row.name + ' ' + row.to + ' → ' + row.from + ' → ' + (outcome.ok ? '成功' : '失败:' + outcome.detail))
1477
1556
  if (!outcome.ok) return { ok: false, reason: outcome.detail }
1478
1557
  const next = rows.slice()
1479
1558
  next.unshift({
@@ -1557,14 +1636,14 @@ function registerTool(ctx, config) {
1557
1636
  skipped: report.skipped.map((item) => item.name + ':' + item.why),
1558
1637
  }
1559
1638
  } catch (error) {
1560
- writeLog('tool failed: ' + oneLine(error?.message ?? error, 300))
1639
+ writeLog('工具调用失败:' + oneLine(error?.message ?? error, 300))
1561
1640
  return { status: 'failed', reason: '没能完成,插件状态需要核对', checked: 0, updates: [], installed: [], reload: 'none' }
1562
1641
  }
1563
1642
  },
1564
1643
  }), 'dsh-aupdate: plugin_updater')
1565
1644
  return true
1566
1645
  } catch (error) {
1567
- writeLog('cannot offer the tool: ' + oneLine(error?.message ?? error, 300))
1646
+ writeLog('无法提供工具:' + oneLine(error?.message ?? error, 300))
1568
1647
  return false
1569
1648
  }
1570
1649
  }
@@ -1774,12 +1853,12 @@ function registerRoutes(scope, ctxRef) {
1774
1853
  sendJson(res, 500, { error: result.error })
1775
1854
  return
1776
1855
  }
1777
- writeLog('settings updated by page: ' + Object.keys(body).join(','))
1856
+ writeLog('设置页改了:' + Object.keys(body).map(fieldLabel).join('、'))
1778
1857
  // 改完立刻按新设置重排,否则要等下一次触发才换节奏。
1779
1858
  try {
1780
1859
  if (typeof ctxRef.reschedule === 'function') ctxRef.reschedule()
1781
1860
  } catch (error) {
1782
- writeLog('reschedule failed: ' + oneLine(error?.message ?? error, 200))
1861
+ writeLog('重排定时失败:' + oneLine(error?.message ?? error, 200))
1783
1862
  }
1784
1863
  sendJson(res, 200, settingsSnapshot(ctxRef.config, ctxRef))
1785
1864
  return
@@ -1792,7 +1871,7 @@ function registerRoutes(scope, ctxRef) {
1792
1871
  return
1793
1872
  }
1794
1873
  const outcome = await rollbackOne(ctxRef, target)
1795
- writeLog('rollback request ' + target + ' -> ' + (outcome.ok ? 'ok' : 'failed: ' + outcome.reason))
1874
+ writeLog('收到回滚请求 ' + target + ' → ' + (outcome.ok ? '成功' : '失败:' + outcome.reason))
1796
1875
  sendJson(res, outcome.ok ? 200 : 409, outcome)
1797
1876
  return
1798
1877
  }
@@ -1812,7 +1891,7 @@ function registerRoutes(scope, ctxRef) {
1812
1891
  }
1813
1892
  sendJson(res, 405, { error: 'method not allowed' })
1814
1893
  } catch (error) {
1815
- writeLog('route failed: ' + oneLine(error?.message ?? error, 300))
1894
+ writeLog('接口处理出错:' + oneLine(error?.message ?? error, 300))
1816
1895
  try { sendJson(res, 500, { error: 'internal' }) } catch {}
1817
1896
  }
1818
1897
  }
@@ -1821,14 +1900,14 @@ function registerRoutes(scope, ctxRef) {
1821
1900
  const register = () => webServer.register({ kind: 'prefix', path: ROUTE_PREFIX, handler })
1822
1901
  if (typeof effect === 'function') {
1823
1902
  effect.call(scope, register, 'dsh-aupdate: settings routes')
1824
- writeLog('settings route ready: ' + ROUTE_PREFIX)
1903
+ writeLog('设置接口已就绪:' + ROUTE_PREFIX)
1825
1904
  return true
1826
1905
  }
1827
1906
  register()
1828
- writeLog('settings route ready (no effect scope): ' + ROUTE_PREFIX)
1907
+ writeLog('设置接口已就绪(没有 effect 作用域):' + ROUTE_PREFIX)
1829
1908
  return true
1830
1909
  } catch (error) {
1831
- writeLog('cannot register settings route: ' + oneLine(error?.message ?? error, 300))
1910
+ writeLog('无法注册设置接口:' + oneLine(error?.message ?? error, 300))
1832
1911
  return false
1833
1912
  }
1834
1913
  }
@@ -1847,15 +1926,15 @@ export function apply(ctx, config) {
1847
1926
  try {
1848
1927
  const tools = serviceOf(scope, 'tools')
1849
1928
  if (tools === null || typeof tools.register !== 'function') {
1850
- writeLog('tool registered: false')
1929
+ writeLog('工具注册失败')
1851
1930
  return
1852
1931
  }
1853
1932
  if (toolService === tools) return
1854
1933
  toolService = tools
1855
1934
  const ok = registerTool(scope, config)
1856
- writeLog('tool registered: ' + ok)
1935
+ writeLog('工具注册:' + (ok ? '成功' : '失败'))
1857
1936
  } catch (error) {
1858
- writeLog('tool registration threw: ' + oneLine(error?.message ?? error, 300))
1937
+ writeLog('注册工具时抛错:' + oneLine(error?.message ?? error, 300))
1859
1938
  }
1860
1939
  }
1861
1940
  // 路由和工具是同一类问题:apply 执行时 webServer 可能还没就绪,
@@ -1865,14 +1944,14 @@ export function apply(ctx, config) {
1865
1944
  try {
1866
1945
  const webServer = serviceOf(scope, 'webServer')
1867
1946
  if (webServer === null || typeof webServer.register !== 'function') {
1868
- writeLog('webServer unavailable: settings page will report it')
1947
+ writeLog('没有 webServer 服务,设置页会显示不可用')
1869
1948
  return
1870
1949
  }
1871
1950
  if (routeService === webServer) return
1872
1951
  const ok = registerRoutes(scope, ctxRef)
1873
1952
  if (ok) routeService = webServer
1874
1953
  } catch (error) {
1875
- writeLog('route registration threw: ' + oneLine(error?.message ?? error, 300))
1954
+ writeLog('注册设置接口时抛错:' + oneLine(error?.message ?? error, 300))
1876
1955
  }
1877
1956
  }
1878
1957
  const inject = propOf(ctx, 'inject')
@@ -1886,10 +1965,10 @@ export function apply(ctx, config) {
1886
1965
  offerRoutes(scope)
1887
1966
  })
1888
1967
  Promise.resolve(fiber).catch((error) => {
1889
- writeLog('tool scope ended: ' + oneLine(error?.message ?? error, 300))
1968
+ writeLog('工具作用域已结束:' + oneLine(error?.message ?? error, 300))
1890
1969
  })
1891
1970
  } catch (error) {
1892
- writeLog('cannot offer the tool: ' + oneLine(error?.message ?? error, 300))
1971
+ writeLog('无法提供工具:' + oneLine(error?.message ?? error, 300))
1893
1972
  offerTool(ctx)
1894
1973
  offerRoutes(ctx)
1895
1974
  }
@@ -1902,9 +1981,9 @@ export function apply(ctx, config) {
1902
1981
  const go = async () => {
1903
1982
  try {
1904
1983
  const report = await beginningRun(mode, ctxRef)
1905
- if (report !== null) writeLog('cycle ' + mode + ' -> ' + report.status + ': ' + report.reason)
1984
+ if (report !== null) writeLog('本轮' + (mode === 'check' ? '检查' : '更新') + ' → ' + statusText(report.status) + ':' + report.reason)
1906
1985
  } catch (error) {
1907
- writeLog('cycle threw: ' + oneLine(error?.message ?? error, 300))
1986
+ writeLog('本轮抛错:' + oneLine(error?.message ?? error, 300))
1908
1987
  }
1909
1988
  }
1910
1989
  void go()
@@ -1939,7 +2018,7 @@ export function apply(ctx, config) {
1939
2018
  clearScheduled()
1940
2019
  const live = settingsOf(ctxRef.config)
1941
2020
  if (!live.enabled) {
1942
- writeLog('settings say disabled; scheduler parked')
2021
+ writeLog('设置里已关闭自动更新,定时器待命')
1943
2022
  return
1944
2023
  }
1945
2024
  // 启动后第一次仍然只看 firstDelayMinutes,之后按当前调度模式算。
@@ -1973,7 +2052,7 @@ export function apply(ctx, config) {
1973
2052
 
1974
2053
  // 设置页要能读到运行状态并改设置,所以路由最后注册、且与 enabled 无关:
1975
2054
  // 关掉定时检查之后,用户仍然要能看到这一页并把它重新打开。
1976
- if (!settings.enabled) writeLog('disabled by config; scheduler parked, settings page still live')
2055
+ if (!settings.enabled) writeLog('配置里已关闭自动更新,定时器待命,设置页仍然可用')
1977
2056
 
1978
2057
  const stop = () => {
1979
2058
  for (const off of timers.splice(0)) {
@@ -1989,7 +2068,7 @@ export function apply(ctx, config) {
1989
2068
  } catch {}
1990
2069
  }
1991
2070
 
1992
- writeLog('ready: every ' + settings.intervalMinutes + ' min, autoApply=' + settings.autoApply + ', hotReload=' + settings.hotReload)
2071
+ writeLog('已就绪:每 ' + settings.intervalMinutes + ' 分钟检查一次,自动安装=' + yesNo(settings.autoApply) + ',就地生效=' + yesNo(settings.hotReload))
1993
2072
  }
1994
2073
 
1995
2074
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aupdate",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "description": "定时检查 DSH 插件更新,串行安装后就地生效,不重启;支持多种调度节奏、失败抑制、按包回滚,并在动手前留快照、忙时自动让开;不更新/只更新哪些插件改成勾选,发现更新在右下角提醒,日志最新在最上面,并在「设置 → 插件更新」里有独立一页。",
6
6
  "license": "MIT",