dsh-profile-config-sync 0.4.0 → 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/client.js CHANGED
@@ -172,7 +172,16 @@ window.__ModuleLoader__.load({
172
172
  kvRow: { display: 'flex', gap: '10px', fontSize: '12px', lineHeight: '18px', alignItems: 'flex-start', padding: '2px 0' },
173
173
  kvKey: { minWidth: '100px', width: '100px', flexShrink: 0, color: 'var(--dsw-alias-label-tertiary)' },
174
174
  kvVal: { flex: 1, minWidth: 0, color: 'var(--dsw-alias-label-secondary)', overflowWrap: 'break-word' },
175
- advice: { fontSize: '12px', lineHeight: '19px', color: 'var(--dsw-alias-label-secondary)', margin: 0, paddingLeft: '18px', display: 'flex', flexDirection: 'column', gap: '2px' },
175
+ advice: { fontSize: '12px', lineHeight: '20px', color: 'var(--dsw-alias-label-secondary)', margin: 0, paddingLeft: '18px', display: 'flex', flexDirection: 'column', gap: '4px' },
176
+ anchorBtn: {
177
+ display: 'inline-flex', alignItems: 'center', gap: '3px',
178
+ marginLeft: '8px', padding: '1px 9px', borderRadius: '999px',
179
+ fontSize: '11.5px', lineHeight: '18px', fontWeight: 600,
180
+ border: '1px solid var(--dsw-alias-toast-action)',
181
+ background: 'color-mix(in srgb, var(--dsw-alias-toast-action) 10%, transparent)',
182
+ color: 'var(--dsw-alias-toast-action)', cursor: 'pointer',
183
+ verticalAlign: 'baseline', textDecoration: 'none',
184
+ },
176
185
  actions: { display: 'flex', gap: '8px', flexWrap: 'wrap', alignItems: 'center' },
177
186
  hint: { fontSize: '12px', lineHeight: '19px', color: 'var(--dsw-alias-label-tertiary)', wordBreak: 'break-all' },
178
187
  code: {
@@ -239,9 +248,10 @@ window.__ModuleLoader__.load({
239
248
  function summarize(data) {
240
249
  if (!data) return { kind: 'idle', text: M('尚未检测', 'Not checked yet') }
241
250
  const { repo, version, bundles, deps } = data
251
+ const webdavOn = Boolean(data.webdav && data.webdav.active)
242
252
  if (!repo || (!repo.exists && !repo.empty)) return { kind: 'error', text: M('仓库路径未配置(见「本机仓库」卡)', 'Repo path not set (see the Local repo card)') }
243
253
  // 云端地址缺失只算"待处理":云端有没有更新由右侧云端徽标讲,这里不重复报错
244
- if (!data.remote || !data.remote.configured) return { kind: 'warn', text: M('云端仓库地址未配置', 'Cloud remote not set') }
254
+ if (!webdavOn && (!data.remote || !data.remote.configured)) return { kind: 'warn', text: M('云端仓库地址未配置', 'Cloud remote not set') }
245
255
  if (bundles.unresolved.length || deps.missing.length) {
246
256
  return {
247
257
  kind: 'error',
@@ -266,7 +276,7 @@ window.__ModuleLoader__.load({
266
276
  ),
267
277
  }
268
278
  }
269
- if (repo.behind === null) return { kind: 'idle', text: M('读不到本机 git 状态(git 不可用或没 upstream)', 'Cannot read local git state (git missing or no upstream)') }
279
+ if (!webdavOn && repo.behind === null) return { kind: 'idle', text: M('读不到本机 git 状态(git 不可用或没 upstream)', 'Cannot read local git state (git missing or no upstream)') }
270
280
  if (repo.dirty > 0) return { kind: 'warn', text: M(`本机有 ${repo.dirty} 处未提交改动,建议推送`, `${repo.dirty} uncommitted change(s) — consider pushing`) }
271
281
  if (repo.ahead > 0) return { kind: 'warn', text: M(`本机有 ${repo.ahead} 个提交还没推送`, `${repo.ahead} local commit(s) not pushed yet`) }
272
282
  // git 干净不代表没东西要推:新会话/新资料还躺在 ~\.dsh 里,没 capture 之前仓库是完全干净的
@@ -799,8 +809,59 @@ window.__ModuleLoader__.load({
799
809
  )
800
810
  }
801
811
 
812
+ /** 根据待办文案与当前体检状态映射直达目标区(用于「待办」里的锚文本快捷按钮)。 */
813
+ function adviceTarget(text, data) {
814
+ const s = String(text || '')
815
+ const webdavOn = Boolean(data && data.webdav && data.webdav.active)
816
+ if (/初始化推送|Initialize push/i.test(s)) {
817
+ return { section: 'automation', label: M('前往初始化推送 →', 'Go to initialize push →') }
818
+ }
819
+ if (/连不上 WebDAV|Cannot reach WebDAV/i.test(s)) {
820
+ return { section: 'platform', label: M('检查 WebDAV →', 'Check WebDAV →') }
821
+ }
822
+ if (/连不上云端|云端仓库地址|Cloud repo is not set|Cannot reach the cloud/i.test(s)) {
823
+ return { section: webdavOn ? 'platform' : 'targets', label: webdavOn ? M('检查 WebDAV →', 'Check WebDAV →') : M('去配置云端 →', 'Go to cloud settings →') }
824
+ }
825
+ if (/拉取|run Pull|\bPull\b/i.test(s) && !/只允许拉取|only Pull is allowed/i.test(s)) {
826
+ return { section: 'automation', label: M('前往立即拉取 →', 'Go to pull →') }
827
+ }
828
+ if (/只允许拉取|only Pull is allowed/i.test(s)) {
829
+ return { section: webdavOn ? 'platform' : 'targets', label: webdavOn ? M('检查 WebDAV →', 'Check WebDAV →') : M('检查云端配置 →', 'Check cloud config →') }
830
+ }
831
+ if (/推送|run Push|\bPush\b/i.test(s)) {
832
+ return { section: 'automation', label: M('前往立即推送 →', 'Go to push →') }
833
+ }
834
+ if (/仓库路径|本机仓库|Repo path|repo directory is not set|Local repo/i.test(s)) {
835
+ return { section: 'targets', label: M('去设置仓库 →', 'Go to repo settings →') }
836
+ }
837
+ if (/客户端根目录|client root/i.test(s)) {
838
+ return { section: 'roots', openRoots: true, label: M('检查本机路径 →', 'Check local paths →') }
839
+ }
840
+ if (/客户端版本|two clients differ/i.test(s)) {
841
+ return { section: 'platform', label: M('查看跨端契约 →', 'View contract →') }
842
+ }
843
+ if (/bundle|依赖|dependency/i.test(s)) {
844
+ return { section: 'actions', label: M('查看生成脚本 →', 'View scripts →') }
845
+ }
846
+ return null
847
+ }
848
+
802
849
  function Advice(props) {
803
- return h('ul', { style: S.advice }, (props.items || []).map((a, i) => h('li', { key: i }, a)))
850
+ const onNav = typeof props.onNavigate === 'function' ? props.onNavigate : null
851
+ return h('ul', { style: S.advice }, (props.items || []).map((a, i) => {
852
+ const target = onNav ? adviceTarget(a, props.data) : null
853
+ return h('li', { key: i },
854
+ h('span', null, a),
855
+ target
856
+ ? h('button', {
857
+ type: 'button',
858
+ style: S.anchorBtn,
859
+ title: M('点击直达对应操作区', 'Jump directly to this section'),
860
+ onClick: () => onNav(target),
861
+ }, target.label)
862
+ : null,
863
+ )
864
+ }))
804
865
  }
805
866
 
806
867
  function MadeNote(props) {
@@ -2257,6 +2318,10 @@ window.__ModuleLoader__.load({
2257
2318
  setMsg(d
2258
2319
  ? M(`云端:落后 ${d.behind} 个提交,领先 ${d.ahead} 个提交`, `Cloud: ${d.behind} commit(s) behind, ${d.ahead} ahead`)
2259
2320
  : (body.error || M('读不到远端', 'Cannot read the remote')))
2321
+ } else if (action === 'push-live') {
2322
+ setMsg(body.alreadyRunning
2323
+ ? M('后台推送已在运行中,请稍候…', 'Live push is already running…')
2324
+ : M('已开始后台推送(不关闭 DSH),进度与结果会在下方实时更新', 'Live push started in background (DSH stays open) — status updates below'))
2260
2325
  } else {
2261
2326
  setMsg(body.closeRequested
2262
2327
  ? M('已排队:客户端马上关闭,退出后执行;拉取完成后按设置自动重开', 'Queued: the client closes now and the sync runs after exit; it relaunches per your settings when pulling finishes')
@@ -2298,6 +2363,8 @@ window.__ModuleLoader__.load({
2298
2363
  }
2299
2364
 
2300
2365
  const pending = auto.pending
2366
+ const livePush = auto.livePush || null
2367
+ const liveRunning = Boolean(livePush && livePush.running)
2301
2368
  // 后台调度拿不到请求语言,宿主把原因中英各存一份,这里按当前界面语言挑
2302
2369
  const pendingReason = pending ? (langIsZh() ? (pending.reasonZh || pending.reason) : (pending.reasonEn || pending.reason)) : ''
2303
2370
  return h('div', { style: S.card },
@@ -2331,26 +2398,66 @@ window.__ModuleLoader__.load({
2331
2398
  h('button', {
2332
2399
  type: 'button',
2333
2400
  style: canPullNow ? S.btnPrimary : { ...S.btnPrimary, opacity: 0.5, cursor: 'not-allowed' },
2334
- disabled: Boolean(busy) || !canPullNow,
2401
+ disabled: Boolean(busy) || !canPullNow || liveRunning,
2335
2402
  title: canPullNow ? '' : M('云端还是空的:没有内容可拉,先「初始化推送」', 'The cloud is still empty — nothing to pull, initialize push first'),
2336
2403
  onClick: () => act('pull-now'),
2337
2404
  }, M('立即拉取(会关闭 DSH)', 'Pull now (closes DSH)')),
2338
2405
  h('button', {
2339
2406
  type: 'button',
2340
- style: pushAllowed ? S.btnPrimary : { ...S.btnPrimary, opacity: 0.5, cursor: 'not-allowed' },
2341
- disabled: Boolean(busy) || !pushAllowed,
2342
- title: pushAllowed ? '' : M('云端已有内容:本机还是空的,先拉取', 'The cloud already has content — pull first'),
2407
+ style: (pushAllowed && !liveRunning) ? S.btnPrimary : { ...S.btnPrimary, opacity: 0.5, cursor: 'not-allowed' },
2408
+ disabled: Boolean(busy) || !pushAllowed || liveRunning,
2409
+ title: pushAllowed
2410
+ ? M('不关闭 DSH 直接在后台抓配置并上传(只读本地配置,安全不打断当前对话)', 'Capture and push in background without closing DSH')
2411
+ : M('云端已有内容:本机还是空的,先拉取', 'The cloud already has content — pull first'),
2412
+ onClick: () => act('push-live'),
2413
+ }, liveRunning
2414
+ ? M('后台推送中…', 'Pushing in background…')
2415
+ : (initMode
2416
+ ? M('初始化推送(不关 DSH)', 'Initialize push (keep DSH open)')
2417
+ : M('立即推送(不关 DSH)', 'Push now (keep DSH open)'))),
2418
+ h('button', {
2419
+ type: 'button',
2420
+ style: (pushAllowed && !liveRunning) ? S.btn : { ...S.btn, opacity: 0.5, cursor: 'not-allowed' },
2421
+ disabled: Boolean(busy) || !pushAllowed || liveRunning,
2422
+ title: pushAllowed
2423
+ ? M('先退出 DSH 再推,可确保内存中尚未落盘的改动一并写入', 'Exit DSH before pushing so in-memory changes flush first')
2424
+ : M('云端已有内容:本机还是空的,先拉取', 'The cloud already has content — pull first'),
2343
2425
  onClick: () => act('push-now'),
2344
2426
  }, initMode
2345
2427
  ? M('初始化推送(会关闭 DSH)', 'Initialize push (closes DSH)')
2346
- : M('立即推送(会关闭 DSH)', 'Push now (closes DSH)')),
2428
+ : M('退出后推送(会关闭 DSH)', 'Push after exit (closes DSH)')),
2347
2429
  pending ? h('button', { type: 'button', style: S.btn, disabled: Boolean(busy), onClick: () => act('cancel') }, M('取消排队', 'Cancel queue')) : null,
2348
2430
  ),
2431
+ livePush && (livePush.running || livePush.finishedAt)
2432
+ ? h('div', {
2433
+ style: {
2434
+ padding: '8px 10px', borderRadius: '8px', fontSize: '12px', lineHeight: '18px',
2435
+ border: '1px solid ' + (livePush.running
2436
+ ? 'var(--dsw-alias-toast-action)'
2437
+ : (livePush.ok ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-state-error-primary)')),
2438
+ background: 'var(--dsw-alias-fill-l1, var(--dsw-alias-bg-layer-2))',
2439
+ color: livePush.running
2440
+ ? 'var(--dsw-alias-label-primary)'
2441
+ : (livePush.ok ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-state-error-primary)'),
2442
+ },
2443
+ },
2444
+ h('div', { style: { fontWeight: 600 } },
2445
+ (livePush.running ? '⏳ ' : (livePush.ok ? '✓ ' : '✕ ')) + (livePush.message || '')),
2446
+ livePush.finishedAt
2447
+ ? h('div', { style: { ...S.footnote, marginTop: '2px' } },
2448
+ M(`完成时间:${new Date(livePush.finishedAt).toLocaleTimeString(localeNow(), { hour12: false })}`,
2449
+ `Finished at: ${new Date(livePush.finishedAt).toLocaleTimeString(localeNow(), { hour12: false })}`)
2450
+ + (livePush.log ? ` · ${livePush.log}` : ''))
2451
+ : (livePush.log
2452
+ ? h('div', { style: { ...S.footnote, marginTop: '2px' } }, M(`日志:${livePush.log}`, `Log: ${livePush.log}`))
2453
+ : null),
2454
+ )
2455
+ : null,
2349
2456
  initMode
2350
2457
  ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary)' } },
2351
2458
  M(
2352
- '本机仓库和云端仓库都还是空的:点「初始化推送」会把本机配置当作仓库的初始内容推上去(自动 git init + 写仓库骨架 + capture + 提交 + 推送)。这时没有东西可拉,拉取按钮是灰的。',
2353
- 'Both the local repo and the cloud are empty: Initialize push uploads this machine\'s config as the repo\'s initial content (git init + repo skeleton + capture + commit + push). There is nothing to pull yet, so Pull stays disabled.',
2459
+ '本机仓库和云端仓库都还是空的:点「初始化推送(不关 DSH)」会直接在后台抓配置并上传;若需先让内存状态完全落盘,也可选「初始化推送(会关闭 DSH)」。这时没有东西可拉,拉取按钮是灰的。',
2460
+ 'Both the local repo and the cloud are empty: "Initialize push (keep DSH open)" captures and uploads in background; use "(closes DSH)" if you want in-memory state flushed first. Pull stays disabled until content exists.',
2354
2461
  ))
2355
2462
  : null,
2356
2463
  (!pushAllowed || !canPullNow)
@@ -2668,6 +2775,57 @@ window.__ModuleLoader__.load({
2668
2775
  return () => { alive = false; clearInterval(timer) }
2669
2776
  }, [])
2670
2777
 
2778
+ const lastLiveFinishedRef = react.useRef(0)
2779
+
2780
+ const jumpToSection = (sid, opts) => {
2781
+ if (!sid) return
2782
+ if (opts && opts.openRoots && !showRoots) setShowRoots(true)
2783
+ setActiveSection(sid)
2784
+ const scrollNow = () => {
2785
+ const el = document.getElementById('sync-section-' + sid)
2786
+ if (!el || !el.scrollIntoView) return
2787
+ el.scrollIntoView({ behavior: 'smooth', block: 'start' })
2788
+ try {
2789
+ if (typeof el.animate === 'function') {
2790
+ el.animate([
2791
+ { boxShadow: '0 0 0 2px var(--dsw-alias-toast-action)' },
2792
+ { boxShadow: '0 0 0 0px transparent' },
2793
+ ], { duration: 1500, easing: 'ease-out' })
2794
+ }
2795
+ } catch { }
2796
+ }
2797
+ if (opts && opts.openRoots && !showRoots) {
2798
+ setTimeout(scrollNow, 60)
2799
+ } else {
2800
+ scrollNow()
2801
+ }
2802
+ }
2803
+
2804
+ // 后台在线推送进行中时,每 1.5s 轮询状态直到结束,并弹出完成/失败提示
2805
+ const liveRunning = Boolean(data && data.auto && data.auto.livePush && data.auto.livePush.running)
2806
+ react.useEffect(() => {
2807
+ if (!liveRunning) return undefined
2808
+ const timer = setInterval(() => {
2809
+ if (typeof refresh === 'function') refresh()
2810
+ }, 1500)
2811
+ return () => clearInterval(timer)
2812
+ }, [liveRunning])
2813
+
2814
+ react.useEffect(() => {
2815
+ const lp = data && data.auto && data.auto.livePush
2816
+ if (!lp || lp.running || !lp.finishedAt) return
2817
+ if (lastLiveFinishedRef.current === 0) {
2818
+ // 首次挂载时如果已经是很久以前完成的旧记录不重弹;10 秒内刚完成则弹提示
2819
+ if (Date.now() - lp.finishedAt > 10000) {
2820
+ lastLiveFinishedRef.current = lp.finishedAt
2821
+ return
2822
+ }
2823
+ }
2824
+ if (lastLiveFinishedRef.current === lp.finishedAt) return
2825
+ lastLiveFinishedRef.current = lp.finishedAt
2826
+ showToast(lp.message || (lp.ok ? M('推送完成', 'Push completed') : M('推送失败', 'Push failed')))
2827
+ }, [data])
2828
+
2671
2829
  // 上次「退出后自动同步」的结果:15 分钟内、且没弹过,就弹 5 秒提示。
2672
2830
  // 判据与「启动即弹」共用 takeFreshResult(同一个 localStorage 键,不会弹两次)。
2673
2831
  react.useEffect(() => {
@@ -2693,6 +2851,9 @@ window.__ModuleLoader__.load({
2693
2851
  if (auto.checking || checking) return { kind: 'idle', text: M('云端检查中…', 'Checking the cloud…') }
2694
2852
  const drift = auto.drift
2695
2853
  if (drift) {
2854
+ if (drift.transport === 'webdav') {
2855
+ return { kind: 'ok', text: M(`WebDAV 已连接(云端 ${drift.files ?? 0} 项)`, `WebDAV connected (${drift.files ?? 0} item(s))`) }
2856
+ }
2696
2857
  const same = drift.behind === 0 && drift.ahead === 0
2697
2858
  if (same) return { kind: 'ok', text: M('云端已同步到最新,无需拉取', 'Cloud is up to date — nothing to pull') }
2698
2859
  const parts = []
@@ -2708,7 +2869,8 @@ window.__ModuleLoader__.load({
2708
2869
 
2709
2870
  const cloudLabel = cloudLine.kind === 'ok' ? M('一致', 'In sync')
2710
2871
  : (cloudLine.kind === 'error' ? M('不一致', 'Out of sync')
2711
- : (cloudLine.kind === 'pull' ? M('待拉取', 'To pull') : M('检查中', 'Checking')))
2872
+ : (cloudLine.kind === 'pull' ? M('待拉取', 'To pull')
2873
+ : (cloudLine.kind === 'init' ? M('待初始化', 'To initialize') : M('检查中', 'Checking'))))
2712
2874
 
2713
2875
  // 插件更新卡:老版本机器进来第一眼就能看到"有新版本 x.y.z"和更新按钮;
2714
2876
  // 更新相关的配置(清单地址、只读令牌)也收在这张卡里,别散到「云端仓库」去。
@@ -2959,11 +3121,20 @@ window.__ModuleLoader__.load({
2959
3121
  }, pendingDetailOpen ? M('收起', 'Collapse') : M('展开', 'Expand'))
2960
3122
  : null,
2961
3123
  ),
2962
- pendingDetailOpen ? localBlock : (localBlock ? h('div', { style: S.footnote }, M(
2963
- `${data.local.pending > 0 ? `有 ${data.local.pending} 个文件待推送` : '没有新写入'} · 点「展开」看具体会话记录与本机 profile`,
2964
- `${data.local.pending > 0 ? `${data.local.pending} file(s) to push` : 'nothing new'} · click Expand for session names and local profile`,
2965
- )) : null),
2966
- data && Array.isArray(data.advice) && data.advice.length ? h(Advice, { items: data.advice }) : null)
3124
+ pendingDetailOpen ? localBlock : (localBlock ? h('div', { style: S.footnote },
3125
+ h('span', null, M(
3126
+ `${data.local.pending > 0 ? `有 ${data.local.pending} 个文件待推送` : '没有新写入'} · 点「展开」看具体会话记录与本机 profile`,
3127
+ `${data.local.pending > 0 ? `${data.local.pending} file(s) to push` : 'nothing new'} · click Expand for session names and local profile`,
3128
+ )),
3129
+ data.local.pending > 0
3130
+ ? h('button', {
3131
+ type: 'button',
3132
+ style: S.anchorBtn,
3133
+ onClick: () => jumpToSection('automation'),
3134
+ }, M('前往立即推送 →', 'Go to push →'))
3135
+ : null,
3136
+ ) : null),
3137
+ data && Array.isArray(data.advice) && data.advice.length ? h(Advice, { items: data.advice, data, onNavigate: jumpToSection }) : null)
2967
3138
  : null,
2968
3139
  )
2969
3140
 
@@ -3008,7 +3179,7 @@ window.__ModuleLoader__.load({
3008
3179
  : M('本机仓库是空的:只生成「拉取」,拉完才能推送',
3009
3180
  'The local repo has no content yet: only Pull (plus Restore) can be generated now. Pull brings the whole cloud repo into this path; push unlocks after that.'))
3010
3181
  : null,
3011
- data && data.remote && !data.remote.configured
3182
+ data && !(data.webdav && data.webdav.active) && data.remote && !data.remote.configured
3012
3183
  ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } },
3013
3184
  M('远端地址未配置:只能生成还原',
3014
3185
  'Cloud remote not set: push/pull unavailable (restore still works).'))
@@ -3136,12 +3307,7 @@ window.__ModuleLoader__.load({
3136
3307
  fontWeight: active ? 600 : 400,
3137
3308
  },
3138
3309
  title: active ? M('当前所在区', 'Current section') : M('跳转到此区', 'Jump to section'),
3139
- onClick: () => {
3140
- setActiveSection(sid)
3141
- const el = document.getElementById('sync-section-' + sid)
3142
- if (!el || !el.scrollIntoView) return
3143
- el.scrollIntoView({ behavior: 'smooth', block: 'start' })
3144
- },
3310
+ onClick: () => jumpToSection(sid),
3145
3311
  }, label)
3146
3312
  }),
3147
3313
  ),