dsh-aupdate 0.6.9 → 0.7.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 +15 -2
  2. package/client.js +146 -18
  3. package/index.js +16 -0
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -149,6 +149,13 @@ mtime 为准:那是磁盘事实。会话目录整个读不到时返回「不
149
149
  - 「全选 / 清空」只作用于当前筛选出来的行——搜完再点全选,意思是把搜到的都勾上
150
150
  - 这个 profile 里装着的插件都会列出来,列表本身就是「能勾什么」的全部答案
151
151
 
152
+ ### 关于 aupdate
153
+
154
+ 设置页底部有「关于 aupdate」信息组(照 Bloom 的「关于 Bloom」做):版本号(从 package.json
155
+ 读取,发版不用改前端)、查看更新日志、源码仓库、提交问题,另有「点个星」(打开 GitHub
156
+ stargazers)与「分享」(复制项目地址到剪贴板,任何环境都能用;失败时地址本身也可点开复制)。
157
+ 外链一律 `target=_blank` + `rel=noopener noreferrer`。
158
+
152
159
  ### 「上一次」不会再被重启清空
153
160
 
154
161
  最近一轮的结果(时间、查了多少个、几个可更新、装成几个、失败原因)现在落在
@@ -400,6 +407,12 @@ their installed versions, instead of a textarea you had to type package names in
400
407
  Search narrows the list; Select all / Clear only touch the rows currently shown, so
401
408
  "search, then select all" means what you expect.
402
409
 
410
+ An **About aupdate** group sits at the bottom of the page (modeled on Bloom's About section):
411
+ the version (read from package.json, so releases need no front-end edit), a changelog link,
412
+ source repository, issue tracker, plus Star and Share (copies the project URL; the URL is
413
+ also selectable if the copy fails). External links use target=_blank with
414
+ rel=noopener noreferrer.
415
+
403
416
  The last run's outcome (when, how many checked, how many updatable, how many installed,
404
417
  why it failed) is persisted to `~/.dsh/aupdate-lastrun.json` and survives a restart. It
405
418
  used to live in memory only, so every restart reset the card to "never run" and looked
@@ -445,8 +458,8 @@ The page renders the log newest first, so whatever just happened is at the top o
445
458
  box instead of at the bottom of a scroll. During installation it writes "Installing N/M:
446
459
  <name>" for each package and, past two minutes on any one package, an explicit slow-install
447
460
  notice — pnpm buffers network warnings until the command ends, so there needs to be an
448
- anchor in the meantime. The Last run card polls /state every two seconds while a cycle is
449
- active and shows the same progress live.
461
+ anchor in the meantime. The settings page polls /state every three seconds while it is open, so progress
462
+ from an automatically scheduled cycle shows up too — not only one started by the button.
450
463
 
451
464
  Log lines are stored as an event code plus its arguments, not as finished sentences, so
452
465
  switching **Display language** re-renders history too. Lines written before 0.6.2 are
package/client.js CHANGED
@@ -8,6 +8,17 @@ window.__ModuleLoader__.load({
8
8
  const NS = 'dsh-aupdate'
9
9
  const API = 'api/dsh-aupdate'
10
10
 
11
+ /**
12
+ * 「关于 aupdate」用到的项目链接集中一处。
13
+ *
14
+ * 外链一律 target=_blank + rel=noopener noreferrer:设置页可能跑在受限
15
+ * webview 里,noopener 防止新页反向控制本页。
16
+ */
17
+ const REPO_URL = 'https://github.com/CalmSun/dsh-aupdate'
18
+ const CHANGELOG_URL = REPO_URL + '/releases'
19
+ const ISSUES_URL = REPO_URL + '/issues/new'
20
+ const STARS_URL = REPO_URL + '/stargazers'
21
+
11
22
  const COPY = {
12
23
  zh: {
13
24
  title: '插件自动更新',
@@ -127,6 +138,20 @@ window.__ModuleLoader__.load({
127
138
  policy: '更新策略',
128
139
  minutes: '分钟',
129
140
  scope: '这些设置只影响本机这个 profile',
141
+ about: '关于 aupdate',
142
+ aboutVersion: '版本',
143
+ aboutChangelog: '更新日志',
144
+ aboutChangelogLink: '查看更新日志',
145
+ aboutRepo: '源码仓库',
146
+ aboutFeedback: '反馈问题',
147
+ aboutFeedbackLink: '提交问题',
148
+ aboutStar: '点个星',
149
+ aboutStarHint: '在 GitHub 上点 Star,让更多人看到',
150
+ aboutShare: '分享',
151
+ aboutShareHint: '复制项目地址,分享给朋友',
152
+ aboutShareDone: '项目地址已复制',
153
+ aboutShareFail: '复制失败,请手动复制项目地址',
154
+ aboutProject: '项目地址',
130
155
  },
131
156
  en: {
132
157
  title: 'Plugin auto-update',
@@ -246,6 +271,20 @@ window.__ModuleLoader__.load({
246
271
  policy: 'Update policy',
247
272
  min: 'min',
248
273
  scope: 'These settings apply to this profile only',
274
+ about: 'About aupdate',
275
+ aboutVersion: 'Version',
276
+ aboutChangelog: 'Changelog',
277
+ aboutChangelogLink: 'View changelog',
278
+ aboutRepo: 'Source code',
279
+ aboutFeedback: 'Report an issue',
280
+ aboutFeedbackLink: 'Open an issue',
281
+ aboutStar: 'Star',
282
+ aboutStarHint: 'Star on GitHub to help others find it',
283
+ aboutShare: 'Share',
284
+ aboutShareHint: 'Copy the project link to share',
285
+ aboutShareDone: 'Project link copied',
286
+ aboutShareFail: 'Could not copy; please copy the link manually',
287
+ aboutProject: 'Project URL',
249
288
  },
250
289
  }
251
290
 
@@ -464,6 +503,10 @@ window.__ModuleLoader__.load({
464
503
  pkgName: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
465
504
  pkgVer: { opacity: 0.5, fontSize: '11px', marginLeft: 'auto', flexShrink: 0 },
466
505
  search: { padding: '4px 8px', borderRadius: '6px', border: '1px solid rgba(128,128,128,0.32)', background: 'transparent', color: 'inherit', fontSize: '12.5px' },
506
+ // 「关于」组:外链靠右等宽、↗ 与文字同色但更淡,避免整行像按钮。
507
+ link: { color: 'inherit', textDecoration: 'none', borderBottom: '1px solid rgba(128,128,128,0.4)', paddingBottom: '1px' },
508
+ linkExt: { opacity: 0.5, marginLeft: '3px' },
509
+ ver: { fontVariantNumeric: 'tabular-nums', opacity: 0.8 },
467
510
  }
468
511
 
469
512
  function Toggle(props) {
@@ -645,6 +688,81 @@ window.__ModuleLoader__.load({
645
688
  )
646
689
  }
647
690
 
691
+ /**
692
+ * 「关于 aupdate」信息组。
693
+ *
694
+ * 照 Bloom 设置页的「关于 Bloom」做:版本、更新日志、仓库、反馈四行纯信息,
695
+ * 再加「点个星 / 分享」。版本从 /state 读(随 package.json 变),不写死。
696
+ *
697
+ * 分享用 clipboard 复制项目地址:navigator.share 在桌面 webview 里多半不可用,
698
+ * 而「复制地址」在任何环境都能工作;失败就让用户手动复制,不静默吞掉。
699
+ */
700
+ function AboutCard(props) {
701
+ useLang()
702
+ const [shareHint, setShareHint] = useState('')
703
+ const version = props.version || ''
704
+
705
+ const extLink = (href, label) => h('a', {
706
+ href,
707
+ target: '_blank',
708
+ rel: 'noopener noreferrer',
709
+ style: S.link,
710
+ }, label, h('span', { style: S.linkExt, 'aria-hidden': 'true' }, '↗'))
711
+
712
+ const share = async () => {
713
+ try {
714
+ if (navigator.clipboard?.writeText) {
715
+ await navigator.clipboard.writeText(REPO_URL)
716
+ setShareHint(T.aboutShareDone)
717
+ return
718
+ }
719
+ setShareHint(T.aboutShareFail)
720
+ } catch {
721
+ setShareHint(T.aboutShareFail)
722
+ }
723
+ }
724
+
725
+ return h('div', { style: S.card },
726
+ h('span', { style: S.label }, T.about),
727
+ h('div', { style: S.row },
728
+ h('span', { style: S.label }, T.aboutVersion),
729
+ h('span', { style: S.ver }, version === '' ? '…' : 'v' + version),
730
+ ),
731
+ h('div', { style: S.row },
732
+ h('span', { style: S.label }, T.aboutChangelog),
733
+ extLink(CHANGELOG_URL, T.aboutChangelogLink),
734
+ ),
735
+ h('div', { style: S.row },
736
+ h('span', { style: S.label }, T.aboutRepo),
737
+ extLink(REPO_URL, 'GitHub'),
738
+ ),
739
+ h('div', { style: S.row },
740
+ h('span', { style: S.label }, T.aboutFeedback),
741
+ extLink(ISSUES_URL, T.aboutFeedbackLink),
742
+ ),
743
+ h('div', { style: S.row },
744
+ h('span', { style: S.labelBox },
745
+ h('span', { style: S.label }, T.aboutStar),
746
+ h('span', { style: S.hint }, T.aboutStarHint),
747
+ ),
748
+ extLink(STARS_URL, 'GitHub'),
749
+ ),
750
+ h('div', { style: S.row },
751
+ h('span', { style: S.labelBox },
752
+ h('span', { style: S.label }, T.aboutShare),
753
+ h('span', { style: S.hint }, T.aboutShareHint),
754
+ ),
755
+ h('button', { type: 'button', style: S.btn, onClick: () => void share() }, T.aboutShare),
756
+ ),
757
+ // 项目地址可点开、可选中复制,失败时用户还有这一条路。
758
+ h('div', { style: S.row },
759
+ h('span', { style: S.label }, T.aboutProject),
760
+ extLink(REPO_URL, REPO_URL.replace('https://', '')),
761
+ ),
762
+ shareHint ? h('span', { style: S.status }, shareHint) : null,
763
+ )
764
+ }
765
+
648
766
  function AutoUpdateCard() {
649
767
  useLang()
650
768
  const [state, setState] = useState(null)
@@ -680,6 +798,25 @@ window.__ModuleLoader__.load({
680
798
 
681
799
  useEffect(() => { void load() }, [load])
682
800
 
801
+ // 进度轮询要常驻:更新多数是定时器自动触发的,若只在点「立刻检查」时轮询,
802
+ // 自动跑的那一轮界面上什么也看不到——上次就是这个原因以为进度功能没生效。
803
+ useEffect(() => {
804
+ let alive = true
805
+ const tick = async () => {
806
+ try {
807
+ const next = await getState(LANG)
808
+ if (alive) {
809
+ setProgress(next?.progress ?? null)
810
+ // 别人(定时器 / 另一个窗口)触发的轮次,也把 running 点亮。
811
+ if (next?.progress) setRunning(true)
812
+ }
813
+ } catch {}
814
+ }
815
+ void tick()
816
+ const timer = setInterval(() => { void tick() }, 3000)
817
+ return () => { alive = false; clearInterval(timer) }
818
+ }, [LANG])
819
+
683
820
  /**
684
821
  * 立即保存。
685
822
  *
@@ -736,15 +873,15 @@ window.__ModuleLoader__.load({
736
873
 
737
874
  /** 把后端进度翻成一行中文/英文;没进度就退回普通「正在检查」。 */
738
875
  const runningText = (() => {
739
- if (!running) return ''
740
- if (progress?.phase === 'installing' && progress.total > 0) {
876
+ if (!progress) return ''
877
+ if (progress.phase === 'installing' && progress.total > 0) {
741
878
  return T.progressInstall
742
879
  .replace('{n}', String(progress.index))
743
880
  .replace('{m}', String(progress.total))
744
881
  .replace('{name}', String(progress.name || ''))
745
882
  }
746
- if (progress?.phase === 'applying') return T.progressApply
747
- if (progress?.phase === 'checking') return T.progressCheck
883
+ if (progress.phase === 'applying') return T.progressApply
884
+ if (progress.phase === 'checking') return T.progressCheck
748
885
  return T.running
749
886
  })()
750
887
 
@@ -752,19 +889,9 @@ window.__ModuleLoader__.load({
752
889
  if (running) return
753
890
  setRunning(true)
754
891
  setRunHint(T.running)
755
- setProgress(null)
756
892
  try {
757
- // 点完立刻先读一次进度(后端可能已经在跑),之后每 2 秒跟一次。
758
- const poll = async () => {
759
- try {
760
- setProgress((await getState(LANG))?.progress ?? null)
761
- } catch {}
762
- }
763
- void poll()
764
- const timer = setInterval(() => { void poll() }, 2000)
765
- const result = await (async () => {
766
- try { return await runNow('update') } finally { clearInterval(timer) }
767
- })()
893
+ // 进度由上面的常驻轮询统一负责,这里只发请求。
894
+ const result = await runNow('update')
768
895
  if (result?.started === false) {
769
896
  setRunHint(result.reason || T.runFailed)
770
897
  } else {
@@ -780,7 +907,7 @@ window.__ModuleLoader__.load({
780
907
  setRunHint(T.runFailed)
781
908
  } finally {
782
909
  setRunning(false)
783
- setProgress(null)
910
+ // 不在这里清 progress:常驻轮询会在后端清掉后同步,手动作废会和它打架。
784
911
  }
785
912
  }, [running])
786
913
 
@@ -961,7 +1088,7 @@ window.__ModuleLoader__.load({
961
1088
  h('button', { type: 'button', style: S.btn, disabled: running, onClick: () => void fire() }, running ? T.running : T.runNow),
962
1089
  ),
963
1090
  // 进度单独占一行:安装要几分钟甚至更久,这里明确告诉用户在装第几个。
964
- running && progress
1091
+ progress
965
1092
  ? h('span', { style: { ...S.status, color: '#4c9aff', fontWeight: 500 } }, runningText)
966
1093
  : null,
967
1094
  last === null || last === undefined
@@ -1025,6 +1152,7 @@ window.__ModuleLoader__.load({
1025
1152
  // 没有保存按钮:改动自己在 350ms 后落盘,这里只报它落没落成。
1026
1153
  saveHint ? h('span', { style: S.status }, saveHint) : null,
1027
1154
  h('span', { style: S.hint }, T.scope),
1155
+ h(AboutCard, { version: state?.version }),
1028
1156
  )
1029
1157
  }
1030
1158
 
package/index.js CHANGED
@@ -18,6 +18,20 @@ import { AsyncLocalStorage } from 'node:async_hooks'
18
18
 
19
19
  export const name = 'dsh-aupdate'
20
20
 
21
+ /**
22
+ * 当前插件版本,直接读 package.json。
23
+ *
24
+ * 设置页的「关于 aupdate」要显示版本;写死在 client 里每次发版都得改两处,
25
+ * 还容易忘。这里在模块加载时读一次,发版只改 package.json 就够了。
26
+ */
27
+ let pluginVersion = '0.0.0'
28
+ try {
29
+ const manifest = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'))
30
+ if (typeof manifest.version === 'string' && manifest.version !== '') pluginVersion = manifest.version
31
+ } catch {
32
+ // 读不到就显示 0.0.0,绝不让设置页因为一个版本号加载失败。
33
+ }
34
+
21
35
  const LOG_MAX_BYTES = 1_000_000
22
36
  /** 一次查询里同时在飞的 registry 请求数。 */
23
37
  const FETCH_CONCURRENCY = 6
@@ -2189,6 +2203,8 @@ function settingsSnapshot(config, ctxRef, lang) {
2189
2203
  return {
2190
2204
  settings,
2191
2205
  overrides: readOverrides(),
2206
+ // 「关于 aupdate」显示用;随 package.json 自动更新,无需手改前端。
2207
+ version: pluginVersion,
2192
2208
  // 运行中的进度:没在跑时为 null,设置页据此决定要不要显示进度条。
2193
2209
  progress: progress === null ? null : { ...progress },
2194
2210
  lastRun: lastRun === null ? null : {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aupdate",
3
- "version": "0.6.9",
3
+ "version": "0.7.1",
4
4
  "type": "module",
5
5
  "description": "定时检查 DSH 插件更新,串行安装后就地生效,不重启;支持多种调度节奏、失败抑制、按包回滚,并在动手前留快照、忙时自动让开;不更新/只更新哪些插件改成勾选,发现更新在右下角提醒,日志最新在最上面,并在「设置 → 插件更新」里有独立一页。",
6
6
  "license": "MIT",