dsh-go-plugin-sync 0.3.6 → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0 — 2026-12-04
4
+
5
+ 0.3.10 之后的功能合并发布(npm 从 0.3.6 直接到本版)。
6
+
7
+ ### 新增
8
+ - 电脑端设置页:补回「复制同步码」按钮,把本机插件导出为 `DSHSYNC1` 同步码并写入剪贴板,剪贴板不可用时填入下方文本框
9
+ - 安装成功后提示“新插件需重启 DSH 后才会加载”;底部新增「日志尾部」折叠
10
+
11
+ ### dsh-go 面板
12
+ - 任务运行中显示进度:当前项、已处理 x / 总数、失败数、已用时间
13
+ - 默认只列待处理插件,已安装项折叠为“已安装 N 个”,可切「显示全部 / 只看待处理」
14
+ - 新增「清空清单」,清掉导入的清单后可重新导入同步码或拉取中转
15
+
16
+ ## 0.3.12 — 2026-12-04
17
+
18
+ ### 新增 / 改进
19
+ - dsh-go 面板:任务运行中显示进度(当前项、已处理 x / 总数、失败数、已用时间),点「刷新」即可看最新状态
20
+ - dsh-go 面板:默认只列待处理插件,已安装项折叠为“已安装 N 个”,可切「显示全部 / 只看待处理」
21
+ - dsh-go 面板:新增「清空清单」,清掉导入的清单,可重新导入同步码或拉取中转
22
+ - 电脑端:安装成功后提示“新插件需重启 DSH 后才会加载”;底部新增「日志尾部」折叠,便于排查
23
+
24
+ ## 0.3.11 — 2026-12-04
25
+
26
+ ### 修复
27
+ - 设置页补回“复制同步码”按钮:把本机插件导出为 `DSHSYNC1` 同步码,优先复制到剪贴板;剪贴板不可用时自动填入下方文本框并全选,按 Ctrl+C 即可复制
28
+
3
29
  ## 0.3.10 — 2026-12-04
4
30
 
5
31
  ### 改进
package/lib/client.js CHANGED
@@ -59,6 +59,7 @@ window.__ModuleLoader__.load({
59
59
  function SyncSettings() {
60
60
  const [rows, setRows] = React.useState([])
61
61
  const [results, setResults] = React.useState([])
62
+ const [log, setLog] = React.useState([])
62
63
  const [picked, setPicked] = React.useState({})
63
64
  const [code, setCode] = React.useState('')
64
65
  const [config, setConfig] = React.useState(null)
@@ -71,6 +72,7 @@ window.__ModuleLoader__.load({
71
72
  const [cleared, setCleared] = React.useState(false)
72
73
  const [queue, setQueue] = React.useState(null)
73
74
  const wasRunning = React.useRef(false)
75
+ const codeRef = React.useRef(null)
74
76
 
75
77
  const note = (text, kind) => { setStatus(text); setTone(kind || '') }
76
78
 
@@ -79,6 +81,7 @@ window.__ModuleLoader__.load({
79
81
  setRows(snapshot.rows || [])
80
82
  setCleared(Boolean(snapshot.cleared))
81
83
  setResults(snapshot.results || [])
84
+ setLog(snapshot.log || [])
82
85
  setConfig(snapshot.config || null)
83
86
  setConfigPath(snapshot.configPath || '')
84
87
  const next = {}
@@ -90,6 +93,7 @@ window.__ModuleLoader__.load({
90
93
  React.useEffect(() => {
91
94
  const tick = () => api('status').then((snapshot) => {
92
95
  if (snapshot.results) setResults(snapshot.results)
96
+ if (snapshot.log) setLog(snapshot.log)
93
97
  setTask(snapshot.task || null)
94
98
  setCurrent(snapshot.current || null)
95
99
  if (!snapshot.task) return
@@ -145,6 +149,28 @@ window.__ModuleLoader__.load({
145
149
  load()
146
150
  }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
147
151
  }
152
+ const copyCode = () => {
153
+ setBusy(true)
154
+ api('export', {}).then((result) => {
155
+ setBusy(false)
156
+ if (result.error) { note(result.error, 'bad'); return }
157
+ setCode(result.code)
158
+ const summary = T(
159
+ `同步码已生成(${result.count} 个插件${result.withFiles ? ',含文件' : ''})`,
160
+ `Sync code generated (${result.count} plugins${result.withFiles ? ', with files' : ''})`
161
+ )
162
+ const fallback = () => {
163
+ try { codeRef.current?.focus(); codeRef.current?.select() } catch {}
164
+ note(summary + T(',已填入下方文本框,按 Ctrl+C 复制', ' — filled below, press Ctrl+C to copy'), 'good')
165
+ }
166
+ if (navigator.clipboard && navigator.clipboard.writeText) {
167
+ navigator.clipboard.writeText(result.code).then(
168
+ () => note(summary + T(',已复制到剪贴板', ' — copied to clipboard'), 'good'),
169
+ fallback,
170
+ )
171
+ } else fallback()
172
+ }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
173
+ }
148
174
  const applySelected = () => {
149
175
  const names = rows.filter((row) => row.action && picked[row.name]).map((row) => row.name)
150
176
  if (names.length === 0) { note(T('先选择要安装的插件', 'Select plugins to install'), 'bad'); return }
@@ -240,13 +266,15 @@ window.__ModuleLoader__.load({
240
266
  h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
241
267
  h('div', { style: { fontWeight: 600 } }, T('同步码', 'Sync code')),
242
268
  h('textarea', {
269
+ ref: codeRef,
243
270
  value: code,
244
271
  rows: 4,
245
272
  placeholder: 'DSHSYNC1:…',
246
273
  onChange: (event) => setCode(event.target.value),
247
274
  style: { ...INPUT, fontFamily: 'ui-monospace, monospace', minHeight: '80px', resize: 'vertical' },
248
275
  }),
249
- h('div', { style: { display: 'flex', gap: '8px' } },
276
+ h('div', { style: { display: 'flex', gap: '8px', flexWrap: 'wrap' } },
277
+ h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: copyCode }, T('复制同步码', 'Copy sync code')),
250
278
  h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: importCode }, T('导入同步码', 'Import code')),
251
279
  h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: load }, T('刷新', 'Refresh')))),
252
280
 
@@ -278,6 +306,14 @@ window.__ModuleLoader__.load({
278
306
  style: { fontSize: '12px', color: item.ok ? '#2e7d32' : '#c62828', wordBreak: 'break-word' },
279
307
  }, `${item.ok ? '✓' : '✗'} ${item.name}${item.message ? ` — ${item.message}` : ''}`))),
280
308
 
309
+ task && !task.running && task.ok && results.some((item) => item.ok && item.action === 'install') &&
310
+ h('div', { style: { fontSize: '13px', color: '#1565c0' } },
311
+ T('新插件需重启 DSH 后才会加载(完全退出再启动)', 'New plugins load after a full DSH restart.')),
312
+
313
+ log.length > 0 && h('details', { style: { fontSize: '13px' } },
314
+ h('summary', { style: { cursor: 'pointer', opacity: 0.7 } }, T('日志尾部', 'Log tail')),
315
+ h('pre', { style: { fontSize: '11px', opacity: 0.75, whiteSpace: 'pre-wrap', wordBreak: 'break-all', margin: '6px 0 0' } }, log.join('\n'))),
316
+
281
317
  h('div', { style: { borderTop: '1px solid rgba(128,128,128,.2)', paddingTop: '12px' } },
282
318
  h('div', { style: { fontWeight: 600, marginBottom: '4px' } }, T('Git 中转(可选)', 'Git relay (optional)')),
283
319
  h(Field, { label: T('仓库地址', 'Repository'), value: relay.repo, onChange: (value) => setPath('relay.repo', value), placeholder: 'https://gitee.com/you/dsh-plugins.git' }),
package/lib/index.js CHANGED
@@ -73,6 +73,7 @@ const taskRunnerPath = () => join(storeDir(), 'task-runner.cjs')
73
73
  const taskSpecPath = () => join(storeDir(), 'task-spec.json')
74
74
  const taskLogPath = () => join(storeDir(), 'task.log')
75
75
  const taskStatusPath = () => join(storeDir(), 'task-status.txt')
76
+ const taskTotalPath = () => join(storeDir(), 'task-total.txt')
76
77
 
77
78
  function readJson(path) {
78
79
  try { return JSON.parse(readFileSync(path, 'utf8')) } catch { return undefined }
@@ -275,6 +276,7 @@ function applySyncCode(scope, text, sourceName, host = {}) {
275
276
  state.manifestSource = { kind: 'code' }
276
277
  state.importedAt = new Date().toISOString()
277
278
  state.sourceName = sourceName
279
+ state.showAll = false
278
280
  persistImported(state)
279
281
  resetUiState()
280
282
  writeCodeFiles(decoded)
@@ -634,6 +636,7 @@ function loadImported() {
634
636
  importedAt: typeof raw?.importedAt === 'string' ? raw.importedAt : null,
635
637
  sourceName: typeof raw?.sourceName === 'string' ? raw.sourceName.slice(0, 120) : null,
636
638
  selected: new Set(),
639
+ showAll: false,
637
640
  lastExportPath: null,
638
641
  lastPastedCode: null,
639
642
  relayLoadedAt: 0,
@@ -679,6 +682,7 @@ function refreshManifests(state, cfg) {
679
682
  state.manifestSource = relay.source
680
683
  state.importedAt = relay.manifest.exportedAt
681
684
  state.sourceName = 'Git 中转'
685
+ state.showAll = false
682
686
  state.relayLoadedAt = relay.mtime
683
687
  state.selected.clear()
684
688
  }
@@ -688,6 +692,7 @@ function refreshManifests(state, cfg) {
688
692
  state.manifestSource = ssh.source
689
693
  state.importedAt = ssh.manifest.exportedAt
690
694
  state.sourceName = 'SSH 远端'
695
+ state.showAll = false
691
696
  state.sshLoadedAt = ssh.mtime
692
697
  state.selected.clear()
693
698
  }
@@ -764,6 +769,24 @@ function readTaskResults() {
764
769
 
765
770
  // ---------------------------------------------------------------- task runner
766
771
 
772
+ /** How many items the current/last task planned to process (0 when unknown). */
773
+ function readTaskTotal() {
774
+ try {
775
+ const count = Number(readFileSync(taskTotalPath(), 'utf8').trim())
776
+ return Number.isFinite(count) && count > 0 ? count : 0
777
+ } catch {
778
+ return 0
779
+ }
780
+ }
781
+
782
+ /** "12 秒" / "2 分 05 秒" — coarse on purpose; progress refreshes on demand. */
783
+ function elapsedText(seconds, en) {
784
+ if (seconds < 60) return en ? `${seconds}s` : `${seconds} 秒`
785
+ const minutes = Math.floor(seconds / 60)
786
+ const rest = seconds % 60
787
+ return en ? `${minutes}m${rest}s` : `${minutes} 分 ${rest} 秒`
788
+ }
789
+
767
790
  function taskRunning() {
768
791
  const status = readTaskStatus()
769
792
  return Boolean(status?.running && Date.now() - status.startedAt < 15 * 60 * 1000)
@@ -773,6 +796,7 @@ function taskRunning() {
773
796
  function startTask(kind, lines, win) {
774
797
  if (taskRunning()) return { ok: false, error: '已有任务在运行,等它结束再试' }
775
798
  ensureStore()
799
+ try { writeFileSync(taskTotalPath(), '0\n') } catch {}
776
800
  if (process.platform === 'win32') return startWindowsTask(kind, win)
777
801
  const script = [
778
802
  '#!/bin/sh',
@@ -944,6 +968,7 @@ function startInstallTask(ctx, jobs) {
944
968
  if (!manager || typeof manager.installBundle !== 'function') return null
945
969
  if (taskRunning()) return { ok: false, error: '已有任务在运行,等它结束再试' }
946
970
  ensureStore()
971
+ try { writeFileSync(taskTotalPath(), '0\n') } catch {}
947
972
  writeFileSync(taskLogPath(), '')
948
973
  writeFileSync(taskStatusPath(), `running ${Math.floor(Date.now() / 1000)} apply\n`)
949
974
  const installs = jobs.filter((job) => job.action === 'install')
@@ -999,11 +1024,17 @@ function startInstallTask(ctx, jobs) {
999
1024
 
1000
1025
  /** Prefer the plugin manager for pure installs; keep the shell path for SSH push/pull. */
1001
1026
  function startApplyTask(ctx, cfg, jobs) {
1027
+ const writeTotal = () => { try { writeFileSync(taskTotalPath(), `${jobs.length}\n`) } catch {} }
1002
1028
  if (jobs.every((job) => job.action === 'install')) {
1003
1029
  const started = startInstallTask(ctx, jobs)
1004
- if (started) return started
1030
+ if (started) {
1031
+ if (started.ok) writeTotal()
1032
+ return started
1033
+ }
1005
1034
  }
1006
- return startTask('apply', buildApply(cfg, jobs), winTask(jobs))
1035
+ const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
1036
+ if (started.ok) writeTotal()
1037
+ return started
1007
1038
  }
1008
1039
 
1009
1040
  /** One result-reporting item: start marker, commands, ok/fail marker. */
@@ -1386,9 +1417,20 @@ function buildView(scope, caps, ctx) {
1386
1417
  const task = readTaskStatus()
1387
1418
  if (task?.running) {
1388
1419
  const stale = Date.now() - task.startedAt > 15 * 60 * 1000
1420
+ const current = readTaskCurrent()
1421
+ const done = readTaskResults().length
1422
+ const failedSoFar = readTaskResults().filter((result) => !result.ok).length
1423
+ const total = readTaskTotal()
1424
+ const elapsed = elapsedText(Math.max(0, Math.floor((Date.now() - task.startedAt) / 1000)), en)
1425
+ const progressText = [
1426
+ current ? (en ? `processing ${current.name}` : `正在处理 ${current.name}`) : '',
1427
+ en ? `done ${done}${total ? ` / ${total}` : ''}` : `已处理 ${done}${total ? ` / ${total}` : ''}`,
1428
+ failedSoFar > 0 ? (en ? `${failedSoFar} failed` : `失败 ${failedSoFar}`) : '',
1429
+ en ? `elapsed ${elapsed}` : `已用 ${elapsed}`,
1430
+ ].filter(Boolean).join(' · ')
1389
1431
  children.push({ type: 'callout', tone: stale ? 'warn' : 'info', text: stale
1390
- ? (en ? 'A task started long ago; check the log.' : '任务开始很久了,看下日志。')
1391
- : (en ? `${taskLabel(task.kind, true)} running…` : `正在${taskLabel(task.kind, false)}…`) })
1432
+ ? (en ? `${taskLabel(task.kind, true)} running too long (${progressText}); check the log.` : `${taskLabel(task.kind, false)}运行太久(${progressText}),看下日志。`)
1433
+ : (en ? `${taskLabel(task.kind, true)} running: ${progressText}` : `${taskLabel(task.kind, false)}中:${progressText}`) })
1392
1434
  } else if (task && task.ok === false) {
1393
1435
  children.push({ type: 'callout', tone: 'bad', text: en
1394
1436
  ? `${taskLabel(task.kind, true)} failed (${task.failed}). Check the log.`
@@ -1443,23 +1485,36 @@ function buildView(scope, caps, ctx) {
1443
1485
  ? `Manifest: ${source || 'imported'}${when ? ` · ${when}` : ''}`
1444
1486
  : `清单来源:${source || '已导入'}${when ? ` · ${when}` : ''}` })
1445
1487
 
1488
+ const pending = rows.filter((row) => row.status !== 'same')
1489
+ const installed = rows.filter((row) => row.status === 'same')
1490
+ const visible = state.showAll ? rows : pending
1446
1491
  if (rows.length === 0) {
1447
1492
  children.push({ type: 'callout', tone: 'good', text: en ? 'The two hosts match.' : '两边完全一致。' })
1448
1493
  } else {
1449
- const shown = rows.slice(0, 40)
1450
- children.push({ type: 'list', items: shown.map((row) => {
1451
- const item = {
1452
- title: row.name,
1453
- subtitle: statusLine(row, en),
1454
- trailing: state.selected.has(row.name) ? '✓' : '○',
1455
- action: { id: 'toggle', args: { name: row.name } },
1456
- }
1457
- const tone = statusTone(row.status)
1458
- if (tone) item.tone = tone
1459
- return item
1460
- }) })
1461
- if (rows.length > shown.length) {
1462
- children.push({ type: 'text', text: en ? `…and ${rows.length - shown.length} more` : `…还有 ${rows.length - shown.length} 项` })
1494
+ if (pending.length === 0) {
1495
+ children.push({ type: 'callout', tone: 'good', text: en ? 'Nothing pending; everything is in sync.' : '没有待处理项,已全部一致。' })
1496
+ }
1497
+ const shown = visible.slice(0, 40)
1498
+ if (shown.length > 0) {
1499
+ children.push({ type: 'list', items: shown.map((row) => {
1500
+ const item = {
1501
+ title: row.name,
1502
+ subtitle: statusLine(row, en),
1503
+ trailing: state.selected.has(row.name) ? '✓' : '○',
1504
+ action: { id: 'toggle', args: { name: row.name } },
1505
+ }
1506
+ const tone = statusTone(row.status)
1507
+ if (tone) item.tone = tone
1508
+ return item
1509
+ }) })
1510
+ }
1511
+ if (visible.length > shown.length) {
1512
+ children.push({ type: 'text', text: en ? `…and ${visible.length - shown.length} more` : `…还有 ${visible.length - shown.length} 项` })
1513
+ }
1514
+ if (!state.showAll && installed.length > 0) {
1515
+ children.push({ type: 'text', text: en
1516
+ ? `${installed.length} already installed (tap "Show all" to view)`
1517
+ : `已安装 ${installed.length} 个(点「显示全部」查看)` })
1463
1518
  }
1464
1519
  }
1465
1520
 
@@ -1469,6 +1524,7 @@ function buildView(scope, caps, ctx) {
1469
1524
  { label: en ? 'Copy code' : '复制同步码', action: 'copy-code' },
1470
1525
  { label: en ? 'Select all' : '全选', action: 'select-all' },
1471
1526
  { label: en ? 'Clear' : '清空', action: 'clear' },
1527
+ { label: state.showAll ? (en ? 'Pending only' : '只看待处理') : (en ? 'Show all' : '显示全部'), action: 'toggle-show-all' },
1472
1528
  { label: en ? 'Refresh' : '刷新', action: 'refresh' },
1473
1529
  ]
1474
1530
  children.push({ type: 'actions', items: primary })
@@ -1477,6 +1533,7 @@ function buildView(scope, caps, ctx) {
1477
1533
  { label: en ? 'Retry failed' : '重试失败', action: 'retry-failed' },
1478
1534
  { label: en ? 'Export' : '导出清单', action: 'export' },
1479
1535
  { label: en ? 'Read workspace' : '工作区导入', action: 'import-workspace' },
1536
+ { label: en ? 'Clear list' : '清空清单', action: 'clear-all' },
1480
1537
  { label: en ? 'Guide' : '使用引导', action: 'guide' },
1481
1538
  ] })
1482
1539
 
@@ -1630,6 +1687,7 @@ function webSnapshot(ctx) {
1630
1687
  cleared,
1631
1688
  task: readTaskStatus(),
1632
1689
  results: readTaskResults(),
1690
+ log: readLogTail(3),
1633
1691
  config: cfg,
1634
1692
  configPath: configPathFor(ctx, scope),
1635
1693
  }
@@ -1840,6 +1898,23 @@ export function apply(ctx) {
1840
1898
  'ssh-scan': sshScan,
1841
1899
  'retry-failed': retryFailed,
1842
1900
 
1901
+ 'toggle-show-all'(scope) {
1902
+ const state = stateFor(scope)
1903
+ state.showAll = !state.showAll
1904
+ return { refresh: true }
1905
+ },
1906
+
1907
+ 'clear-all'(scope) {
1908
+ const state = stateFor(scope)
1909
+ state.manifest = null
1910
+ state.manifestSource = null
1911
+ state.sourceName = null
1912
+ state.importedAt = null
1913
+ state.selected.clear()
1914
+ try { unlinkSync(importFile()) } catch {}
1915
+ return [{ toast: '已清空清单,可重新导入同步码或拉取中转' }, { refresh: true }]
1916
+ },
1917
+
1843
1918
  guide() {
1844
1919
  return { open: 'panel:guide' }
1845
1920
  },
@@ -1916,6 +1991,7 @@ export function apply(ctx) {
1916
1991
  state.manifestSource = { kind: kind || 'file' }
1917
1992
  state.importedAt = new Date().toISOString()
1918
1993
  state.sourceName = typeof sourceName === 'string' ? sourceName : null
1994
+ state.showAll = false
1919
1995
  state.selected.clear()
1920
1996
  persistImported(state)
1921
1997
  resetUiState()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-go-plugin-sync",
3
- "version": "0.3.6",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "dsh": {