dsh-aupdate 0.4.2 → 0.5.0
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.
- package/README.md +51 -0
- package/client.js +242 -18
- package/index.js +54 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -63,6 +63,7 @@ https://github.com/CalmSun/dsh-aupdate
|
|
|
63
63
|
| `hotReload` | `true` | 装完就地生效,否则等重启 |
|
|
64
64
|
| `maxPerCycle` | `0` | 一轮最多装几个,0 表示不限 |
|
|
65
65
|
| `sessionIdleMinutes` | `2` | 会话静默多少分钟才算闲,0 表示只看子任务 |
|
|
66
|
+
| `notify` | `true` | 发现可更新版本时在右下角提醒,列出插件与版本 |
|
|
66
67
|
|
|
67
68
|
## 什么时候动手
|
|
68
69
|
|
|
@@ -118,11 +119,24 @@ mtime 为准:那是磁盘事实。会话目录整个读不到时返回「不
|
|
|
118
119
|
## 设置页
|
|
119
120
|
|
|
120
121
|
插件页里的这一行有摘要和整页两种视图,保存后立刻按新节奏重排,不用重启。
|
|
122
|
+
同一份界面还挂在**设置 → 插件更新**里,是独立的一页,不用先去插件页翻这张卡。
|
|
121
123
|
读写走 `/api/dsh-aupdate/{state,run,rollback,logs}`。
|
|
122
124
|
|
|
125
|
+
### 勾选插件,而不是手写包名
|
|
126
|
+
|
|
127
|
+
`exclude` / `allow` 原来要一行一个包名地敲。现在整页里是两张勾选清单,直接列出
|
|
128
|
+
这个 profile 实际装着的插件和各自的已装版本:
|
|
129
|
+
|
|
130
|
+
- **不自动更新的包**:勾上的永远不参与自动更新
|
|
131
|
+
- **只更新这些包**:勾上后只更新勾中的;一个都不勾表示不启用这条白名单
|
|
132
|
+
- 能按名字搜索,`/state` 里带着 `packages`(名字、版本、当前是否被排除/在白名单里)
|
|
133
|
+
- 「全选 / 清空」只作用于当前筛选出来的行——搜完再点全选,意思是把搜到的都勾上
|
|
134
|
+
- 白名单里留着已卸载的包名时照样列出来并标「未安装」,否则那条规则再也删不掉
|
|
135
|
+
|
|
123
136
|
整页最下面是**运行日志**卡片,直接看插件最近写了什么,不用再去翻文件:
|
|
124
137
|
|
|
125
138
|
- 可选显示最近 100 / 200 / 500 / 1000 行,默认 200
|
|
139
|
+
- **最新的在最上面**:按时间倒序渲染,刚装了什么不用滚到底
|
|
126
140
|
- 打开「自动刷新」后每 5 秒拉一次,正在排查时开着;关掉就完全不动
|
|
127
141
|
- 读之前会先把待写队列刷下去,所以刚点完检查,那几行马上就在里面
|
|
128
142
|
- 时间戳按本地时区显示,文件超过 1MB 轮转给一句提示,另附总行数
|
|
@@ -135,6 +149,18 @@ mtime 为准:那是磁盘事实。会话目录整个读不到时返回「不
|
|
|
135
149
|
一律 503。不用「只认回环地址」这种判据:浏览器里任何网页都能向 127.0.0.1 发请求。
|
|
136
150
|
`/state` 和 `/logs` 也照样要过,因为它们分别会吐全量设置和读磁盘上的日志文件。
|
|
137
151
|
|
|
152
|
+
## 更新提醒
|
|
153
|
+
|
|
154
|
+
发现可更新版本时,界面右下角浮一条提醒,列出插件名和「当前 → 新」版本;超过 8 条
|
|
155
|
+
时余下给一句「还有 N 个」,15 秒后自动消失。
|
|
156
|
+
|
|
157
|
+
同一批更新只提醒一次:这批更新的签名记在 `localStorage` 里,刷新页面不会重复弹。
|
|
158
|
+
关掉「发现更新时提醒我」就完全不弹,日志和设置页照常记录——提醒只是别让它装完你
|
|
159
|
+
还不知道,不是唯一的告知渠道。
|
|
160
|
+
|
|
161
|
+
提醒用的是原生 DOM 浮层,不是新的槽位:槽位只在宿主页挂载时才渲染,而提醒要能在
|
|
162
|
+
会话、插件页、设置页都出现。
|
|
163
|
+
|
|
138
164
|
## 效率
|
|
139
165
|
|
|
140
166
|
- 只取 dist-tags:24 个包从 2.88 MB 降到 655 B
|
|
@@ -242,6 +268,7 @@ A successful install clears the record.
|
|
|
242
268
|
| `hotReload` | `true` | Apply in place after install instead of waiting for a restart |
|
|
243
269
|
| `maxPerCycle` | `0` | Installs per cycle; 0 means no limit |
|
|
244
270
|
| `sessionIdleMinutes` | `2` | Session must be quiet this long to count as idle; 0 judges by subagents only |
|
|
271
|
+
| `notify` | `true` | Announce available updates in the bottom-right corner, with plugin names and versions |
|
|
245
272
|
|
|
246
273
|
### When it acts
|
|
247
274
|
|
|
@@ -301,6 +328,27 @@ a rollback, collapse into the newest one. Otherwise a single failing version wou
|
|
|
301
328
|
pile up one row per cycle and bury the entry you actually want to return to.
|
|
302
329
|
`1.0 → 1.1` and `1.0 → 1.2` are different events and stay separate.
|
|
303
330
|
|
|
331
|
+
### Settings page
|
|
332
|
+
|
|
333
|
+
The row in the plugins page shows a summary and a full page; saving re-schedules
|
|
334
|
+
immediately without a restart. The same UI is also its own page under
|
|
335
|
+
**Settings → Plugin updates**, so it is not buried in the plugins page.
|
|
336
|
+
|
|
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.
|
|
343
|
+
|
|
344
|
+
### Update notices
|
|
345
|
+
|
|
346
|
+
When a check finds updates, a notice appears in the bottom-right corner listing each
|
|
347
|
+
plugin and its current → new version; past eight it adds "and N more", and it closes
|
|
348
|
+
itself after 15 seconds. Each batch is announced once — the signature is kept in
|
|
349
|
+
`localStorage` — and turning "Tell me when updates are found" off silences it entirely
|
|
350
|
+
while the log and settings page keep recording.
|
|
351
|
+
|
|
304
352
|
### Tool
|
|
305
353
|
|
|
306
354
|
`plugin_updater` with an `action` argument: `check`, `update`, `state`, or `history`.
|
|
@@ -320,6 +368,9 @@ pile up one row per cycle and bury the entry you actually want to return to.
|
|
|
320
368
|
`~/.dsh/aupdate.log`, flushed on write and rotated when it grows. Setting overrides
|
|
321
369
|
live in `~/.dsh/aupdate-settings.json`.
|
|
322
370
|
|
|
371
|
+
The page renders the log newest first, so whatever just happened is at the top of the
|
|
372
|
+
box instead of at the bottom of a scroll.
|
|
373
|
+
|
|
323
374
|
You can read this file straight from the settings page (see above). Point it
|
|
324
375
|
elsewhere with `DSH_AUTO_UPDATE_LOG`.
|
|
325
376
|
|
package/client.js
CHANGED
|
@@ -83,6 +83,24 @@ window.__ModuleLoader__.load({
|
|
|
83
83
|
logsAutoHint: '每 5 秒拉一次,正在排查时开着',
|
|
84
84
|
logsRotated: '日志已超过 1MB,旧内容在 .old 里',
|
|
85
85
|
logsTotal: '共 {n} 行',
|
|
86
|
+
logsNewest: '最新的在最上面',
|
|
87
|
+
notify: '发现更新时提醒我',
|
|
88
|
+
notifyHint: '在界面右下角弹一条提醒,列出可更新的插件和「当前 → 新」版本;同一批更新只提醒一次',
|
|
89
|
+
pkgsExclude: '不自动更新的包',
|
|
90
|
+
pkgsExcludeHint: '勾上的插件永远不自动更新;一个都不勾表示全部参与自动更新',
|
|
91
|
+
pkgsAllow: '只更新这些包',
|
|
92
|
+
pkgsAllowHint: '勾上后只更新勾选的插件;一个都不勾表示不启用这条白名单',
|
|
93
|
+
pkgsSearch: '搜索插件名',
|
|
94
|
+
pkgsAll: '全选',
|
|
95
|
+
pkgsNone: '清空',
|
|
96
|
+
pkgsEmpty: '这个 profile 里没有可自动更新的插件',
|
|
97
|
+
pkgsCount: '已勾选 {n} 个',
|
|
98
|
+
pkgsNotInstalled: '未安装',
|
|
99
|
+
pkgsNoMatch: '没有匹配的插件',
|
|
100
|
+
pageLabel: '插件更新',
|
|
101
|
+
toastTitle: '{n} 个插件可以更新',
|
|
102
|
+
toastMore: '还有 {n} 个',
|
|
103
|
+
toastDismiss: '知道了',
|
|
86
104
|
history: '更新记录',
|
|
87
105
|
historyEmpty: '还没有安装过任何更新',
|
|
88
106
|
rollback: '回滚',
|
|
@@ -168,6 +186,24 @@ window.__ModuleLoader__.load({
|
|
|
168
186
|
logsAutoHint: 'Polls every 5s; turn it on while debugging',
|
|
169
187
|
logsRotated: 'Log passed 1MB; older content is in .old',
|
|
170
188
|
logsTotal: '{n} lines',
|
|
189
|
+
logsNewest: 'newest first',
|
|
190
|
+
notify: 'Tell me when updates are found',
|
|
191
|
+
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
|
+
pkgsExclude: 'Never auto-update',
|
|
193
|
+
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
|
+
pkgsSearch: 'Search plugin names',
|
|
197
|
+
pkgsAll: 'All',
|
|
198
|
+
pkgsNone: 'None',
|
|
199
|
+
pkgsEmpty: 'This profile has no plugins that can auto-update',
|
|
200
|
+
pkgsCount: '{n} selected',
|
|
201
|
+
pkgsNotInstalled: 'not installed',
|
|
202
|
+
pkgsNoMatch: 'Nothing matches',
|
|
203
|
+
pageLabel: 'Plugin updates',
|
|
204
|
+
toastTitle: '{n} plugin(s) can update',
|
|
205
|
+
toastMore: 'and {n} more',
|
|
206
|
+
toastDismiss: 'Got it',
|
|
171
207
|
history: 'Update history',
|
|
172
208
|
historyEmpty: 'No update has been installed yet',
|
|
173
209
|
rollback: 'Roll back',
|
|
@@ -314,6 +350,12 @@ window.__ModuleLoader__.load({
|
|
|
314
350
|
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' },
|
|
315
351
|
logTime: { opacity: 0.5 },
|
|
316
352
|
logText: {},
|
|
353
|
+
// 勾选清单:包名可能很长(@scope/name),要能截断,版本靠右对齐。
|
|
354
|
+
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
|
+
pkgRow: { display: 'flex', alignItems: 'center', gap: '8px', padding: '2px 4px', borderRadius: '4px', cursor: 'pointer' },
|
|
356
|
+
pkgName: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
357
|
+
pkgVer: { opacity: 0.5, fontSize: '11px', marginLeft: 'auto', flexShrink: 0 },
|
|
358
|
+
search: { padding: '4px 8px', borderRadius: '6px', border: '1px solid rgba(128,128,128,0.32)', background: 'transparent', color: 'inherit', fontSize: '12.5px' },
|
|
317
359
|
}
|
|
318
360
|
|
|
319
361
|
function Toggle(props) {
|
|
@@ -427,6 +469,73 @@ window.__ModuleLoader__.load({
|
|
|
427
469
|
)
|
|
428
470
|
}
|
|
429
471
|
|
|
472
|
+
/**
|
|
473
|
+
* 勾选清单。
|
|
474
|
+
*
|
|
475
|
+
* 原来是两个 textarea,让用户一行一个包名敲进去。难用在两处:包名得照着
|
|
476
|
+
* node_modules 手抄,抄错一个字符这条规则就永远不生效、也不会报错;而且看不出
|
|
477
|
+
* 自己填的到底是不是想排除的那个。改成从 /state 拿到的已装清单直接勾。
|
|
478
|
+
*/
|
|
479
|
+
function PackagePicker(props) {
|
|
480
|
+
const { packages, selected, onChange } = props
|
|
481
|
+
const [query, setQuery] = useState('')
|
|
482
|
+
const chosen = useMemo(() => new Set(Array.isArray(selected) ? selected : []), [selected])
|
|
483
|
+
const all = useMemo(() => (Array.isArray(packages) ? packages : []), [packages])
|
|
484
|
+
const rows = useMemo(() => {
|
|
485
|
+
const text = query.trim().toLowerCase()
|
|
486
|
+
if (text === '') return all
|
|
487
|
+
return all.filter((item) => String(item.name).toLowerCase().includes(text))
|
|
488
|
+
}, [all, query])
|
|
489
|
+
|
|
490
|
+
const commit = (next) => onChange(Array.from(next).sort())
|
|
491
|
+
|
|
492
|
+
const toggle = (name) => {
|
|
493
|
+
const next = new Set(chosen)
|
|
494
|
+
if (next.has(name)) next.delete(name)
|
|
495
|
+
else next.add(name)
|
|
496
|
+
commit(next)
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// 全选/清空只作用于当前筛选出来的行:搜索之后再点「全选」,
|
|
500
|
+
// 用户的意思是「把搜到的都勾上」,不是把看不见的也一并改掉。
|
|
501
|
+
const setVisible = (on) => {
|
|
502
|
+
const next = new Set(chosen)
|
|
503
|
+
for (const item of rows) {
|
|
504
|
+
if (on) next.add(item.name)
|
|
505
|
+
else next.delete(item.name)
|
|
506
|
+
}
|
|
507
|
+
commit(next)
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
if (all.length === 0) return h('span', { style: S.status }, T.pkgsEmpty)
|
|
511
|
+
|
|
512
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '6px' } },
|
|
513
|
+
h('div', { style: S.actions },
|
|
514
|
+
h('input', {
|
|
515
|
+
type: 'search',
|
|
516
|
+
value: query,
|
|
517
|
+
placeholder: T.pkgsSearch,
|
|
518
|
+
onChange: (event) => setQuery(event.target.value),
|
|
519
|
+
style: { ...S.search, flex: '1 1 160px' },
|
|
520
|
+
}),
|
|
521
|
+
h('button', { type: 'button', style: S.btn, onClick: () => setVisible(true) }, T.pkgsAll),
|
|
522
|
+
h('button', { type: 'button', style: S.btn, onClick: () => setVisible(false) }, T.pkgsNone),
|
|
523
|
+
h('span', { style: S.hint }, T.pkgsCount.replace('{n}', String(chosen.size))),
|
|
524
|
+
),
|
|
525
|
+
h('div', { style: S.pkgList },
|
|
526
|
+
rows.length === 0
|
|
527
|
+
? h('span', { style: { ...S.status, padding: '4px' } }, T.pkgsNoMatch)
|
|
528
|
+
: rows.map((item) => h('label', { key: item.name, style: S.pkgRow, title: item.name },
|
|
529
|
+
h(Toggle, { checked: chosen.has(item.name), onChange: () => toggle(item.name) }),
|
|
530
|
+
h('span', { style: S.pkgName }, item.name),
|
|
531
|
+
item.version === ''
|
|
532
|
+
? h('span', { style: S.pkgVer }, T.pkgsNotInstalled)
|
|
533
|
+
: h('span', { style: S.pkgVer }, item.version),
|
|
534
|
+
)),
|
|
535
|
+
),
|
|
536
|
+
)
|
|
537
|
+
}
|
|
538
|
+
|
|
430
539
|
function AutoUpdateCard() {
|
|
431
540
|
const [state, setState] = useState(null)
|
|
432
541
|
const [draft, setDraft] = useState(null)
|
|
@@ -460,7 +569,7 @@ window.__ModuleLoader__.load({
|
|
|
460
569
|
|
|
461
570
|
const dirty = useMemo(() => {
|
|
462
571
|
if (state === null || draft === null) return false
|
|
463
|
-
const keys = ['enabled', 'autoApply', 'hotReload', 'checkOnStart', 'idleOnly', 'intervalMinutes', 'firstDelayMinutes', 'allowMajor', 'allowPrerelease', 'scheduleMode', 'dailyAt', 'everyHours', 'everyDays', 'suppressHours', 'maxPerCycle', 'sessionIdleMinutes']
|
|
572
|
+
const keys = ['enabled', 'autoApply', 'hotReload', 'checkOnStart', 'idleOnly', 'notify', 'intervalMinutes', 'firstDelayMinutes', 'allowMajor', 'allowPrerelease', 'scheduleMode', 'dailyAt', 'everyHours', 'everyDays', 'suppressHours', 'maxPerCycle', 'sessionIdleMinutes']
|
|
464
573
|
for (const key of keys) {
|
|
465
574
|
if (draft[key] !== state.settings[key]) return true
|
|
466
575
|
}
|
|
@@ -481,6 +590,7 @@ window.__ModuleLoader__.load({
|
|
|
481
590
|
hotReload: draft.hotReload,
|
|
482
591
|
checkOnStart: draft.checkOnStart,
|
|
483
592
|
idleOnly: draft.idleOnly,
|
|
593
|
+
notify: draft.notify,
|
|
484
594
|
intervalMinutes: draft.intervalMinutes,
|
|
485
595
|
firstDelayMinutes: draft.firstDelayMinutes,
|
|
486
596
|
exclude: draft.exclude,
|
|
@@ -579,6 +689,7 @@ window.__ModuleLoader__.load({
|
|
|
579
689
|
h(SwitchRow, { label: T.hotReload, hint: T.hotReloadHint, value: draft.hotReload, onChange: (v) => patch('hotReload', v), disabled: !draft.enabled }),
|
|
580
690
|
h(SwitchRow, { label: T.checkOnStart, value: draft.checkOnStart, onChange: (v) => patch('checkOnStart', v), disabled: !draft.enabled }),
|
|
581
691
|
h(SwitchRow, { label: T.idleOnly, hint: T.idleOnlyHint, value: draft.idleOnly, onChange: (v) => patch('idleOnly', v), disabled: !draft.enabled }),
|
|
692
|
+
h(SwitchRow, { label: T.notify, hint: T.notifyHint, value: draft.notify, onChange: (v) => patch('notify', v) }),
|
|
582
693
|
),
|
|
583
694
|
h('div', { style: S.card },
|
|
584
695
|
h(SelectRow, {
|
|
@@ -613,15 +724,13 @@ window.__ModuleLoader__.load({
|
|
|
613
724
|
h(NumberRow, { label: T.sessionIdle, hint: T.sessionIdleHint, value: draft.sessionIdleMinutes, min: 0, max: 120, onChange: (v) => patch('sessionIdleMinutes', v), disabled: !draft.enabled || !draft.idleOnly }),
|
|
614
725
|
gateLine(state),
|
|
615
726
|
h('div', { style: S.labelBox },
|
|
616
|
-
h('span', { style: S.label }, T.
|
|
617
|
-
h('span', { style: S.hint }, T.
|
|
727
|
+
h('span', { style: S.label }, T.pkgsExclude),
|
|
728
|
+
h('span', { style: S.hint }, T.pkgsExcludeHint),
|
|
618
729
|
),
|
|
619
|
-
h(
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
onChange: (
|
|
623
|
-
style: S.area,
|
|
624
|
-
spellCheck: false,
|
|
730
|
+
h(PackagePicker, {
|
|
731
|
+
packages: state?.packages,
|
|
732
|
+
selected: draft.exclude,
|
|
733
|
+
onChange: (list) => patch('exclude', list),
|
|
625
734
|
}),
|
|
626
735
|
),
|
|
627
736
|
// 策略与范围:白名单 / 预发布 / 跨大版本,决定「什么算可以装」。
|
|
@@ -630,14 +739,13 @@ window.__ModuleLoader__.load({
|
|
|
630
739
|
h(SwitchRow, { label: T.allowMajor, hint: T.allowMajorHint, value: draft.allowMajor, onChange: (v) => patch('allowMajor', v) }),
|
|
631
740
|
h(SwitchRow, { label: T.allowPrerelease, hint: T.allowPrereleaseHint, value: draft.allowPrerelease, onChange: (v) => patch('allowPrerelease', v) }),
|
|
632
741
|
h('div', { style: S.labelBox },
|
|
633
|
-
h('span', { style: S.label }, T.
|
|
634
|
-
h('span', { style: S.hint }, T.
|
|
742
|
+
h('span', { style: S.label }, T.pkgsAllow),
|
|
743
|
+
h('span', { style: S.hint }, T.pkgsAllowHint),
|
|
635
744
|
),
|
|
636
|
-
h(
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
spellCheck: false,
|
|
745
|
+
h(PackagePicker, {
|
|
746
|
+
packages: state?.packages,
|
|
747
|
+
selected: draft.allow,
|
|
748
|
+
onChange: (list) => patch('allow', list),
|
|
641
749
|
}),
|
|
642
750
|
),
|
|
643
751
|
h('div', { style: S.actions },
|
|
@@ -724,14 +832,16 @@ window.__ModuleLoader__.load({
|
|
|
724
832
|
return () => clearInterval(timer)
|
|
725
833
|
}, [auto])
|
|
726
834
|
|
|
727
|
-
|
|
835
|
+
// 后端按追加顺序给(老的在前面),这里渲染时倒过来:最近发生的事在最上面,
|
|
836
|
+
// 打开这一栏先看到的应该是刚才装了什么,而不是要滚到底才看见。
|
|
837
|
+
const rows = (data?.rows ?? []).slice().reverse()
|
|
728
838
|
const total = data?.total ?? 0
|
|
729
839
|
|
|
730
840
|
return h('div', { style: S.card },
|
|
731
841
|
h('div', { style: S.row },
|
|
732
842
|
h('div', { style: S.labelBox },
|
|
733
843
|
h('span', { style: S.label }, T.logs),
|
|
734
|
-
h('span', { style: S.hint }, T.logsHint),
|
|
844
|
+
h('span', { style: S.hint }, T.logsHint + ' · ' + T.logsNewest),
|
|
735
845
|
),
|
|
736
846
|
h('div', { style: S.actions },
|
|
737
847
|
h('select', {
|
|
@@ -793,9 +903,114 @@ window.__ModuleLoader__.load({
|
|
|
793
903
|
return h('span', { style: { fontSize: '12px', opacity: 0.68 } }, text)
|
|
794
904
|
}
|
|
795
905
|
|
|
906
|
+
/* ── 更新提醒 ────────────────────────────────────────────────────────
|
|
907
|
+
*
|
|
908
|
+
* 定时更新最容易出的事,是它在后台悄悄装完,用户根本不知道装了什么。
|
|
909
|
+
* 这里轮询 /state,发现 lastRun 里有可更新项就在右下角浮一条提醒。
|
|
910
|
+
*
|
|
911
|
+
* 用原生 DOM 而不是再注册一个槽位:提醒要能在任何页面出现(会话、插件页、
|
|
912
|
+
* 设置页),而槽位只在宿主页挂载时才渲染。浮层还得幂等——同一批更新重复弹
|
|
913
|
+
* 三次比不弹更烦,所以把「已提醒过的批次」签名记进 localStorage。
|
|
914
|
+
*/
|
|
915
|
+
const NOTIFIED_KEY = 'dsh-aupdate:notified'
|
|
916
|
+
|
|
917
|
+
function notifiedMark() {
|
|
918
|
+
try { return window.localStorage.getItem(NOTIFIED_KEY) || '' } catch { return '' }
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
function markNotified(sig) {
|
|
922
|
+
try { window.localStorage.setItem(NOTIFIED_KEY, sig) } catch {}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
let toastOpen = false
|
|
926
|
+
|
|
927
|
+
function showUpdateToast(updates) {
|
|
928
|
+
if (toastOpen) return
|
|
929
|
+
const doc = typeof document === 'undefined' ? null : document
|
|
930
|
+
if (doc === null || doc.body === null) return
|
|
931
|
+
toastOpen = true
|
|
932
|
+
const box = doc.createElement('div')
|
|
933
|
+
box.setAttribute('data-dsh-aupdate', 'toast')
|
|
934
|
+
box.style.cssText = [
|
|
935
|
+
'position:fixed', 'right:16px', 'bottom:16px', 'z-index:2147483000',
|
|
936
|
+
'max-width:340px', 'padding:12px 14px', 'border-radius:10px',
|
|
937
|
+
'background:rgba(28,28,30,0.97)', 'color:#f4f4f5',
|
|
938
|
+
'box-shadow:0 8px 28px rgba(0,0,0,0.38)', 'border:1px solid rgba(255,255,255,0.14)',
|
|
939
|
+
'font:13px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif',
|
|
940
|
+
'display:flex', 'flex-direction:column', 'gap:8px',
|
|
941
|
+
].join(';')
|
|
942
|
+
|
|
943
|
+
const title = doc.createElement('div')
|
|
944
|
+
title.textContent = T.toastTitle.replace('{n}', String(updates.length))
|
|
945
|
+
title.style.cssText = 'font-weight:600'
|
|
946
|
+
box.appendChild(title)
|
|
947
|
+
|
|
948
|
+
const list = doc.createElement('div')
|
|
949
|
+
list.style.cssText = 'display:flex;flex-direction:column;gap:3px;max-height:180px;overflow:auto'
|
|
950
|
+
for (const item of updates.slice(0, 8)) {
|
|
951
|
+
const row = doc.createElement('div')
|
|
952
|
+
row.textContent = item.name + ' ' + (item.current || '?') + ' → ' + (item.target || '?')
|
|
953
|
+
row.style.cssText = 'font-size:12px;opacity:0.9;white-space:nowrap;overflow:hidden;text-overflow:ellipsis'
|
|
954
|
+
list.appendChild(row)
|
|
955
|
+
}
|
|
956
|
+
box.appendChild(list)
|
|
957
|
+
|
|
958
|
+
if (updates.length > 8) {
|
|
959
|
+
const more = doc.createElement('div')
|
|
960
|
+
more.textContent = T.toastMore.replace('{n}', String(updates.length - 8))
|
|
961
|
+
more.style.cssText = 'font-size:11.5px;opacity:0.6'
|
|
962
|
+
box.appendChild(more)
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
const close = doc.createElement('button')
|
|
966
|
+
close.type = 'button'
|
|
967
|
+
close.textContent = T.toastDismiss
|
|
968
|
+
close.style.cssText = 'align-self:flex-end;padding:3px 10px;border-radius:6px;border:1px solid rgba(255,255,255,0.25);background:transparent;color:inherit;cursor:pointer;font-size:12px'
|
|
969
|
+
const dismiss = () => {
|
|
970
|
+
toastOpen = false
|
|
971
|
+
try { box.remove() } catch {}
|
|
972
|
+
}
|
|
973
|
+
close.addEventListener('click', dismiss)
|
|
974
|
+
box.appendChild(close)
|
|
975
|
+
doc.body.appendChild(box)
|
|
976
|
+
// 不点也不会一直挂着:15 秒后自己消失,省得挡住下面的界面。
|
|
977
|
+
setTimeout(dismiss, 15000)
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
function startUpdateNotifier() {
|
|
981
|
+
let stopped = false
|
|
982
|
+
let timer = null
|
|
983
|
+
const tick = async () => {
|
|
984
|
+
if (stopped) return
|
|
985
|
+
try {
|
|
986
|
+
const state = await getState()
|
|
987
|
+
if (state?.settings?.notify !== false) {
|
|
988
|
+
const updates = Array.isArray(state?.lastRun?.updates) ? state.lastRun.updates : []
|
|
989
|
+
if (updates.length > 0) {
|
|
990
|
+
const sig = updates.map((item) => item.name + '@' + (item.target || '')).sort().join('|')
|
|
991
|
+
if (sig !== notifiedMark()) {
|
|
992
|
+
markNotified(sig)
|
|
993
|
+
showUpdateToast(updates)
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
} catch {
|
|
998
|
+
// 读不到就等下一轮,提醒失败不该写日志也不该报错。
|
|
999
|
+
}
|
|
1000
|
+
if (!stopped) timer = setTimeout(() => void tick(), 60000)
|
|
1001
|
+
}
|
|
1002
|
+
void tick()
|
|
1003
|
+
return () => {
|
|
1004
|
+
stopped = true
|
|
1005
|
+
if (timer !== null) clearTimeout(timer)
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
796
1009
|
return {
|
|
797
1010
|
inject: ['slots'],
|
|
798
1011
|
apply(ctx) {
|
|
1012
|
+
// 提醒跟着插件一起上、一起卸:ctx.effect 收的是清理函数。
|
|
1013
|
+
if (typeof ctx.effect === 'function') ctx.effect(startUpdateNotifier, 'dsh-aupdate: update notices')
|
|
799
1014
|
// key 的格式是「包名#条目id」:本插件在 cordis.patch.yml 里的条目 id 就是包名本身,
|
|
800
1015
|
// 和 dsh-ops 的 dsh-ops#dsh-ops 一样。写成 #auto-update 之类是挂不上的。
|
|
801
1016
|
ctx.slots.inject('plugins.row.config', () => ctx.slots.register({
|
|
@@ -808,6 +1023,15 @@ window.__ModuleLoader__.load({
|
|
|
808
1023
|
name: 'plugins.bundle.config',
|
|
809
1024
|
key: NS,
|
|
810
1025
|
}, (props) => (props && props.view === 'summary' ? h(AutoUpdateSummary) : h(AutoUpdateCard))))
|
|
1026
|
+
|
|
1027
|
+
// 设置 → 插件更新:挂成独立的一页,写法照抄 dsh-our-free-model-balance-zxp
|
|
1028
|
+
// 的「渠道余额」。原来只有插件页里那张卡,想改策略得先去插件页翻它。
|
|
1029
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
1030
|
+
name: 'settings.section',
|
|
1031
|
+
id: NS,
|
|
1032
|
+
order: 36,
|
|
1033
|
+
label: () => T.pageLabel,
|
|
1034
|
+
}, () => h(AutoUpdateCard)))
|
|
811
1035
|
},
|
|
812
1036
|
}
|
|
813
1037
|
},
|
package/index.js
CHANGED
|
@@ -219,7 +219,7 @@ function settingsPath() {
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
const OVERRIDEABLE = [
|
|
222
|
-
'enabled', 'autoApply', 'hotReload', 'checkOnStart', 'idleOnly',
|
|
222
|
+
'enabled', 'autoApply', 'hotReload', 'checkOnStart', 'idleOnly', 'notify',
|
|
223
223
|
'intervalMinutes', 'firstDelayMinutes', 'exclude',
|
|
224
224
|
'allow', 'allowMajor', 'allowPrerelease',
|
|
225
225
|
// 调度:四种节奏 + 失败抑制时长。这些键不写进 Config schema,
|
|
@@ -373,6 +373,9 @@ function settingsOf(config) {
|
|
|
373
373
|
hotReload: booleanSetting(config, 'hotReload', true),
|
|
374
374
|
checkOnStart: booleanSetting(config, 'checkOnStart', true),
|
|
375
375
|
idleOnly: booleanSetting(config, 'idleOnly', true),
|
|
376
|
+
// 发现可更新版本时是否弹出提醒。默认开着:定时更新最容易出的事,是它一直在
|
|
377
|
+
// 后台装,用户根本不知道装了什么、装到哪一版。
|
|
378
|
+
notify: booleanSetting(config, 'notify', true),
|
|
376
379
|
intervalMinutes: numberSetting(config, 'intervalMinutes', 1440, 10, 10080),
|
|
377
380
|
firstDelayMinutes: numberSetting(config, 'firstDelayMinutes', 5, 0, 1440),
|
|
378
381
|
exclude: stringList(config?.exclude),
|
|
@@ -714,6 +717,47 @@ function dependencyList(profileDir, exclude, allow = []) {
|
|
|
714
717
|
return rows
|
|
715
718
|
}
|
|
716
719
|
|
|
720
|
+
/**
|
|
721
|
+
* 设置页的勾选清单。
|
|
722
|
+
*
|
|
723
|
+
* dependencyList 会按 exclude/allow 过滤,而那正是勾选框要展示的东西——被排除的包
|
|
724
|
+
* 也必须出现在列表里,否则一旦勾上就再也取消不掉。所以这里不过滤,只给每一项
|
|
725
|
+
* 标注「当前是否被排除 / 是否在白名单里」,让页面自己决定勾没勾。
|
|
726
|
+
*
|
|
727
|
+
* 白名单里还可能留着已经卸载的包名(改过 dependencies 之后就会这样)。它们没有
|
|
728
|
+
* 对应的勾选项,但不能悄悄丢掉,否则用户再也没有入口删掉这条规则。
|
|
729
|
+
*/
|
|
730
|
+
function packageChoices(profileDir, settings) {
|
|
731
|
+
const manifest = readJson(join(profileDir, 'package.json'))
|
|
732
|
+
const deps = manifest?.dependencies
|
|
733
|
+
if (deps === null || typeof deps !== 'object') return []
|
|
734
|
+
const skip = new Set(settings.exclude)
|
|
735
|
+
const only = new Set(settings.allow)
|
|
736
|
+
const known = new Set()
|
|
737
|
+
const rows = []
|
|
738
|
+
for (const [name, spec] of Object.entries(deps)) {
|
|
739
|
+
if (typeof spec !== 'string') continue
|
|
740
|
+
if (/^(link|file|workspace|portal):/iu.test(spec)) continue
|
|
741
|
+
if (!NPM_NAME_RE.test(name)) continue
|
|
742
|
+
known.add(name)
|
|
743
|
+
const version = installedVersion(profileDir, name, spec)
|
|
744
|
+
rows.push({
|
|
745
|
+
name,
|
|
746
|
+
version: typeof version === 'string' ? version : '',
|
|
747
|
+
excluded: skip.has(name),
|
|
748
|
+
allowed: only.has(name),
|
|
749
|
+
})
|
|
750
|
+
}
|
|
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
|
+
// 不能直接用 localeCompare:它的结果跟着系统区域变,同一个 profile 在不同机器上
|
|
756
|
+
// 排出来的顺序会不一样,页面顺序跳来跳去会让人以为列表变了。
|
|
757
|
+
rows.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
|
|
758
|
+
return rows
|
|
759
|
+
}
|
|
760
|
+
|
|
717
761
|
/**
|
|
718
762
|
* 已装版本带缓存。
|
|
719
763
|
*
|
|
@@ -1641,6 +1685,15 @@ function settingsSnapshot(config, ctxRef) {
|
|
|
1641
1685
|
reload: lastRun.reload,
|
|
1642
1686
|
snapshot: lastRun.snapshot ?? '',
|
|
1643
1687
|
},
|
|
1688
|
+
// 设置页把已装插件列成勾选框,用户勾就行,不用照着手抄包名。
|
|
1689
|
+
// 每项带上已装版本,勾的时候能看见自己勾的是哪个版本。
|
|
1690
|
+
packages: (() => {
|
|
1691
|
+
try {
|
|
1692
|
+
return packageChoices(profileDirOf(ctxRef?.ctx ?? null), settings)
|
|
1693
|
+
} catch {
|
|
1694
|
+
return []
|
|
1695
|
+
}
|
|
1696
|
+
})(),
|
|
1644
1697
|
path: settingsPath(),
|
|
1645
1698
|
history: readHistory().slice(0, 40),
|
|
1646
1699
|
historyPath: historyPath(),
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-aupdate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "定时检查 DSH
|
|
5
|
+
"description": "定时检查 DSH 插件更新,串行安装后就地生效,不重启;支持多种调度节奏、失败抑制、按包回滚,并在动手前留快照、忙时自动让开;不更新/只更新哪些插件改成勾选,发现更新在右下角提醒,日志最新在最上面,并在「设置 → 插件更新」里有独立一页。",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|