dsh-aupdate 0.6.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 +13 -0
  2. package/client.js +79 -8
  3. package/index.js +21 -0
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -141,6 +141,12 @@ mtime 为准:那是磁盘事实。会话目录整个读不到时返回「不
141
141
  「还没跑过」,看着像这一轮根本没跑过。读的时候逐字段校验,坏文件只会让这张卡缺席,
142
142
  不会让插件加载失败。
143
143
 
144
+ ### 显示语言
145
+
146
+ 设置页顶部有「显示语言」:跟随系统 / 中文 / English。切换立即生效,不用等保存往返;
147
+ 选择会存进 `~/.dsh/aupdate-settings.json`(键 `lang`),换个浏览器或换台机器打开设置页
148
+ 还是同一个语言。只影响文案,不改插件的更新行为。
149
+
144
150
  整页最下面是**运行日志**卡片,直接看插件最近写了什么,不用再去翻文件。日志正文用中文写,
145
151
  一行一件事(检查了多少个、装哪个、为什么跳过),状态词也翻成人话;
146
152
 
@@ -356,6 +362,13 @@ why it failed) is persisted to `~/.dsh/aupdate-lastrun.json` and survives a rest
356
362
  used to live in memory only, so every restart reset the card to "never run" and looked
357
363
  like nothing had happened.
358
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.
371
+
359
372
  ### Update notices
360
373
 
361
374
  When a check finds updates, a notice appears in the bottom-right corner listing each
package/client.js CHANGED
@@ -95,6 +95,11 @@ window.__ModuleLoader__.load({
95
95
  pkgsNotInstalled: '未安装',
96
96
  pkgsNoMatch: '没有匹配的插件',
97
97
  pageLabel: '插件更新',
98
+ language: '显示语言',
99
+ languageHint: '只换这个设置页和提醒的文案,不改插件的更新行为',
100
+ langAuto: '跟随系统',
101
+ langZh: '中文',
102
+ langEn: 'English',
98
103
  toastTitle: '{n} 个插件可以更新',
99
104
  toastMore: '还有 {n} 个',
100
105
  toastDismiss: '知道了',
@@ -195,6 +200,11 @@ window.__ModuleLoader__.load({
195
200
  pkgsNotInstalled: 'not installed',
196
201
  pkgsNoMatch: 'Nothing matches',
197
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',
198
208
  toastTitle: '{n} plugin(s) can update',
199
209
  toastMore: 'and {n} more',
200
210
  toastDismiss: 'Got it',
@@ -222,9 +232,50 @@ window.__ModuleLoader__.load({
222
232
  }
223
233
  }
224
234
 
225
- const IS_ZH = detectZh()
226
- const T = IS_ZH ? COPY.zh : COPY.en
227
- 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
+ }
228
279
 
229
280
  /**
230
281
  * 时间必须先转成浏览器本地时区再显示。
@@ -269,12 +320,12 @@ window.__ModuleLoader__.load({
269
320
  const when = new Date(iso)
270
321
  if (Number.isNaN(when.getTime())) return ''
271
322
  const minutes = Math.floor((Date.now() - when.getTime()) / 60000)
272
- if (minutes < 1) return IS_ZH ? '刚刚' : 'just now'
273
- 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'
274
325
  const hours = Math.floor(minutes / 60)
275
- if (hours < 24) return IS_ZH ? hours + ' 小时前' : hours + ' h ago'
326
+ if (hours < 24) return LANG === 'zh' ? hours + ' 小时前' : hours + ' h ago'
276
327
  const days = Math.floor(hours / 24)
277
- return IS_ZH ? days + ' 天前' : days + ' d ago'
328
+ return LANG === 'zh' ? days + ' 天前' : days + ' d ago'
278
329
  }
279
330
 
280
331
  function endpoint(name) {
@@ -487,6 +538,7 @@ window.__ModuleLoader__.load({
487
538
  * 自己填的到底是不是想排除的那个。改成从 /state 拿到的已装清单直接勾。
488
539
  */
489
540
  function PackagePicker(props) {
541
+ useLang()
490
542
  const { packages, selected, onChange } = props
491
543
  const [query, setQuery] = useState('')
492
544
  const chosen = useMemo(() => new Set(Array.isArray(selected) ? selected : []), [selected])
@@ -547,6 +599,7 @@ window.__ModuleLoader__.load({
547
599
  }
548
600
 
549
601
  function AutoUpdateCard() {
602
+ useLang()
550
603
  const [state, setState] = useState(null)
551
604
  const [draft, setDraft] = useState(null)
552
605
  const [phase, setPhase] = useState('loading') // loading | ready | error
@@ -562,6 +615,8 @@ window.__ModuleLoader__.load({
562
615
  setPhase('loading')
563
616
  try {
564
617
  const next = await getState()
618
+ // 语言先落地再渲染:否则第一屏会先按系统语言画一次,再跳成用户选的。
619
+ applyLang(next?.settings?.lang)
565
620
  setState(next)
566
621
  setDraft(next.settings)
567
622
  setPhase('ready')
@@ -579,7 +634,7 @@ window.__ModuleLoader__.load({
579
634
 
580
635
  const dirty = useMemo(() => {
581
636
  if (state === null || draft === null) return false
582
- 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']
583
638
  for (const key of keys) {
584
639
  if (draft[key] !== state.settings[key]) return true
585
640
  }
@@ -593,6 +648,7 @@ window.__ModuleLoader__.load({
593
648
  setSaveHint('')
594
649
  try {
595
650
  const next = await saveState({
651
+ lang: draft.lang,
596
652
  enabled: draft.enabled,
597
653
  autoApply: draft.autoApply,
598
654
  hotReload: draft.hotReload,
@@ -612,6 +668,7 @@ window.__ModuleLoader__.load({
612
668
  maxPerCycle: draft.maxPerCycle,
613
669
  sessionIdleMinutes: draft.sessionIdleMinutes,
614
670
  })
671
+ applyLang(next?.settings?.lang)
615
672
  setState(next)
616
673
  setDraft(next.settings)
617
674
  setSaveHint(T.saved + ' · ' + T.savedHint)
@@ -691,6 +748,18 @@ window.__ModuleLoader__.load({
691
748
  h('p', { style: S.sub }, T.subtitle),
692
749
  ),
693
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
+ }),
694
763
  h(SwitchRow, { label: T.enabled, hint: T.enabledHint, value: draft.enabled, onChange: (v) => patch('enabled', v) }),
695
764
  h(SwitchRow, { label: T.autoApply, hint: T.autoApplyHint, value: draft.autoApply, onChange: (v) => patch('autoApply', v), disabled: !draft.enabled }),
696
765
  h(SwitchRow, { label: T.hotReload, hint: T.hotReloadHint, value: draft.hotReload, onChange: (v) => patch('hotReload', v), disabled: !draft.enabled }),
@@ -805,6 +874,7 @@ window.__ModuleLoader__.load({
805
874
  * 每 5 秒重渲染自己,不该把整张设置卡片连同输入框一起重渲染——那样光标会跳。
806
875
  */
807
876
  function LogCard() {
877
+ useLang()
808
878
  const [lines, setLines] = useState(200)
809
879
  const [data, setData] = useState(null)
810
880
  const [phase, setPhase] = useState('loading') // loading | ready | missing
@@ -877,6 +947,7 @@ window.__ModuleLoader__.load({
877
947
  * summary 只报最关键的一件事——上次检查的结果,别把整页塞进一行。
878
948
  */
879
949
  function AutoUpdateSummary() {
950
+ useLang()
880
951
  const [state, setState] = useState(null)
881
952
  useEffect(() => {
882
953
  let alive = true
package/index.js CHANGED
@@ -254,6 +254,8 @@ const OVERRIDEABLE = [
254
254
  // 只活在覆盖层里——Config 的字段类型是宿主校验的,加错一个类型
255
255
  // 会在加载期直接抛错,而覆盖层是我们自己的文件,改坏了只影响这一项。
256
256
  'scheduleMode', 'dailyAt', 'everyHours', 'everyDays', 'suppressHours',
257
+ // 界面显示语言。存这里而不是浏览器里:换台机器、换个浏览器打开,选择还在。
258
+ 'lang',
257
259
  // 效率闸门:一轮最多装几个、会话多静才算闲。
258
260
  'maxPerCycle', 'sessionIdleMinutes',
259
261
  ]
@@ -261,6 +263,19 @@ const OVERRIDEABLE = [
261
263
  /** 四种调度模式。minutes 是原来的「间隔 N 分钟」,其余照抄竞品。 */
262
264
  const SCHEDULE_MODES = ['minutes', 'hours', 'days', 'daily']
263
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
+
264
279
  /** 数值型覆盖项的边界:写坏了钳进范围,而不是让设置页把插件配废。 */
265
280
  const NUMBER_BOUNDS = {
266
281
  intervalMinutes: [10, 10080],
@@ -322,6 +337,11 @@ function writeOverrides(patch) {
322
337
  if (SCHEDULE_MODES.includes(text)) next[key] = text
323
338
  continue
324
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
+ }
325
345
  const bounds = NUMBER_BOUNDS[key]
326
346
  if (bounds !== undefined) {
327
347
  const value = typeof raw === 'number' ? raw : Number(raw)
@@ -414,6 +434,7 @@ function settingsOf(config) {
414
434
  allowPrerelease: booleanSetting(config, 'allowPrerelease', false),
415
435
  // 调度模式:intervalMinutes 只在 minutes 模式下生效,
416
436
  // 其余三种各有自己的参数,切模式不丢原来的值。
437
+ lang: langOf(config),
417
438
  scheduleMode: scheduleModeOf(config),
418
439
  dailyAt: clockOf(config, 'dailyAt', '03:00'),
419
440
  everyHours: numberSetting(config, 'everyHours', 6, 1, 168),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aupdate",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "description": "定时检查 DSH 插件更新,串行安装后就地生效,不重启;支持多种调度节奏、失败抑制、按包回滚,并在动手前留快照、忙时自动让开;不更新/只更新哪些插件改成勾选,发现更新在右下角提醒,日志最新在最上面,并在「设置 → 插件更新」里有独立一页。",
6
6
  "license": "MIT",