dsh-profile-config-sync 0.5.0 → 0.6.41

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
@@ -236,7 +236,10 @@ window.__ModuleLoader__.load({
236
236
  hint ? h('span', { style: { ...S.sectionHint, opacity: 0.75 } }, `· `) : null,
237
237
  hint ? h('div', { style: S.sectionHint }, hint) : null,
238
238
  ),
239
- h('div', { style: S.grid }, list),
239
+ // 用展开而不是把数组直接当 children:数组 children 会被 React 当成列表,
240
+ // 要求每一项都有 key(原来每区都在刷 "Each child in a list should have a unique key",
241
+ // 且报错位置指到 ConfigSyncPanel,很难对上号)。逐项展开就没有这个要求。
242
+ h('div', { style: S.grid }, ...list),
240
243
  )
241
244
  }
242
245
 
@@ -281,7 +284,20 @@ window.__ModuleLoader__.load({
281
284
  if (repo.ahead > 0) return { kind: 'warn', text: M(`本机有 ${repo.ahead} 个提交还没推送`, `${repo.ahead} local commit(s) not pushed yet`) }
282
285
  // git 干净不代表没东西要推:新会话/新资料还躺在 ~\.dsh 里,没 capture 之前仓库是完全干净的
283
286
  const local = data.local || {}
284
- if (local.known && local.pending > 0) {
287
+ // 三件不能混成一件事的:从没同步过 / 扫描没跑完 / 真的没有
288
+ if (local.known === false) return { kind: 'idle', text: M('还没有同步记录:先推送或拉取一次', 'No sync record yet — push or pull once') }
289
+ if (local.truncated) return { kind: 'warn', text: M('待推送扫描没跑完(文件太多或超时),数字可能偏小', 'Pending scan did not finish (too many files or timeout) — the count may be low') }
290
+ // 非 Windows:执行体只抓 profile / 提示 / Skills / 预设,别让「没有待推送」被读成「全都同步了」
291
+ if (Array.isArray(local.engineGroups) && local.pending === 0) {
292
+ return {
293
+ kind: 'idle',
294
+ text: M(
295
+ `已同步(这台机器走跨平台引擎,只处理 ${local.engineGroups.join(' / ')};会话记录、插件数据、额外路径等组要 Windows 版才会同步)`,
296
+ `Up to date (this machine uses the cross-platform engine, which only handles ${local.engineGroups.join(' / ')}; conversations, plugin data and extra paths sync on Windows)`,
297
+ ),
298
+ }
299
+ }
300
+ if (local.pending > 0) {
285
301
  return {
286
302
  kind: 'warn',
287
303
  text: M(
@@ -346,15 +362,15 @@ window.__ModuleLoader__.load({
346
362
  throw new Error(M(`${reason}(已自动重试 3 次)`, `${reason} (retried 3 times)`))
347
363
  }
348
364
 
349
- /** 每个 POST 都带 accept-language:宿主的建议句/错误信息按它出中文或英文。 */
350
- const jsonHeaders = { 'content-type': 'application/json', ...langHeaders() }
365
+ /** 每个 POST 都现读 accept-language:用户切语言后不必重载模块,宿主错误信息也跟着走。 */
366
+ const jsonHeaders = () => ({ 'content-type': 'application/json', ...langHeaders() })
351
367
 
352
368
  async function callPrepare(action, message, backupDir) {
353
369
  const res = await fetch('/config-sync/prepare', {
354
370
  method: 'POST',
355
371
  cache: 'no-store',
356
372
  credentials: 'same-origin',
357
- headers: jsonHeaders,
373
+ headers: jsonHeaders(),
358
374
  body: JSON.stringify({ action, message: message || '', backupDir: backupDir || '' }),
359
375
  })
360
376
  const text = await res.text()
@@ -369,7 +385,7 @@ window.__ModuleLoader__.load({
369
385
  method: 'POST',
370
386
  cache: 'no-store',
371
387
  credentials: 'same-origin',
372
- headers: jsonHeaders,
388
+ headers: jsonHeaders(),
373
389
  body: JSON.stringify(payload),
374
390
  })
375
391
  const text = await res.text()
@@ -379,13 +395,13 @@ window.__ModuleLoader__.load({
379
395
  return body
380
396
  }
381
397
 
382
- /** 自动同步接口:check / pull-now / push-now / cancel。 */
398
+ /** 自动同步接口:check / pull-now / push-now / push-live / cancel。 */
383
399
  async function callAuto(payload) {
384
400
  const res = await fetch('/config-sync/auto', {
385
401
  method: 'POST',
386
402
  cache: 'no-store',
387
403
  credentials: 'same-origin',
388
- headers: jsonHeaders,
404
+ headers: jsonHeaders(),
389
405
  body: JSON.stringify(payload),
390
406
  })
391
407
  const text = await res.text()
@@ -405,7 +421,7 @@ window.__ModuleLoader__.load({
405
421
  method: 'POST',
406
422
  cache: 'no-store',
407
423
  credentials: 'same-origin',
408
- headers: jsonHeaders,
424
+ headers: jsonHeaders(),
409
425
  body: JSON.stringify(payload),
410
426
  }
411
427
  : { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
@@ -426,7 +442,7 @@ window.__ModuleLoader__.load({
426
442
  method: 'POST',
427
443
  cache: 'no-store',
428
444
  credentials: 'same-origin',
429
- headers: jsonHeaders,
445
+ headers: jsonHeaders(),
430
446
  body: JSON.stringify(payload),
431
447
  }
432
448
  : { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
@@ -447,7 +463,7 @@ window.__ModuleLoader__.load({
447
463
  method: 'POST',
448
464
  cache: 'no-store',
449
465
  credentials: 'same-origin',
450
- headers: jsonHeaders,
466
+ headers: jsonHeaders(),
451
467
  body: JSON.stringify(payload),
452
468
  }
453
469
  : { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
@@ -465,7 +481,7 @@ window.__ModuleLoader__.load({
465
481
  method: 'POST',
466
482
  cache: 'no-store',
467
483
  credentials: 'same-origin',
468
- headers: jsonHeaders,
484
+ headers: jsonHeaders(),
469
485
  body: JSON.stringify(payload),
470
486
  }
471
487
  : { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
@@ -483,7 +499,7 @@ window.__ModuleLoader__.load({
483
499
  method: 'POST',
484
500
  cache: 'no-store',
485
501
  credentials: 'same-origin',
486
- headers: jsonHeaders,
502
+ headers: jsonHeaders(),
487
503
  body: JSON.stringify(payload),
488
504
  }
489
505
  : { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
@@ -502,7 +518,7 @@ window.__ModuleLoader__.load({
502
518
  method,
503
519
  cache: 'no-store',
504
520
  credentials: 'same-origin',
505
- headers: payload ? jsonHeaders : langHeaders(),
521
+ headers: payload ? jsonHeaders() : langHeaders(),
506
522
  body: payload ? JSON.stringify(payload) : undefined,
507
523
  })
508
524
  const text = await res.text()
@@ -524,7 +540,7 @@ window.__ModuleLoader__.load({
524
540
  method: 'POST',
525
541
  cache: 'no-store',
526
542
  credentials: 'same-origin',
527
- headers: jsonHeaders,
543
+ headers: jsonHeaders(),
528
544
  body: JSON.stringify(payload),
529
545
  }
530
546
  : { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
@@ -541,18 +557,21 @@ window.__ModuleLoader__.load({
541
557
  const [busy, setBusy] = react.useState(false)
542
558
  const [made, setMade] = react.useState(null)
543
559
 
544
- const refresh = react.useCallback(async (done) => {
545
- setBusy(true)
546
- setErr('')
560
+ const refresh = react.useCallback(async (doneOrOpts, maybeOpts) => {
561
+ const done = typeof doneOrOpts === 'function' ? doneOrOpts : null
562
+ const opts = (typeof doneOrOpts === 'object' && doneOrOpts) ? doneOrOpts : (maybeOpts || {})
563
+ const silent = Boolean(opts && opts.silent)
564
+ if (!silent) setBusy(true)
565
+ if (!silent) setErr('')
547
566
  try {
548
567
  const d = await callStatus()
549
568
  setData(d)
550
- if (typeof done === 'function') done(null, d)
569
+ if (done) done(null, d)
551
570
  } catch (e) {
552
571
  const msg = String((e && e.message) || e)
553
- setErr(msg)
554
- if (typeof done === 'function') done(msg, null)
555
- } finally { setBusy(false) }
572
+ if (!silent) setErr(msg)
573
+ if (done) done(msg, null)
574
+ } finally { if (!silent) setBusy(false) }
556
575
  }, [])
557
576
 
558
577
  react.useEffect(() => {
@@ -678,7 +697,7 @@ window.__ModuleLoader__.load({
678
697
  return (async () => {
679
698
  const res = await fetch('/config-sync/webdav', {
680
699
  method: payload ? 'POST' : 'GET',
681
- headers: payload ? jsonHeaders : langHeaders(),
700
+ headers: payload ? jsonHeaders() : langHeaders(),
682
701
  body: payload ? JSON.stringify(payload) : undefined,
683
702
  })
684
703
  const text = await res.text()
@@ -689,40 +708,118 @@ window.__ModuleLoader__.load({
689
708
  })()
690
709
  }
691
710
 
692
- function WebdavCard(props) {
693
- const [st, setSt] = react.useState(null)
711
+ /**
712
+ * 云端仓库与同步方式卡(合并原「云端仓库」与「同步方式(WebDAV)」):
713
+ * - 先选同步模式:Git 仓库 / WebDAV / 自动(优先 WebDAV)
714
+ * - 按所选模式展开对应字段与操作,避免用 WebDAV 时还一直提示“先填 Git 远端地址”
715
+ */
716
+ function CloudTargetCard(props) {
717
+ const remote = (props.data && props.data.remote) || {}
718
+ const wdStatus = (props.data && props.data.webdav) || {}
719
+ const [wdFetched, setWdFetched] = react.useState(null)
720
+ const st = wdFetched || wdStatus
721
+ const currentMode = st.mode || wdStatus.mode || 'git'
722
+ const currentWdUrl = st.url || ''
723
+ const currentWdUser = st.user || ''
724
+ const currentWdDir = st.dir || ''
725
+ const currentGitUrl = remote.url || ''
726
+ const currentGitKey = remote.sshKey || ''
727
+
694
728
  const [editing, setEditing] = react.useState(false)
695
- const [url, setUrl] = react.useState('')
696
- const [user, setUser] = react.useState('')
697
- const [pass, setPass] = react.useState('')
698
- const [dir, setDir] = react.useState('')
699
- const [mode, setMode] = react.useState('git')
729
+ const [mode, setMode] = react.useState(currentMode)
730
+ const [wdUrl, setWdUrl] = react.useState(currentWdUrl)
731
+ const [wdUser, setWdUser] = react.useState(currentWdUser)
732
+ const [wdPass, setWdPass] = react.useState('')
733
+ const [wdDir, setWdDir] = react.useState(currentWdDir)
734
+ const [gitUrl, setGitUrl] = react.useState(currentGitUrl)
735
+ const [gitKey, setGitKey] = react.useState(currentGitKey)
700
736
  const [busy, setBusy] = react.useState(false)
701
737
  const [err, setErr] = react.useState('')
702
738
  const [msg, setMsg] = react.useState('')
703
739
 
704
- const load = react.useCallback(async () => {
740
+ const loadWebdav = react.useCallback(async () => {
705
741
  try {
706
742
  const r = await callWebdav()
707
- setSt(r)
708
- setUrl(r.url || ''); setUser(r.user || ''); setDir(r.dir || ''); setMode(r.mode || 'git')
709
- setPass('')
710
- } catch (e) { setErr(String((e && e.message) || e)) }
743
+ setWdFetched(r)
744
+ } catch { /* status 已带基础字段;不打断页面 */ }
711
745
  }, [])
712
- react.useEffect(() => { load() }, [])
746
+ react.useEffect(() => { loadWebdav() }, [])
747
+
748
+ react.useEffect(() => {
749
+ if (editing) return
750
+ setMode(currentMode)
751
+ setWdUrl(currentWdUrl)
752
+ setWdUser(currentWdUser)
753
+ setWdDir(currentWdDir)
754
+ setWdPass('')
755
+ setGitUrl(currentGitUrl)
756
+ setGitKey(currentGitKey)
757
+ }, [editing, currentMode, currentWdUrl, currentWdUser, currentWdDir, currentGitUrl, currentGitKey])
758
+
759
+ const activeMode = editing ? mode : currentMode
760
+ const wdConfigured = Boolean(st.configured || st.url)
761
+ const gitConfigured = Boolean(remote.configured || remote.url)
762
+ const missing = Boolean(props.data) && (
763
+ activeMode === 'webdav' ? !wdConfigured
764
+ : (activeMode === 'git' ? !gitConfigured : (!wdConfigured && !gitConfigured))
765
+ )
766
+ const isEditing = editing || (!wdConfigured && !gitConfigured && Boolean(props.data))
767
+
768
+ const sourceLabel = (s) => s === 'settings' ? M('本机设置', 'Machine settings')
769
+ : (s === 'git' ? M('git 配置', 'git config')
770
+ : (s === 'default' ? M('自动探测', 'Auto-detected') : M('未配置', 'Not set')))
771
+
772
+ const startEdit = () => {
773
+ setMode(currentMode)
774
+ setWdUrl(currentWdUrl)
775
+ setWdUser(currentWdUser)
776
+ setWdDir(currentWdDir)
777
+ setWdPass('')
778
+ setGitUrl(currentGitUrl)
779
+ setGitKey(currentGitKey)
780
+ setErr(''); setMsg(''); setEditing(true)
781
+ }
782
+ const cancelEdit = () => {
783
+ setMode(currentMode)
784
+ setWdUrl(currentWdUrl)
785
+ setWdUser(currentWdUser)
786
+ setWdDir(currentWdDir)
787
+ setWdPass('')
788
+ setGitUrl(currentGitUrl)
789
+ setGitKey(currentGitKey)
790
+ setEditing(false); setErr(''); setMsg('')
791
+ }
713
792
 
714
793
  const save = async () => {
715
794
  setBusy(true); setErr(''); setMsg('')
716
795
  try {
717
- // 密码留空 = 不改(避免把已有密码清空)
718
- await callWebdav({ action: 'save', url, user, dir, mode, pass })
719
- setEditing(false); setPass('')
720
- setMsg(M('已保存', 'Saved'))
721
- await load()
796
+ if (mode === 'webdav' && !wdUrl.trim()) {
797
+ throw new Error(M('请填写 WebDAV 地址', 'Enter a WebDAV URL'))
798
+ }
799
+ if (mode === 'git' && !gitUrl.trim()) {
800
+ throw new Error(M('请填写 Git 远端地址', 'Enter a Git remote URL'))
801
+ }
802
+ if (mode === 'auto' && !wdUrl.trim() && !gitUrl.trim()) {
803
+ throw new Error(M('自动模式下请至少填写 WebDAV 地址或 Git 远端地址', 'In Auto mode, provide at least a WebDAV URL or a Git remote URL'))
804
+ }
805
+ await callWebdav({ action: 'save', url: wdUrl, user: wdUser, dir: wdDir, mode, pass: wdPass })
806
+ let gitSet = false
807
+ const gitDirty = gitUrl.trim() !== currentGitUrl.trim() || gitKey.trim() !== currentGitKey.trim()
808
+ if (gitDirty && (gitUrl.trim() || currentGitUrl.trim() || gitKey.trim() || currentGitKey.trim())) {
809
+ const r = await callSettings({ remoteUrl: gitUrl, sshKey: gitKey })
810
+ gitSet = Boolean(r && r.gitRemoteSet)
811
+ }
812
+ setEditing(false); setWdPass('')
813
+ setMsg(M(
814
+ `已保存${gitSet ? ',并已更新本机 git origin' : ''}`,
815
+ `Saved${gitSet ? ' and updated local git origin' : ''}`,
816
+ ))
817
+ await loadWebdav()
722
818
  if (typeof props.onSaved === 'function') props.onSaved()
723
819
  } catch (e) { setErr(String((e && e.message) || e)) } finally { setBusy(false) }
724
820
  }
725
- const run = async (action) => {
821
+
822
+ const runWebdav = async (action) => {
726
823
  setBusy(true); setErr(''); setMsg('')
727
824
  try {
728
825
  const r = await callWebdav({ action })
@@ -738,7 +835,7 @@ window.__ModuleLoader__.load({
738
835
 
739
836
  const field = (label, value, onCh, ph, type) => h('div', { style: S.kvRow },
740
837
  h('div', { style: S.kvKey }, label),
741
- editing
838
+ isEditing
742
839
  ? h('input', {
743
840
  type: type || 'text', style: S.input, value, placeholder: ph, spellCheck: false,
744
841
  onChange: (e) => onCh(e.target.value),
@@ -747,63 +844,104 @@ window.__ModuleLoader__.load({
747
844
  value || M('(未设置)', '(not set)')),
748
845
  )
749
846
 
847
+ const modeText = currentMode === 'webdav'
848
+ ? M('WebDAV', 'WebDAV')
849
+ : (currentMode === 'auto'
850
+ ? (wdStatus.active ? M('自动(当前走 WebDAV)', 'Auto (using WebDAV)') : M('自动(当前走 Git)', 'Auto (using Git)'))
851
+ : M('Git 仓库', 'Git repo'))
852
+ const showWebdav = activeMode === 'webdav' || activeMode === 'auto'
853
+ const showGit = activeMode === 'git' || activeMode === 'auto'
854
+
750
855
  return h('div', { style: S.card },
751
856
  h('div', { style: S.cardHead },
752
- h('div', { style: S.cardTitle }, M('同步方式(WebDAV)', 'Sync via WebDAV')),
753
- editing
857
+ h('div', { style: S.cardTitle }, M('云端仓库与同步方式', 'Cloud repo & transport')),
858
+ isEditing && missing
859
+ ? h('div', { style: { ...S.hint, flex: 1 } }, M('先选择并填好云端目标才能生成推送/拉取', 'Configure the cloud target to enable push/pull'))
860
+ : null,
861
+ isEditing
754
862
  ? h('div', { style: S.actions },
755
- h('button', { type: 'button', style: S.btnPrimary, disabled: busy || !url.trim(), onClick: save }, busy ? M('保存中…', 'Saving…') : M('保存', 'Save')),
756
- h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => { setEditing(false); setErr(''); setMsg('') } }, M('取消', 'Cancel')),
863
+ h('button', { type: 'button', style: S.btnPrimary, disabled: busy, onClick: save }, busy ? M('保存中…', 'Saving…') : M('保存', 'Save')),
864
+ (!wdConfigured && !gitConfigured) ? null : h('button', { type: 'button', style: S.btn, disabled: busy, onClick: cancelEdit }, M('取消', 'Cancel')),
757
865
  )
758
866
  : h('div', { style: S.actions },
759
- h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => { setEditing(true); setErr(''); setMsg('') } }, M('修改', 'Edit')),
867
+ h('button', { type: 'button', style: S.btn, disabled: busy || !props.data, onClick: startEdit }, M('修改', 'Edit')),
760
868
  ),
761
869
  ),
762
- field(M('同步模式', 'Mode'), mode === 'webdav' ? M('WebDAV', 'WebDAV') : (mode === 'auto' ? M('自动(配了就用 WebDAV)', 'Auto (WebDAV when set)') : M('git', 'git')),
763
- setMode, ''),
764
- editing
870
+ isEditing
765
871
  ? h('div', { style: S.kvRow },
766
- h('div', { style: S.kvKey }, M('模式', 'Mode')),
872
+ h('div', { style: S.kvKey }, M('同步模式', 'Mode')),
767
873
  h('select', {
768
874
  style: S.input, value: mode,
769
875
  onChange: (e) => setMode(e.target.value),
770
876
  },
771
- h('option', { value: 'git' }, M('git(默认)', 'git (default)')),
877
+ h('option', { value: 'git' }, M('Git 仓库(默认)', 'Git repo (default)')),
772
878
  h('option', { value: 'webdav' }, M('WebDAV', 'WebDAV')),
773
- h('option', { value: 'auto' }, M('自动', 'Auto')),
879
+ h('option', { value: 'auto' }, M('自动(配了 WebDAV 就用,否则用 Git)', 'Auto (WebDAV when set, else Git)')),
774
880
  ))
881
+ : h(Kv, { k: M('同步模式', 'Mode'), v: modeText }),
882
+ showWebdav
883
+ ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '6px', paddingTop: activeMode === 'auto' ? '6px' : '0px', borderTop: activeMode === 'auto' ? '1px solid var(--dsw-alias-border-l1)' : 'none' } },
884
+ activeMode === 'auto' ? h('div', { style: { ...S.hint, fontWeight: 600 } }, M('WebDAV(优先)', 'WebDAV (primary)')) : null,
885
+ field(M('WebDAV 地址', 'WebDAV URL'), isEditing ? wdUrl : currentWdUrl, setWdUrl, 'https://dav.example.com/remote.php/dav/files/me'),
886
+ field(M('用户名', 'Username'), isEditing ? wdUser : currentWdUser, setWdUser, ''),
887
+ isEditing
888
+ ? h('div', { style: S.kvRow },
889
+ h('div', { style: S.kvKey }, M('密码', 'Password')),
890
+ h('input', {
891
+ type: 'password', style: S.input, value: wdPass,
892
+ placeholder: st.hasPassword ? M('已设置,留空表示不改', 'Set; leave blank to keep') : '',
893
+ spellCheck: false,
894
+ onChange: (e) => setWdPass(e.target.value),
895
+ }))
896
+ : h(Kv, {
897
+ k: M('密码', 'Password'),
898
+ v: st.hasPassword ? M('已设置(不回显)', 'set (not shown)') : M('未设置', 'not set'),
899
+ }),
900
+ field(M('远端目录', 'Remote dir'), isEditing ? wdDir : currentWdDir, setWdDir, 'dsh-config-sync'),
901
+ h(Kv, {
902
+ k: M('传输安全', 'Transport'),
903
+ v: (st.secure === false)
904
+ ? M('http 明文(有密码泄露风险)', 'http (credentials in clear text)')
905
+ : M('https', 'https'),
906
+ }),
907
+ h('div', { style: S.actions },
908
+ h('button', { type: 'button', style: S.btn, disabled: busy || isEditing || !wdConfigured, onClick: () => runWebdav('test') }, M('测试连接', 'Test')),
909
+ h('button', { type: 'button', style: S.btn, disabled: busy || isEditing || !wdConfigured, onClick: () => runWebdav('upload') }, M('立即上传', 'Upload now')),
910
+ h('button', { type: 'button', style: S.btn, disabled: busy || isEditing || !wdConfigured, onClick: () => runWebdav('download') }, M('立即下载', 'Download now')),
911
+ ),
912
+ h('div', { style: S.footnote }, M(
913
+ 'WebDAV 与 git 共用同一份仓库格式,只换传输层:上传不删云端多余文件(开启「同步内容 → 删除云端副本」时除外),下载不删本机多余文件;两边都有且不同时本机那份留底为 .conflict-<时间>。',
914
+ 'WebDAV reuses the same repo format and only swaps the transport: upload keeps extra cloud files (unless "Also delete the cloud copy" is on in Content), download keeps extra local files; when both differ the local copy is kept as .conflict-<time>.',
915
+ )),
916
+ )
917
+ : null,
918
+ showGit
919
+ ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '6px', paddingTop: activeMode === 'auto' ? '6px' : '0px', borderTop: activeMode === 'auto' ? '1px solid var(--dsw-alias-border-l1)' : 'none' } },
920
+ activeMode === 'auto' ? h('div', { style: { ...S.hint, fontWeight: 600 } }, M('Git 仓库(WebDAV 未配时备用)', 'Git repo (fallback)')) : null,
921
+ field(M('远端地址', 'Remote URL'), isEditing ? gitUrl : currentGitUrl, setGitUrl, 'git@<host>:you/dsh-config.git'),
922
+ field(M('SSH 私钥', 'SSH key'), isEditing ? gitKey : currentGitKey, setGitKey, M('C:\\Users\\你\\.ssh\\id_ed25519', 'C:\\Users\\you\\.ssh\\id_ed25519')),
923
+ h(Kv, {
924
+ k: M('私钥来源', 'Key source'),
925
+ v: `${sourceLabel(remote.sshKeyFrom)}${remote.sshKeyExists ? '' : M('(文件不存在)', ' (file missing)')}`,
926
+ }),
927
+ h(Kv, { k: M('地址来源', 'URL source'), v: sourceLabel(remote.urlSource) }),
928
+ h(Kv, { k: M('设置文件', 'Settings file'), v: remote.settingsPath || M('(未知)', '(unknown)') }),
929
+ h('div', { style: S.footnote }, M(
930
+ '远端地址支持任意 git 托管平台(Gitee / GitHub / GitLab / 自建 Gitea):'
931
+ + 'git@host:owner/repo.git、ssh://、https:// 三种写法都行;'
932
+ + '例:git@gitee.com:you/dsh-config.git、git@github.com:you/dsh-config.git、https://gitlab.com/you/dsh-config.git。'
933
+ + 'SSH 地址用私钥/ssh config 走认证,https 地址用 Git 凭据管理器里的账号或令牌。',
934
+ 'Any git host works (Gitee / GitHub / GitLab / self-hosted Gitea): '
935
+ + 'git@host:owner/repo.git, ssh:// and https:// are all accepted; '
936
+ + 'e.g. git@gitee.com:you/dsh-config.git, git@github.com:you/dsh-config.git, https://gitlab.com/you/dsh-config.git. '
937
+ + 'SSH URLs authenticate with the key or ssh config; https URLs use the account or token in Git Credential Manager.',
938
+ )),
939
+ h('div', { style: S.footnote }, M(
940
+ '只存私钥路径不存内容;保存远端地址会同步更新本机 git origin,git 失败则整套回滚。',
941
+ 'Only the key path is stored; saving also updates the local git origin, rolling everything back if git fails.',
942
+ )),
943
+ )
775
944
  : null,
776
- field(M('WebDAV 地址', 'WebDAV URL'), editing ? url : (st && st.url) || '', setUrl, 'https://dav.example.com/remote.php/dav/files/me'),
777
- field(M('用户名', 'Username'), editing ? user : (st && st.user) || '', setUser, ''),
778
- editing
779
- ? h('div', { style: S.kvRow },
780
- h('div', { style: S.kvKey }, M('密码', 'Password')),
781
- h('input', {
782
- type: 'password', style: S.input, value: pass,
783
- placeholder: (st && st.hasPassword) ? M('已设置,留空表示不改', 'Set; leave blank to keep') : '',
784
- spellCheck: false,
785
- onChange: (e) => setPass(e.target.value),
786
- }))
787
- : h(Kv, {
788
- k: M('密码', 'Password'),
789
- v: (st && st.hasPassword) ? M('已设置(不回显)', 'set (not shown)') : M('未设置', 'not set'),
790
- }),
791
- field(M('远端目录', 'Remote dir'), editing ? dir : (st && st.dir) || '', setDir, 'dsh-config-sync'),
792
- h(Kv, {
793
- k: M('传输安全', 'Transport'),
794
- v: (st && st.secure === false)
795
- ? M('http 明文(有密码泄露风险)', 'http (credentials in clear text)')
796
- : M('https', 'https'),
797
- }),
798
- h('div', { style: S.actions },
799
- h('button', { type: 'button', style: S.btn, disabled: busy || !(st && st.configured), onClick: () => run('test') }, M('测试连接', 'Test')),
800
- h('button', { type: 'button', style: S.btn, disabled: busy || !(st && st.configured), onClick: () => run('upload') }, M('立即上传', 'Upload now')),
801
- h('button', { type: 'button', style: S.btn, disabled: busy || !(st && st.configured), onClick: () => run('download') }, M('立即下载', 'Download now')),
802
- ),
803
- h('div', { style: S.footnote }, M(
804
- 'WebDAV 与 git 共用同一份仓库格式,只换传输层:上传不删云端多余文件,下载不删本机多余文件;两边都有且不同时本机那份留底为 .conflict-<时间>。',
805
- 'WebDAV reuses the same repo format and only swaps the transport: upload never deletes extra cloud files, download never deletes extra local files; when both differ the local copy is kept as .conflict-<time>.',
806
- )),
807
945
  err ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } }, M(`失败:${err}`, `Failed: ${err}`)) : null,
808
946
  msg ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-success-primary)' } }, msg) : null,
809
947
  )
@@ -817,21 +955,21 @@ window.__ModuleLoader__.load({
817
955
  return { section: 'automation', label: M('前往初始化推送 →', 'Go to initialize push →') }
818
956
  }
819
957
  if (/连不上 WebDAV|Cannot reach WebDAV/i.test(s)) {
820
- return { section: 'platform', label: M('检查 WebDAV →', 'Check WebDAV →') }
958
+ return { section: 'targets', label: M('检查 WebDAV →', 'Check WebDAV →') }
821
959
  }
822
960
  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 →') }
961
+ return { section: 'targets', label: webdavOn ? M('检查 WebDAV →', 'Check WebDAV →') : M('去配置云端 →', 'Go to cloud settings →') }
824
962
  }
825
963
  if (/拉取|run Pull|\bPull\b/i.test(s) && !/只允许拉取|only Pull is allowed/i.test(s)) {
826
964
  return { section: 'automation', label: M('前往立即拉取 →', 'Go to pull →') }
827
965
  }
828
966
  if (/只允许拉取|only Pull is allowed/i.test(s)) {
829
- return { section: webdavOn ? 'platform' : 'targets', label: webdavOn ? M('检查 WebDAV →', 'Check WebDAV →') : M('检查云端配置 →', 'Check cloud config →') }
967
+ return { section: 'targets', label: webdavOn ? M('检查 WebDAV →', 'Check WebDAV →') : M('检查云端配置 →', 'Check cloud config →') }
830
968
  }
831
969
  if (/推送|run Push|\bPush\b/i.test(s)) {
832
970
  return { section: 'automation', label: M('前往立即推送 →', 'Go to push →') }
833
971
  }
834
- if (/仓库路径|本机仓库|Repo path|repo directory is not set|Local repo/i.test(s)) {
972
+ if (/仓库路径|本机仓库|Repo path|repo directory is not set|Local repo|仓库目录|runnable sync script/i.test(s)) {
835
973
  return { section: 'targets', label: M('去设置仓库 →', 'Go to repo settings →') }
836
974
  }
837
975
  if (/客户端根目录|client root/i.test(s)) {
@@ -857,7 +995,7 @@ window.__ModuleLoader__.load({
857
995
  type: 'button',
858
996
  style: S.anchorBtn,
859
997
  title: M('点击直达对应操作区', 'Jump directly to this section'),
860
- onClick: () => onNav(target),
998
+ onClick: () => onNav(target.section, target),
861
999
  }, target.label)
862
1000
  : null,
863
1001
  )
@@ -924,6 +1062,10 @@ window.__ModuleLoader__.load({
924
1062
  */
925
1063
  function RepoCard(props) {
926
1064
  const repo = (props.data && props.data.repo) || {}
1065
+ // WebDAV 模式下仓库目录只是普通文件夹(没有 .git),分支/HEAD 与提交前后比较都不存在;
1066
+ // 以前这里一律回落到 '?',面板上就显示成「? @ ?」「落后 ? · 领先 ?」,看着像坏了
1067
+ const wdOn = Boolean(props.data && props.data.webdav && props.data.webdav.active)
1068
+ const hasGitRef = Boolean(repo.branch || repo.head)
927
1069
  // 空目录不算「没配好」:它是新机器还没拉取的状态,不该把人按在编辑态
928
1070
  const missing = Boolean(props.data) && !repo.exists && !repo.empty
929
1071
  const [editing, setEditing] = react.useState(false)
@@ -990,16 +1132,27 @@ window.__ModuleLoader__.load({
990
1132
  }),
991
1133
  h(Kv, {
992
1134
  k: M('分支 / HEAD', 'Branch / HEAD'),
993
- v: repo.exists ? `${repo.branch || '?'} @ ${repo.head || '?'}` : (repo.empty ? M('(待首次拉取)', '(after the first pull)') : M('(不可用)', '(unavailable)')),
1135
+ v: !repo.exists
1136
+ ? (repo.empty ? M('(待首次拉取)', '(after the first pull)') : M('(不可用)', '(unavailable)'))
1137
+ : (hasGitRef
1138
+ ? `${repo.branch || '?'} @ ${repo.head || '?'}`
1139
+ : (wdOn
1140
+ ? M('(WebDAV 模式:这个目录不是 git 仓库,没有分支)', '(WebDAV mode: this folder is not a git repository, so there is no branch)')
1141
+ : M('(这个目录还没有 git 提交)', '(this folder has no git commits yet)'))),
994
1142
  }),
995
1143
  h(Kv, {
996
1144
  k: M('远端', 'Remote'),
997
- v: repo.exists
998
- ? M(
999
- `落后 ${repo.behind ?? '?'} · 领先 ${repo.ahead ?? '?'} · 未提交 ${repo.uncommitted ?? repo.dirty ?? '?'}` + (repo.pending ? `(本机待同步 ${repo.pending})` : ''),
1000
- `behind ${repo.behind ?? '?'} · ahead ${repo.ahead ?? '?'} · uncommitted ${repo.uncommitted ?? repo.dirty ?? '?'}` + (repo.pending ? ` (${repo.pending} pending on this machine)` : ''),
1001
- )
1002
- : (repo.empty ? M('(拉取之后才有得比)', '(available after the first pull)') : M('(不可用)', '(unavailable)')),
1145
+ v: !repo.exists
1146
+ ? (repo.empty ? M('(拉取之后才有得比)', '(available after the first pull)') : M('(不可用)', '(unavailable)'))
1147
+ : (repo.behind === null || repo.ahead === null
1148
+ ? (wdOn
1149
+ ? M('(WebDAV 模式不比提交前后)', '(WebDAV mode: no commit comparison)')
1150
+ : M('(还没有上游分支,无法比较前后)', '(no upstream branch to compare)'))
1151
+ + ` · ${M('未提交', 'uncommitted')} ${repo.uncommitted ?? repo.dirty ?? '?'}` + (repo.pending ? `(${M('本机待同步', 'pending on this machine')} ${repo.pending})` : '')
1152
+ : M(
1153
+ `落后 ${repo.behind} · 领先 ${repo.ahead} · 未提交 ${repo.uncommitted ?? repo.dirty ?? '?'}` + (repo.pending ? `(本机待同步 ${repo.pending})` : ''),
1154
+ `behind ${repo.behind} · ahead ${repo.ahead} · uncommitted ${repo.uncommitted ?? repo.dirty ?? '?'}` + (repo.pending ? ` (${repo.pending} pending on this machine)` : ''),
1155
+ )),
1003
1156
  }),
1004
1157
  (repo.empty || repo.phase === 'missing')
1005
1158
  ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary)' } },
@@ -1029,106 +1182,7 @@ window.__ModuleLoader__.load({
1029
1182
  )
1030
1183
  }
1031
1184
 
1032
- /**
1033
- * 云端仓库卡:远端地址 + SSH 私钥路径。
1034
- * 默认只读展示;点「修改」才变成可编辑,保存走 POST /config-sync/settings,
1035
- * 宿主那边会同时 git remote set-url,失败则回滚设置文件并回显错误。
1036
- */
1037
- function RemoteCard(props) {
1038
- const remote = (props.data && props.data.remote) || {}
1039
- // 没配过云端仓库 = 强制编辑态:不给「取消」,也不许就这么放着去生成推送/拉取
1040
- const missing = Boolean(props.data) && !remote.configured
1041
- const [editing, setEditing] = react.useState(false)
1042
- const [url, setUrl] = react.useState(remote.url || '')
1043
- const [key, setKey] = react.useState(remote.sshKey || '')
1044
- const [busy, setBusy] = react.useState(false)
1045
- const [err, setErr] = react.useState('')
1046
- const [msg, setMsg] = react.useState('')
1047
- const isEditing = editing || missing
1048
- const sourceLabel = (s) => s === 'settings' ? M('本机设置', 'Machine settings')
1049
- : (s === 'git' ? M('git 配置', 'git config')
1050
- : (s === 'default' ? M('自动探测', 'Auto-detected') : M('未配置', 'Not set')))
1051
-
1052
- const startEdit = () => {
1053
- setUrl(remote.url || '')
1054
- setKey(remote.sshKey || '')
1055
- setErr('')
1056
- setMsg('')
1057
- setEditing(true)
1058
- }
1059
- const cancelEdit = () => { setEditing(false); setErr(''); setMsg('') }
1060
- const save = async () => {
1061
- setBusy(true); setErr(''); setMsg('')
1062
- try {
1063
- const r = await callSettings({ remoteUrl: url, sshKey: key })
1064
- setMsg(M(
1065
- `已保存${r.gitRemoteSet ? ',并已更新本机 git origin' : ''}`,
1066
- `Saved${r.gitRemoteSet ? ' and updated the local git origin' : ''}`,
1067
- ))
1068
- setEditing(false)
1069
- if (typeof props.onSaved === 'function') props.onSaved()
1070
- } catch (e) {
1071
- setErr(String((e && e.message) || e))
1072
- } finally { setBusy(false) }
1073
- }
1074
-
1075
- const field = (label, value, onChange, placeholder) => h('div', { style: S.kvRow },
1076
- h('div', { style: S.kvKey }, label),
1077
- isEditing
1078
- ? h('input', {
1079
- type: 'text', style: S.input, value, placeholder, spellCheck: false,
1080
- onChange: (e) => onChange(e.target.value),
1081
- })
1082
- : h('div', { style: { ...S.kvVal, fontFamily: 'Consolas, ui-monospace, monospace' } }, value || M('(未配置)', '(not set)')),
1083
- )
1084
-
1085
- return h('div', { style: S.card },
1086
- h('div', { style: S.cardHead },
1087
- h('div', { style: S.cardTitle }, M('云端仓库', 'Cloud repo')),
1088
- isEditing && missing
1089
- ? h('div', { style: { ...S.hint, flex: 1 } }, M('先填远端地址才能生成推送/拉取', 'Set the remote URL to enable push/pull'))
1090
- : null,
1091
- isEditing
1092
- ? h('div', { style: S.actions },
1093
- h('button', { type: 'button', style: S.btnPrimary, disabled: busy || !url.trim(), onClick: save }, busy ? M('保存中…', 'Saving…') : M('保存', 'Save')),
1094
- missing ? null : h('button', { type: 'button', style: S.btn, disabled: busy, onClick: cancelEdit }, M('取消', 'Cancel')),
1095
- )
1096
- : h('div', { style: S.actions },
1097
- h('button', { type: 'button', style: S.btn, disabled: !props.data, onClick: startEdit }, M('修改', 'Edit')),
1098
- ),
1099
- ),
1100
- field(M('远端地址', 'Remote URL'), isEditing ? url : (remote.url || ''), setUrl, 'git@<host>:you/dsh-config.git'),
1101
- field(M('SSH 私钥', 'SSH key'), isEditing ? key : (remote.sshKey || ''), setKey, M('C:\\Users\\你\\.ssh\\id_ed25519', 'C:\\Users\\you\\.ssh\\id_ed25519')),
1102
- h(Kv, {
1103
- k: M('私钥来源', 'Key source'),
1104
- v: `${sourceLabel(remote.sshKeyFrom)}${remote.sshKeyExists ? '' : M('(文件不存在)', ' (file missing)')}`,
1105
- }),
1106
- h(Kv, { k: M('地址来源', 'URL source'), v: sourceLabel(remote.urlSource) }),
1107
- h(Kv, { k: M('设置文件', 'Settings file'), v: remote.settingsPath || M('(未知)', '(unknown)') }),
1108
- missing && !remote.sshKeyExists
1109
- ? h('div', { style: S.footnote }, M(
1110
- '私钥可留空:认证交给 .ssh\\config 或 Git 默认选择;填了才写进脚本的 GIT_SSH_COMMAND。',
1111
- 'The key is optional — auth falls back to .ssh\\config or Git defaults; fill it only to write GIT_SSH_COMMAND into scripts.',
1112
- ))
1113
- : null,
1114
- err ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } }, M(`保存失败:${err}`, `Save failed: ${err}`)) : null,
1115
- msg ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-success-primary)' } }, msg) : null,
1116
- h('div', { style: S.footnote }, M(
1117
- '远端地址支持任意 git 托管平台(Gitee / GitHub / GitLab / 自建 Gitea):'
1118
- + 'git@host:owner/repo.git、ssh://、https:// 三种写法都行;'
1119
- + '例:git@gitee.com:you/dsh-config.git、git@github.com:you/dsh-config.git、https://gitlab.com/you/dsh-config.git。'
1120
- + 'SSH 地址用下面的私钥/ssh config 走认证,https 地址用 Git 凭据管理器里的账号或令牌。',
1121
- 'Any git host works (Gitee / GitHub / GitLab / self-hosted Gitea): '
1122
- + 'git@host:owner/repo.git, ssh:// and https:// are all accepted; '
1123
- + 'e.g. git@gitee.com:you/dsh-config.git, git@github.com:you/dsh-config.git, https://gitlab.com/you/dsh-config.git. '
1124
- + 'SSH URLs authenticate with the key or ssh config below; https URLs use the account or token in Git Credential Manager.',
1125
- )),
1126
- h('div', { style: S.footnote }, M(
1127
- '只存私钥路径不存内容;保存远端地址会同步更新本机 git origin,git 失败则整套回滚。',
1128
- 'Only the key path is stored; saving also updates the local git origin, rolling everything back if git fails.',
1129
- )),
1130
- )
1131
- }
1185
+ // RemoteCard 已合并进 CloudTargetCard(同步方式 + 云端目标统一在一张卡里)
1132
1186
 
1133
1187
  /**
1134
1188
  * 「还原备份」卡:先看备份目录在哪(默认 <DshHome>\backups,可改成别的绝对路径),
@@ -1339,7 +1393,7 @@ window.__ModuleLoader__.load({
1339
1393
  `动手前先整份备份当前位置到 ${pv.backupTo || 'backups\\<自动命名>'},不满意还能再退回来。`,
1340
1394
  `The current location is copied to ${pv.backupTo || 'backups\\<auto-named>'} first, so you can undo it.`,
1341
1395
  )),
1342
- h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warning-primary)' } }, M(
1396
+ h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary, #d97706)' } }, M(
1343
1397
  '确认后:客户端正常退出 → 弹出进度窗口执行 → 完成后自动重启客户端。',
1344
1398
  'After confirming: the client closes normally, a progress window runs it, then the client restarts automatically.',
1345
1399
  )),
@@ -1357,8 +1411,8 @@ window.__ModuleLoader__.load({
1357
1411
  },
1358
1412
  h('div', { style: { ...S.cardTitle, fontSize: '13px' } }, confirmTitle),
1359
1413
  h('div', { style: S.hint }, M(
1360
- `快照时间 ${when(confirm.snap.at)}(${rel(confirm.snap.at)})· ${confirm.snap.files || 0} 个文件 · ${size(confirm.snap.bytes)} · ${confirm.snap.plugins || 0} 个插件`,
1361
- `Snapshot ${when(confirm.snap.at)} (${rel(confirm.snap.at)}) · ${confirm.snap.files || 0} files · ${size(confirm.snap.bytes)} · ${confirm.snap.plugins || 0} plugins`,
1414
+ `快照时间 ${when(confirm.snap.at)}(${rel(confirm.snap.at)})· ${confirm.snap.plugins || 0} 个插件 · ${confirm.snap.bundles || 0} 个 bundle`,
1415
+ `Snapshot ${when(confirm.snap.at)} (${rel(confirm.snap.at)}) · ${confirm.snap.plugins || 0} plugins · ${confirm.snap.bundles || 0} bundles`,
1362
1416
  )),
1363
1417
  listBox(
1364
1418
  M(`将撤走 ${pvRemovePlugins.length} 个快照之后装上的插件`, `Removing ${pvRemovePlugins.length} plugin(s) installed after this snapshot`),
@@ -1380,7 +1434,7 @@ window.__ModuleLoader__.load({
1380
1434
  '动手前会把当前配置整份存到 backups\\manual-<时间戳>;撤走的东西另有 rollback 清单,随时能再还原回来。',
1381
1435
  'The current config is copied to backups\\manual-<timestamp> first, and everything removed is listed in a rollback manifest — both can be restored later.',
1382
1436
  )),
1383
- h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warning-primary)' } }, M(
1437
+ h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary, #d97706)' } }, M(
1384
1438
  '确认后:客户端正常退出 → 弹出进度窗口执行还原 → 完成后自动重启客户端。',
1385
1439
  'After confirming: the client closes normally, a progress window runs the restore, then the client restarts automatically.',
1386
1440
  )),
@@ -1403,7 +1457,7 @@ window.__ModuleLoader__.load({
1403
1457
  h('div', {
1404
1458
  style: { ...S.hint, fontFamily: 'Consolas, ui-monospace, monospace', wordBreak: 'break-all' },
1405
1459
  }, M(`备份位置:${manual.dir}`, `Backup path: ${manual.dir}`)),
1406
- h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warning-primary)' } }, M(
1460
+ h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary, #d97706)' } }, M(
1407
1461
  '这份备份认不出类型,自动还原不知道该写回哪,按下面三步手动拷:',
1408
1462
  'This backup cannot be classified, so there is no automatic target. Copy it by hand:',
1409
1463
  )),
@@ -1508,6 +1562,8 @@ window.__ModuleLoader__.load({
1508
1562
  const [busy, setBusy] = react.useState(false)
1509
1563
  const [err, setErr] = react.useState('')
1510
1564
  const [msg, setMsg] = react.useState('')
1565
+ // 「放弃清单」的二次确认态:一次点击就删掉整份清单与已做的逐项选择,太容易被误触
1566
+ const [armDiscard, setArmDiscard] = react.useState(false)
1511
1567
 
1512
1568
  const load = async () => {
1513
1569
  setBusy(true); setErr('')
@@ -1528,6 +1584,9 @@ window.__ModuleLoader__.load({
1528
1584
  h('div', { style: S.hint }, err
1529
1585
  ? M(`读取失败:${err}`, `Read failed: ${err}`)
1530
1586
  : M('正在读取冲突清单…', 'Loading conflicts…')),
1587
+ // 失败后没有重试入口的话,这张卡会一直钉在「读取失败」上:
1588
+ // 父层的「重新检测」只刷 /status,不会重拉这张卡。
1589
+ err ? h('button', { type: 'button', style: S.btn, disabled: busy, onClick: load }, M('重试', 'Retry')) : null,
1531
1590
  )
1532
1591
  }
1533
1592
  if (!state.exists) return null
@@ -1675,7 +1734,12 @@ window.__ModuleLoader__.load({
1675
1734
  h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => setAll('cloud') }, M('全部用云端', 'All cloud')),
1676
1735
  h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => setAll('local') }, M('全部用本机', 'All local')),
1677
1736
  h('button', { type: 'button', style: S.btnPrimary, disabled: busy, onClick: save }, busy ? M('保存中…', 'Saving…') : M('保存选择', 'Save')),
1678
- h('button', { type: 'button', style: S.btn, disabled: busy, onClick: discard }, M('放弃清单', 'Discard')),
1737
+ // 两段式:点一下就删掉整份清单(连同逐项选择),和旁边「保存选择」长得很像,
1738
+ // 误点等于白选一遍。第一次点只进入确认态,再点才真的删。
1739
+ h('button', {
1740
+ type: 'button', style: S.btn, disabled: busy,
1741
+ onClick: () => { if (!armDiscard) { setArmDiscard(true); return } setArmDiscard(false); discard() },
1742
+ }, armDiscard ? M('确认放弃?(点此删除清单)', 'Confirm discard (click again)') : M('放弃清单', 'Discard')),
1679
1743
  ),
1680
1744
  err ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } }, M(`操作失败:${err}`, `Failed: ${err}`)) : null,
1681
1745
  msg ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-success-primary)' } }, msg) : null,
@@ -1794,7 +1858,8 @@ window.__ModuleLoader__.load({
1794
1858
  if (!data || !draft) {
1795
1859
  return h('div', { style: S.card },
1796
1860
  h('div', { style: S.cardTitle }, M('插件数据与额外路径', 'Plugin data & extra paths')),
1797
- h('div', { style: S.hint }, err ? M(`读取失败:${err}`, `Read failed: ${err}`) : M('正在读取规则…', 'Loading rules…')))
1861
+ h('div', { style: S.hint }, err ? M(`读取失败:${err}`, `Read failed: ${err}`) : M('正在读取规则…', 'Loading rules…')),
1862
+ err ? h('button', { type: 'button', style: S.btn, disabled: busy, onClick: load }, M('重试', 'Retry')) : null)
1798
1863
  }
1799
1864
 
1800
1865
  const hardMB = Math.round(data.hardMaxBytes / (1024 * 1024))
@@ -1845,6 +1910,18 @@ window.__ModuleLoader__.load({
1845
1910
  ),
1846
1911
 
1847
1912
  // 排除名单
1913
+ // 安全必需项补齐要让人看见:宿主会把 browser-profiles 这类条目补回生效名单,
1914
+ // 但不静默改用户的口径 —— 这里明确说「你的文件缺这几条,已按内置名单补齐」。
1915
+ (() => {
1916
+ const mm = data && data.config && data.config.pluginData && data.config.pluginData.missingMandatory
1917
+ if (!mm || (!(mm.skipDirs || []).length && !(mm.exclude || []).length)) return null
1918
+ const parts = [...(mm.skipDirs || []), ...(mm.exclude || [])].filter((v, i, a) => a.indexOf(v) === i)
1919
+ return h('div', { style: { ...S.footnote, marginTop: '6px', color: 'var(--dsw-alias-label-warn, #b45309)' } },
1920
+ M(
1921
+ `你的规则文件缺少安全必需项,已按内置名单补齐:${parts.join('、')}(这些是浏览器剖面/凭据库,删掉也不会同步;点保存会写回文件)`,
1922
+ `Your rules file was missing mandatory safety entries; they are restored: ${parts.join(', ')} (browser profiles / credential stores — never synced even if removed; saving writes them back).`,
1923
+ ))
1924
+ })(),
1848
1925
  h('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', marginTop: '6px', flexWrap: 'wrap' } },
1849
1926
  h('div', { style: { fontSize: '12px' } }, M('排除名单(通配,一行一条)', 'Exclusions (wildcards, one per line)')),
1850
1927
  h('button', { type: 'button', style: S.btn, disabled: !editing || busy, onClick: resetExclude }, M('恢复默认', 'Restore defaults')),
@@ -1948,7 +2025,8 @@ window.__ModuleLoader__.load({
1948
2025
  if (!data || !data.available) {
1949
2026
  return h('div', { style: S.card },
1950
2027
  h('div', { style: S.cardTitle }, M('工作区显示状态', 'Workspace visibility')),
1951
- h('div', { style: S.hint }, err ? M('读取失败:' + err, 'Read failed: ' + err) : M('本机还没有工作区数据,DSH 初始化后可用。', 'No workspace data yet — available after DSH initializes.')))
2028
+ h('div', { style: S.hint }, err ? M('读取失败:' + err, 'Read failed: ' + err) : M('本机还没有工作区数据,DSH 初始化后可用。', 'No workspace data yet — available after DSH initializes.')),
2029
+ err ? h('button', { type: 'button', style: S.btn, disabled: busy, onClick: load }, M('重试', 'Retry')) : null)
1952
2030
  }
1953
2031
 
1954
2032
  const wss = data.workspaces || []
@@ -2044,9 +2122,9 @@ window.__ModuleLoader__.load({
2044
2122
  // 编辑态下用带词义的按钮文案(隐藏/显示,颜色区分),不再是一个孤零零的按钮。
2045
2123
  open
2046
2124
  ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px', marginTop: '6px', paddingLeft: '18px' } },
2047
- (w.sessions || []).length === 0
2125
+ (Array.isArray(w.sessions) ? w.sessions : []).length === 0
2048
2126
  ? h('div', { style: S.footnote }, M('这个工作区还没有会话。', 'No sessions in this workspace.'))
2049
- : w.sessions.map(s => h('div', {
2127
+ : (Array.isArray(w.sessions) ? w.sessions : []).map(s => h('div', {
2050
2128
  key: s.id,
2051
2129
  style: {
2052
2130
  display: 'flex', alignItems: 'center', gap: '8px', fontSize: '12px', lineHeight: '18px',
@@ -2156,6 +2234,7 @@ window.__ModuleLoader__.load({
2156
2234
  return h('div', { style: S.card },
2157
2235
  h('div', { style: S.cardTitle }, M('同步内容', 'Sync content')),
2158
2236
  h('div', { style: S.hint }, err ? M(`读取失败:${err}`, `Read failed: ${err}`) : M('正在读取同步范围…', 'Loading sync scope…')),
2237
+ err ? h('button', { type: 'button', style: S.btn, disabled: busy, onClick: load }, M('重试', 'Retry')) : null,
2159
2238
  )
2160
2239
  }
2161
2240
 
@@ -2203,6 +2282,7 @@ window.__ModuleLoader__.load({
2203
2282
  const groupOn = g.enabled !== false
2204
2283
  const canExpand = items.length > 0
2205
2284
  return h('div', {
2285
+ key: g.id,
2206
2286
  style: { borderTop: '1px solid var(--dsw-alias-border-l1)', paddingTop: '6px', paddingBottom: '2px' },
2207
2287
  },
2208
2288
  // 整行可点:点一下展开明细,再点收起(不再单独放「明细」按钮)
@@ -2248,6 +2328,7 @@ window.__ModuleLoader__.load({
2248
2328
  },
2249
2329
  },
2250
2330
  items.map((i) => h('label', {
2331
+ key: i.id,
2251
2332
  style: {
2252
2333
  display: 'flex', gap: '8px', alignItems: 'center', fontSize: '12px',
2253
2334
  cursor: editing ? 'pointer' : 'default', opacity: groupOn ? 1 : 0.6,
@@ -2292,6 +2373,8 @@ window.__ModuleLoader__.load({
2292
2373
  const [busy, setBusy] = react.useState('')
2293
2374
  const [err, setErr] = react.useState('')
2294
2375
  const [msg, setMsg] = react.useState('')
2376
+ const [liveLocal, setLiveLocal] = react.useState(null)
2377
+ const [nowTick, setNowTick] = react.useState(() => Date.now())
2295
2378
 
2296
2379
  const save = async (patch) => {
2297
2380
  setBusy('save'); setErr(''); setMsg('')
@@ -2304,14 +2387,31 @@ window.__ModuleLoader__.load({
2304
2387
 
2305
2388
  const act = async (action, extra) => {
2306
2389
  setBusy(action); setErr(''); setMsg('')
2390
+ if (action === 'push-live') {
2391
+ setLiveLocal({
2392
+ running: true,
2393
+ startedAt: Date.now(),
2394
+ finishedAt: 0,
2395
+ ok: null,
2396
+ phase: 'starting',
2397
+ message: initMode
2398
+ ? M('正在核对云端状态并启动初始化推送…', 'Checking cloud state and starting initialize push…')
2399
+ : M('正在核对云端状态并启动后台推送…', 'Checking cloud state and starting background push…'),
2400
+ recent: [],
2401
+ initPush: initMode,
2402
+ })
2403
+ }
2307
2404
  try {
2308
2405
  const res = await fetch('/config-sync/auto', {
2309
2406
  method: 'POST', cache: 'no-store', credentials: 'same-origin',
2310
- headers: jsonHeaders,
2407
+ headers: jsonHeaders(),
2311
2408
  body: JSON.stringify({ action, ...(extra || {}) }),
2312
2409
  })
2313
2410
  const text = await res.text()
2314
- const body = text ? JSON.parse(text) : null
2411
+ let body
2412
+ // 这一处原来是全文件唯一没有 try 的 JSON.parse:宿主代理回一页 HTML 错误时,
2413
+ // 用户看到的是 "Unexpected token '<'" 这种噪声,而不是「500 返回非 JSON」。
2414
+ try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
2315
2415
  if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
2316
2416
  if (action === 'check') {
2317
2417
  const d = body.drift
@@ -2319,16 +2419,17 @@ window.__ModuleLoader__.load({
2319
2419
  ? M(`云端:落后 ${d.behind} 个提交,领先 ${d.ahead} 个提交`, `Cloud: ${d.behind} commit(s) behind, ${d.ahead} ahead`)
2320
2420
  : (body.error || M('读不到远端', 'Cannot read the remote')))
2321
2421
  } 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'))
2422
+ if (body.livePush) setLiveLocal(body.livePush)
2325
2423
  } else {
2326
2424
  setMsg(body.closeRequested
2327
2425
  ? M('已排队:客户端马上关闭,退出后执行;拉取完成后按设置自动重开', 'Queued: the client closes now and the sync runs after exit; it relaunches per your settings when pulling finishes')
2328
2426
  : M('已排队:退出 DSH 后自动执行', 'Queued: runs automatically after DSH exits'))
2329
2427
  }
2330
- if (typeof props.onSaved === 'function') props.onSaved()
2331
- } catch (e) { setErr(String((e && e.message) || e)) } finally { setBusy('') }
2428
+ if (typeof props.onSaved === 'function') props.onSaved(action === 'push-live' ? { silent: true } : undefined)
2429
+ } catch (e) {
2430
+ if (action === 'push-live') setLiveLocal(null)
2431
+ setErr(String((e && e.message) || e))
2432
+ } finally { setBusy('') }
2332
2433
  }
2333
2434
 
2334
2435
  const sw = (patchKey, stateKey, label, hintText) => {
@@ -2363,10 +2464,39 @@ window.__ModuleLoader__.load({
2363
2464
  }
2364
2465
 
2365
2466
  const pending = auto.pending
2366
- const livePush = auto.livePush || null
2467
+ const serverLive = auto.livePush || null
2468
+ const hasServerLive = Boolean(serverLive && (serverLive.running || serverLive.finishedAt))
2469
+ // 后端状态一旦到齐(或已有更新时间戳)就以真实状态为准,避免旧的乐观占位盖住真实进度
2470
+ const livePush = hasServerLive && (!liveLocal || serverLive.startedAt >= (liveLocal.startedAt || 0) - 2000)
2471
+ ? serverLive
2472
+ : (liveLocal || serverLive)
2367
2473
  const liveRunning = Boolean(livePush && livePush.running)
2474
+ react.useEffect(() => {
2475
+ if (!liveRunning) return undefined
2476
+ setNowTick(Date.now())
2477
+ const timer = setInterval(() => setNowTick(Date.now()), 1000)
2478
+ return () => clearInterval(timer)
2479
+ }, [liveRunning])
2480
+ react.useEffect(() => {
2481
+ if (hasServerLive && !serverLive.running && liveLocal) setLiveLocal(null)
2482
+ }, [hasServerLive, serverLive && serverLive.running, serverLive && serverLive.finishedAt])
2368
2483
  // 后台调度拿不到请求语言,宿主把原因中英各存一份,这里按当前界面语言挑
2369
2484
  const pendingReason = pending ? (langIsZh() ? (pending.reasonZh || pending.reason) : (pending.reasonEn || pending.reason)) : ''
2485
+ const liveSteps = (() => {
2486
+ if (!livePush) return []
2487
+ const isWebdav = livePush.transport === 'webdav' || Boolean(props.data && props.data.webdav && props.data.webdav.active)
2488
+ const base = []
2489
+ if (livePush.initPush) base.push({ key: 'init', label: M('初始化仓库', 'Init repo') })
2490
+ base.push({ key: 'capture', label: M('抓取配置', 'Capture') })
2491
+ if (!isWebdav) base.push({ key: 'commit', label: M('提交变更', 'Commit') })
2492
+ base.push({ key: 'upload', label: isWebdav ? M('上传 WebDAV', 'Upload WebDAV') : M('推送远端', 'Push remote') })
2493
+ return base
2494
+ })()
2495
+ const phaseRank = { starting: -1, init: 0, capture: 1, commit: 2, upload: 3, done: 99, error: -2 }
2496
+ const curRank = phaseRank[String((livePush && livePush.phase) || 'starting')] ?? -1
2497
+ const elapsedSec = (livePush && livePush.startedAt)
2498
+ ? Math.max(0, Math.floor(((livePush.finishedAt || nowTick) - livePush.startedAt) / 1000))
2499
+ : 0
2370
2500
  return h('div', { style: S.card },
2371
2501
  h('div', { style: S.cardHead },
2372
2502
  h('div', { style: S.cardTitle }, M('自动同步', 'Auto sync')),
@@ -2410,11 +2540,13 @@ window.__ModuleLoader__.load({
2410
2540
  ? M('不关闭 DSH 直接在后台抓配置并上传(只读本地配置,安全不打断当前对话)', 'Capture and push in background without closing DSH')
2411
2541
  : M('云端已有内容:本机还是空的,先拉取', 'The cloud already has content — pull first'),
2412
2542
  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)'))),
2543
+ }, busy === 'push-live'
2544
+ ? M('准备启动…', 'Starting…')
2545
+ : (liveRunning
2546
+ ? M('后台推送中…', 'Pushing in background…')
2547
+ : (initMode
2548
+ ? M('初始化推送(不关 DSH)', 'Initialize push (keep DSH open)')
2549
+ : M('立即推送(不关 DSH)', 'Push now (keep DSH open)')))),
2418
2550
  h('button', {
2419
2551
  type: 'button',
2420
2552
  style: (pushAllowed && !liveRunning) ? S.btn : { ...S.btn, opacity: 0.5, cursor: 'not-allowed' },
@@ -2431,7 +2563,8 @@ window.__ModuleLoader__.load({
2431
2563
  livePush && (livePush.running || livePush.finishedAt)
2432
2564
  ? h('div', {
2433
2565
  style: {
2434
- padding: '8px 10px', borderRadius: '8px', fontSize: '12px', lineHeight: '18px',
2566
+ padding: '9px 11px', borderRadius: '8px', fontSize: '12px', lineHeight: '18px',
2567
+ display: 'flex', flexDirection: 'column', gap: '6px',
2435
2568
  border: '1px solid ' + (livePush.running
2436
2569
  ? 'var(--dsw-alias-toast-action)'
2437
2570
  : (livePush.ok ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-state-error-primary)')),
@@ -2441,15 +2574,56 @@ window.__ModuleLoader__.load({
2441
2574
  : (livePush.ok ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-state-error-primary)'),
2442
2575
  },
2443
2576
  },
2444
- h('div', { style: { fontWeight: 600 } },
2445
- (livePush.running ? '⏳ ' : (livePush.ok ? '✓ ' : '✕ ')) + (livePush.message || '')),
2577
+ h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px', flexWrap: 'wrap' } },
2578
+ h('div', { style: { fontWeight: 600 } },
2579
+ (livePush.running ? '⏳ ' : (livePush.ok ? '✓ ' : '✕ ')) + (livePush.message || '')),
2580
+ h('div', { style: { ...S.footnote, fontFamily: 'Consolas, ui-monospace, monospace' } },
2581
+ livePush.running
2582
+ ? M(`已耗时 ${elapsedSec}s`, `${elapsedSec}s elapsed`)
2583
+ : M(`耗时 ${elapsedSec}s`, `${elapsedSec}s`)),
2584
+ ),
2585
+ liveSteps.length
2586
+ ? h('div', { style: { display: 'flex', gap: '6px', flexWrap: 'wrap', alignItems: 'center' } },
2587
+ liveSteps.map((st, idx) => {
2588
+ const stRank = phaseRank[st.key] ?? idx
2589
+ const done = livePush.phase === 'done' || (curRank > stRank && curRank >= 0)
2590
+ const active = livePush.running && curRank === stRank
2591
+ const failed = !livePush.running && livePush.ok === false && curRank === stRank
2592
+ return h('span', {
2593
+ key: st.key,
2594
+ style: {
2595
+ ...S.chip,
2596
+ border: '1px solid ' + (active
2597
+ ? 'var(--dsw-alias-toast-action)'
2598
+ : (done
2599
+ ? 'var(--dsw-alias-state-success-primary)'
2600
+ : (failed ? 'var(--dsw-alias-state-error-primary)' : 'var(--dsw-alias-border-l1)'))),
2601
+ background: done
2602
+ ? 'var(--dsw-alias-state-success-tertiary)'
2603
+ : (failed ? 'var(--dsw-alias-state-error-tertiary, var(--dsw-alias-file-diff-deleted-bg))' : 'var(--dsw-alias-bg-base)'),
2604
+ color: active
2605
+ ? 'var(--dsw-alias-toast-action)'
2606
+ : (done ? 'var(--dsw-alias-label-primary)' : 'var(--dsw-alias-label-secondary)'),
2607
+ fontWeight: active ? 600 : 500,
2608
+ },
2609
+ }, `${done ? '✓ ' : (active ? '▸ ' : (failed ? '✕ ' : ''))}${idx + 1}. ${st.label}`)
2610
+ }))
2611
+ : null,
2612
+ (livePush.running || livePush.ok === false) && Array.isArray(livePush.recent) && livePush.recent.length
2613
+ ? h('div', {
2614
+ style: {
2615
+ ...S.code, padding: '6px 8px', fontSize: '11px', lineHeight: '16px',
2616
+ maxHeight: '96px', overflowY: 'auto',
2617
+ },
2618
+ }, livePush.recent.join('\n'))
2619
+ : null,
2446
2620
  livePush.finishedAt
2447
- ? h('div', { style: { ...S.footnote, marginTop: '2px' } },
2621
+ ? h('div', { style: S.footnote },
2448
2622
  M(`完成时间:${new Date(livePush.finishedAt).toLocaleTimeString(localeNow(), { hour12: false })}`,
2449
2623
  `Finished at: ${new Date(livePush.finishedAt).toLocaleTimeString(localeNow(), { hour12: false })}`)
2450
2624
  + (livePush.log ? ` · ${livePush.log}` : ''))
2451
2625
  : (livePush.log
2452
- ? h('div', { style: { ...S.footnote, marginTop: '2px' } }, M(`日志:${livePush.log}`, `Log: ${livePush.log}`))
2626
+ ? h('div', { style: S.footnote }, M(`日志:${livePush.log}`, `Log: ${livePush.log}`))
2453
2627
  : null),
2454
2628
  )
2455
2629
  : null,
@@ -2691,12 +2865,24 @@ window.__ModuleLoader__.load({
2691
2865
  setUpdBusy(true)
2692
2866
  setUpdMsg(M('DSH 即将退出,退出后安装并自动重启…', 'DSH will exit; the package is installed afterwards and DSH relaunches…'))
2693
2867
  try {
2694
- await callUpdate({ action: 'install-restart' })
2695
- showToast(M('DSH 即将退出并自动安装、重启…', 'DSH will exit, install, and relaunch…'))
2868
+ const r = await callUpdate({ action: 'install-restart' })
2869
+ // closeRequested=false 说明后端没能让客户端退出(taskkill 被拦 / app.quit 被模态框挡住),
2870
+ // 这时再喊「马上退出」就是骗人:安装要等到真的退出之后才会发生。
2871
+ if (r && r.closeRequested === false) {
2872
+ setUpdMsg(M('已排队:没能让客户端自动退出,请手动完全退出 DSH,退出后会自动安装并重启',
2873
+ 'Queued: the client did not exit automatically. Quit DSH fully; the install and relaunch run afterwards.'))
2874
+ showToast(M('已排队:请手动退出 DSH(窗口 + 托盘),退出后自动安装并重启',
2875
+ 'Queued: quit DSH fully (window and tray); install and relaunch run afterwards.'))
2876
+ } else {
2877
+ showToast(M('DSH 即将退出并自动安装、重启…', 'DSH will exit, install, and relaunch…'))
2878
+ }
2696
2879
  } catch (e) {
2697
2880
  const msg = String((e && e.message) || e)
2698
2881
  setUpdMsg(M('安装失败:', 'Install failed: ') + msg)
2699
2882
  showToast(M('安装失败:', 'Install failed: ') + msg)
2883
+ } finally {
2884
+ // 必须复位:退出没真的发生时(上面 closeRequested=false 就是这种),
2885
+ // 卡上 7 个按钮会全部 disabled 且本会话内没有复位入口。
2700
2886
  setUpdBusy(false)
2701
2887
  }
2702
2888
  }
@@ -2768,7 +2954,9 @@ window.__ModuleLoader__.load({
2768
2954
  await callAuto({ action: 'check' })
2769
2955
  } catch { /* 检查失败不该挡住页面,状态行会显示失败原因 */ }
2770
2956
  if (alive) setChecking(false)
2771
- if (alive && typeof refresh === 'function') refresh()
2957
+ // 静默刷新:这里是每 2 分钟的自动复查。用非静默的 refresh() 会把整页 busy 置真
2958
+ //(按钮周期性变灰),网络抖动时还会把「读取失败」写进页面,而 data 明明是有效的。
2959
+ if (alive && typeof refresh === 'function') refresh({ silent: true })
2772
2960
  }
2773
2961
  run()
2774
2962
  const timer = setInterval(run, 2 * 60 * 1000)
@@ -2777,14 +2965,22 @@ window.__ModuleLoader__.load({
2777
2965
 
2778
2966
  const lastLiveFinishedRef = react.useRef(0)
2779
2967
 
2780
- const jumpToSection = (sid, opts) => {
2968
+ const jumpToSection = (sidOrTarget, opts) => {
2969
+ const sid = (sidOrTarget && typeof sidOrTarget === 'object') ? sidOrTarget.section : sidOrTarget
2970
+ const options = (sidOrTarget && typeof sidOrTarget === 'object') ? sidOrTarget : opts
2781
2971
  if (!sid) return
2782
- if (opts && opts.openRoots && !showRoots) setShowRoots(true)
2972
+ if (options && options.openRoots && !showRoots) setShowRoots(true)
2783
2973
  setActiveSection(sid)
2784
2974
  const scrollNow = () => {
2785
2975
  const el = document.getElementById('sync-section-' + sid)
2786
- if (!el || !el.scrollIntoView) return
2787
- el.scrollIntoView({ behavior: 'smooth', block: 'start' })
2976
+ if (!el) return
2977
+ const body = bodyRef && bodyRef.current
2978
+ if (body && typeof body.scrollTo === 'function') {
2979
+ const top = el.getBoundingClientRect().top - body.getBoundingClientRect().top + body.scrollTop - 8
2980
+ body.scrollTo({ top: Math.max(0, top), behavior: 'smooth' })
2981
+ } else if (typeof el.scrollIntoView === 'function') {
2982
+ el.scrollIntoView({ behavior: 'smooth', block: 'start' })
2983
+ }
2788
2984
  try {
2789
2985
  if (typeof el.animate === 'function') {
2790
2986
  el.animate([
@@ -2794,21 +2990,34 @@ window.__ModuleLoader__.load({
2794
2990
  }
2795
2991
  } catch { }
2796
2992
  }
2797
- if (opts && opts.openRoots && !showRoots) {
2993
+ if (options && options.openRoots && !showRoots) {
2798
2994
  setTimeout(scrollNow, 60)
2799
2995
  } else {
2800
2996
  scrollNow()
2801
2997
  }
2802
2998
  }
2803
2999
 
2804
- // 后台在线推送进行中时,每 1.5s 轮询状态直到结束,并弹出完成/失败提示
2805
3000
  const liveRunning = Boolean(data && data.auto && data.auto.livePush && data.auto.livePush.running)
3001
+ // 后台在线推送进行中时,每 800ms 静默轮询状态直到结束,并弹出完成/失败提示。
3002
+ // 用「自调度 setTimeout + in-flight 门闩」而不是 setInterval:/status 要跑备份枚举与本机待推送统计,
3003
+ // 推送期间经常超过 800ms,setInterval 会让请求不断叠加(失败还要退避重试,越叠越多)。
2806
3004
  react.useEffect(() => {
2807
3005
  if (!liveRunning) return undefined
2808
- const timer = setInterval(() => {
2809
- if (typeof refresh === 'function') refresh()
2810
- }, 1500)
2811
- return () => clearInterval(timer)
3006
+ let alive = true
3007
+ let pending = false
3008
+ let timer = null
3009
+ const tick = async () => {
3010
+ if (!alive) return
3011
+ if (!pending) {
3012
+ pending = true
3013
+ try {
3014
+ if (typeof refresh === 'function') await refresh({ silent: true })
3015
+ } catch { /* 静默轮询失败不影响页面 */ } finally { pending = false }
3016
+ }
3017
+ if (alive) timer = setTimeout(tick, 800)
3018
+ }
3019
+ timer = setTimeout(tick, 800)
3020
+ return () => { alive = false; if (timer) clearTimeout(timer) }
2812
3021
  }, [liveRunning])
2813
3022
 
2814
3023
  react.useEffect(() => {
@@ -2889,9 +3098,11 @@ window.__ModuleLoader__.load({
2889
3098
  const failed = !has && u.ok === false && !restartRequired
2890
3099
  const kind = (restartRequired || preparedReady || has) ? 'warn' : (failed ? 'error' : 'ok')
2891
3100
  const notesText = (u.remote && (langIsZh() ? (u.remote.notes || u.remote.notesEn) : (u.remote.notesEn || u.remote.notes))) || ''
2892
- // 检查失败时把每个源的失败原因摆出来,别只给一句 aborted
3101
+ // 检查失败时仅在 error 尚未带明细时补充 sourceNote,避免把各源报错打印两遍
2893
3102
  const badSources = (Array.isArray(u.sources) ? u.sources : []).filter((x) => x && x.ok === false)
2894
- const sourceNote = badSources.length
3103
+ const errText = String(u.error || '')
3104
+ const alreadyDetailed = badSources.length > 0 && badSources.some((x) => errText.includes(x.host || x.url || ''))
3105
+ const sourceNote = (badSources.length && !alreadyDetailed)
2895
3106
  ? M(
2896
3107
  `(${badSources.map((x) => `${x.host || x.url}: ${x.error || '失败'}`).join(';')})`,
2897
3108
  ` (${badSources.map((x) => `${x.host || x.url}: ${x.error || 'failed'}`).join('; ')})`,
@@ -2966,15 +3177,15 @@ window.__ModuleLoader__.load({
2966
3177
  h('input', {
2967
3178
  type: 'text', style: S.input, value: updToken, spellCheck: false,
2968
3179
  placeholder: cfg.tokenSet
2969
- ? M('已配置;留空表示不改', 'Already set; leave empty to keep it')
2970
- : M('Gitee 私人令牌(私有库必填)', 'Gitee personal token (required for private repos)'),
3180
+ ? M('已配置;留空表示不改(支持 $GITHUB_TOKEN 读取环境变量)', 'Already set; leave empty to keep (or enter $GITHUB_TOKEN for env var)')
3181
+ : M('GitHub / Gitee 令牌,或填 $GITHUB_TOKEN 读取本机环境变量', 'GitHub / Gitee token, or $GITHUB_TOKEN to read from env'),
2971
3182
  onChange: (e) => setUpdToken(e.target.value),
2972
3183
  }),
2973
3184
  ),
2974
3185
  h('div', { style: S.actions },
2975
3186
  h('button', { type: 'button', style: S.btnPrimary, disabled: updBusy, onClick: saveUpdConfig }, updBusy ? M('保存中…', 'Saving…') : M('保存', 'Save')),
2976
3187
  h('button', { type: 'button', style: S.btn, disabled: updBusy, onClick: cancelEditUpd }, M('取消', 'Cancel')),
2977
- cfg.tokenSet
3188
+ cfg.tokenSaved
2978
3189
  ? h('button', { type: 'button', style: S.btn, disabled: updBusy, onClick: clearUpdToken }, M('清除已存令牌', 'Clear stored token'))
2979
3190
  : null,
2980
3191
  ),
@@ -2983,7 +3194,7 @@ window.__ModuleLoader__.load({
2983
3194
  h(Kv, {
2984
3195
  k: M('更新清单', 'Manifest'),
2985
3196
  v: cfg.manifestUrlIsDefault
2986
- ? M('内置默认(jsDelivr → GitHub raw 依次尝试)', 'Built-in default (jsDelivr → GitHub raw in order)')
3197
+ ? M('内置默认(GitHub API / gh-proxy / ghfast / GitHub raw 依次尝试)', 'Built-in default (GitHub API / gh-proxy / ghfast / GitHub raw in order)')
2987
3198
  : (cfg.manifestUrl || '…'),
2988
3199
  }),
2989
3200
  h(Kv, {
@@ -2994,9 +3205,15 @@ window.__ModuleLoader__.load({
2994
3205
  }),
2995
3206
  h(Kv, {
2996
3207
  k: M('更新令牌', 'Token'),
2997
- v: cfg.tokenSet
2998
- ? M('已配置(只存本机)', 'Set (stored on this machine only)')
2999
- : M('未配置(私有库会读不到清单)', 'Not set (private repos cannot be read)'),
3208
+ v: cfg.tokenSource === 'env' && cfg.tokenEnv
3209
+ ? M(`已从环境变量 ${cfg.tokenEnv} 读取(不落盘、绝不推送)`, `From env var ${cfg.tokenEnv} (not stored, never pushed)`)
3210
+ : cfg.tokenSource === 'git-credential'
3211
+ ? M('已从本机 git 凭据自动读取(不落盘、绝不推送)', 'From local git credential (not stored, never pushed)')
3212
+ : cfg.tokenSource === 'gh-cli'
3213
+ ? M('已从 GitHub CLI (gh) 自动读取(不落盘、绝不推送)', 'From GitHub CLI (gh) (not stored, never pushed)')
3214
+ : cfg.tokenSet
3215
+ ? M('已配置(仅存本机,绝不推送)', 'Set (local only, never pushed)')
3216
+ : M('未配置(公开库可不填;私有库可用本机 GitHub 登录、$GITHUB_TOKEN 或填入令牌)', 'Not set (optional for public repos; private repos use local GitHub login, $GITHUB_TOKEN, or a token)'),
3000
3217
  }),
3001
3218
  u.remote && u.remote.npmTgzUrls && u.remote.npmTgzUrls.length
3002
3219
  ? h(Kv, {
@@ -3204,11 +3421,9 @@ window.__ModuleLoader__.load({
3204
3421
  )
3205
3422
 
3206
3423
  const workspaceViewCard = h(WorkspaceViewCard, {})
3207
- const remoteCard = data ? h(RemoteCard, { data, onSaved: refresh }) : null
3424
+ const cloudCard = data ? h(CloudTargetCard, { data, onSaved: refresh }) : null
3208
3425
  const autoCard = data ? h(AutoCard, { data, onSaved: refresh }) : null
3209
- // 0.4.0:跨端状态卡(只读)与 WebDAV 同步方式卡
3210
3426
  const platformCard = h(PlatformCard, { data })
3211
- const webdavCard = h(WebdavCard, { onSaved: refresh })
3212
3427
  // 「还原备份」自己拿 status 里的 backup 段(快照列表),改动后让父层 refresh 重新读
3213
3428
  const restoreCard = data ? h(RestoreCard, { data, onSaved: refresh }) : null
3214
3429
  // 「同步内容」卡自己拉 /config-sync/scope,不依赖 status(status 读的是仓库与本机,跟勾选无关)
@@ -3232,7 +3447,7 @@ window.__ModuleLoader__.load({
3232
3447
  h('div', { ref: headerRef, style: S.pageHeader },
3233
3448
  h('div', { style: S.pageHeaderMain },
3234
3449
  h('div', { style: S.pageTitleRow },
3235
- h('div', { style: S.pageTitle }, M('配置同步', 'Config Sync')),
3450
+ h('div', { style: S.pageTitle }, M('配置备份与同步', 'Config Backup & Sync')),
3236
3451
  h('div', { style: S.badgeGroup },
3237
3452
  h('span', { style: S.badgeKey }, M('本机', 'local')),
3238
3453
  h('span', { style: chipStyle(summary.kind) }, chipLabel(summary.kind)),
@@ -3244,20 +3459,29 @@ window.__ModuleLoader__.load({
3244
3459
  ),
3245
3460
  ),
3246
3461
  // 一行元信息:版本与仓库位置。状态说明交给上面的徽标和下面的指标条,这里不再重复。
3462
+ // 仓库位置只在真有 git 分支时才写 branch @ head;WebDAV 模式退化成写传输方式,
3463
+ // 免得出现「app x / Electron y · ? @ ?」这种看着像坏掉的尾巴。
3247
3464
  h('div', { style: S.meta },
3248
3465
  data ? [
3249
3466
  h('span', { key: 'app' }, `app ${data.version.local || '?'} / Electron ${data.version.electron || '?'}`),
3250
- data.repo && data.repo.exists
3251
- ? [
3252
- h('span', { key: 's2', style: S.metaSep }, '·'),
3253
- h('span', { key: 'repo' }, `${data.repo.branch || '?'} @ ${(data.repo.head || '').split(' ')[0] || '?'}`),
3254
- ]
3255
- : null,
3467
+ (() => {
3468
+ const label = data.repo && data.repo.exists
3469
+ ? (data.repo.branch || data.repo.head
3470
+ ? `${data.repo.branch || '?'} @ ${(data.repo.head || '').split(' ')[0] || '?'}`
3471
+ : (data.webdav && data.webdav.active ? 'WebDAV' : ''))
3472
+ : ''
3473
+ return label
3474
+ ? [
3475
+ h('span', { key: 's2', style: S.metaSep }, '·'),
3476
+ h('span', { key: 'repo' }, label),
3477
+ ]
3478
+ : null
3479
+ })(),
3256
3480
  ] : h('span', null, summary.text),
3257
3481
  ),
3258
3482
  h('div', { style: S.pageLead },
3259
- M('配置在本机、仓库、云端之间流转。改完立即生效;写回与还原在退出客户端后执行。',
3260
- 'Configs flow between this machine, the repo and the cloud. Edits apply at once; write-back and restore run after the client quits.')),
3483
+ M('多端配置备份、同步与还原:本机 → 仓库 → 云端 → 另一台机器。改完立即生效;写回与还原在退出客户端后执行。',
3484
+ 'Multi-device backup, sync and restore: this machine → repo → cloud → another machine. Edits apply at once; write-back and restore run after the client quits.')),
3261
3485
  ),
3262
3486
  h('div', { style: S.headerActions },
3263
3487
  // 「本机路径」区唯一的入口:平时普通按钮,只有根外路径/被覆盖这两类告警才变橙并带数字
@@ -3285,7 +3509,7 @@ window.__ModuleLoader__.load({
3285
3509
  ...(conflictCard ? [['conflict', M('同步冲突', 'Sync conflicts')]] : []),
3286
3510
  ...(showRoots ? [['roots', M('本机路径', 'Local paths')]] : []),
3287
3511
  ['targets', M('同步目标', 'Targets')],
3288
- ['platform', M('跨端/传输', 'Platform')],
3512
+ ['platform', M('跨端状态', 'Platform')],
3289
3513
  ['automation', M('自动化', 'Automation')],
3290
3514
  ['actions', M('生成脚本', 'Scripts')],
3291
3515
  ['restore', M('还原备份', 'Restore')],
@@ -3336,9 +3560,8 @@ window.__ModuleLoader__.load({
3336
3560
  ? Section(M('同步冲突', 'Sync conflicts'), M('这些文件挡住了拉取:逐项选完保存,再点「立即拉取」', 'These files block the pull: pick per file, save, then pull'), [conflictCard], 'conflict')
3337
3561
  : null,
3338
3562
  Section(M('本机路径', 'Local paths'), M('每台机器确认一次即可:仓库里用占位符,落地时按这里展开', 'Confirm once per machine: the repo stores placeholders, expanded with these paths'), [rootsCard], 'roots'),
3339
- Section(M('同步目标', 'Sync targets'), M('仓库与远端都是本机设置,改完即生效', 'Repo and remote are local settings, applied at once'), [repoCard, remoteCard].filter(Boolean), 'targets'),
3340
- // 0.4.0:跨端状态与 WebDAV 方式紧随同步目标,便于「先确认平台、再选传输」
3341
- Section(M('跨端与同步方式', 'Platform & transport'), M('本机平台、仓库契约来自哪个平台、是否改用 WebDAV', 'Local platform, which platform the contract came from, and whether to use WebDAV'), [platformCard, webdavCard].filter(Boolean), 'platform'),
3563
+ Section(M('同步目标', 'Sync targets'), M('本机仓库、同步方式(Git / WebDAV)与云端目标统一在这里设置', 'Local repo, sync transport (Git / WebDAV), and cloud target settings'), [repoCard, cloudCard].filter(Boolean), 'targets'),
3564
+ Section(M('跨端状态', 'Cross-platform'), M('本机平台、仓库契约来自哪个平台与已登记机器', 'Local platform, which platform the contract came from, and registered machines'), [platformCard].filter(Boolean), 'platform'),
3342
3565
  Section(M('自动化与插件更新', 'Automation & plugin update'), M('退出后自动做什么、插件自己怎么升级', 'What runs automatically after exit, and how the plugin upgrades'), [autoCard, updCard].filter(Boolean), 'automation'),
3343
3566
  Section(M('退出后执行', 'After exit'), M('生成脚本 → 退出客户端后跑一遍', 'Generate the script → it runs after the client quits'), [actionCard], 'actions'),
3344
3567
  Section(M('还原备份', 'Restore backup'), M('点快照 → 确认差异 → 排队还原(退出客户端后执行)', 'Pick a snapshot → confirm the diff → queued restore (runs after the client quits)'), [restoreCard].filter(Boolean), 'restore'),
@@ -3381,7 +3604,13 @@ window.__ModuleLoader__.load({
3381
3604
  try {
3382
3605
  const r = await callRoots()
3383
3606
  setData(r)
3384
- if (editing) setDraft(snap(r))
3607
+ const next = snap(r)
3608
+ // 两件事一起判:
3609
+ // ① 编辑态下不用服务端值覆盖未保存的草稿(手填的路径会无声消失);
3610
+ // ② 一个根都没探测到(forced:没路径就先填)时也要把空草稿灌进去,
3611
+ // 否则输入框永远不出现、保存按钮恒 disabled,「首次填根」直接成死局。
3612
+ const noRoots = !(next.appRoot || next.dshHome || next.workspaceHome)
3613
+ if (!draft && (editing || noRoots)) setDraft(next)
3385
3614
  } catch (e) {
3386
3615
  setErr(String((e && e.message) || e))
3387
3616
  } finally { setBusy(false) }
@@ -3633,11 +3862,12 @@ window.__ModuleLoader__.load({
3633
3862
  */
3634
3863
  /** 问题反馈:提交即建 GitHub Issue(label feedback),列表读 Issue,点「已解决」就关单。 */
3635
3864
  function FeedbackCard() {
3636
- const empty = { connected: false, repo: '', label: 'feedback', items: [], counts: { open: 0, closed: 0, total: 0 }, outbox: [], error: '', ghFile: '', version: '', owner: '', login: '', canClose: false, readAnon: false, note: '' }
3865
+ const empty = { connected: false, repo: '', defaultRepo: '', label: 'feedback', items: [], counts: { open: 0, closed: 0, total: 0 }, outbox: [], error: '', ghFile: '', version: '', owner: '', login: '', canClose: false, readAnon: false, note: '', tokenPresent: false, tokenSource: 'none', tokenEnv: '', tokenSaved: false, envCandidates: [] }
3637
3866
  const [st, setSt] = react.useState(empty)
3638
3867
  const [title, setTitle] = react.useState('')
3639
3868
  const [text, setText] = react.useState('')
3640
3869
  const [token, setToken] = react.useState('')
3870
+ const [repoInput, setRepoInput] = react.useState('')
3641
3871
  const [askToken, setAskToken] = react.useState(false)
3642
3872
  const [busy, setBusy] = react.useState(false)
3643
3873
  const [msg, setMsg] = react.useState('')
@@ -3646,17 +3876,18 @@ window.__ModuleLoader__.load({
3646
3876
  const [filter, setFilter] = react.useState('open')
3647
3877
  const [kw, setKw] = react.useState('')
3648
3878
 
3649
- const load = async () => {
3879
+ const load = async (forceRefresh = false) => {
3650
3880
  setBusy(true)
3651
3881
  try {
3652
- const r = await callFeedback(null)
3882
+ const r = await callFeedback(null, forceRefresh ? { query: { refresh: '1' } } : undefined)
3653
3883
  setSt({ ...empty, ...r })
3884
+ if (r && r.repo && !askToken) setRepoInput(String(r.repo))
3654
3885
  setErr(String(r.error || ''))
3655
3886
  } catch (e) {
3656
3887
  setErr(String((e && e.message) || e))
3657
3888
  } finally { setBusy(false) }
3658
3889
  }
3659
- react.useEffect(() => { load() }, [])
3890
+ react.useEffect(() => { load(false) }, [])
3660
3891
 
3661
3892
  const submit = async () => {
3662
3893
  setBusy(true); setErr(''); setMsg('')
@@ -3680,14 +3911,29 @@ window.__ModuleLoader__.load({
3680
3911
  } finally { setBusy(false) }
3681
3912
  }
3682
3913
 
3683
- const saveToken = async () => {
3914
+ const saveToken = async (opts = {}) => {
3684
3915
  setBusy(true); setErr(''); setMsg('')
3685
3916
  try {
3686
- await callFeedback({ token }, { query: { action: 'token' } })
3917
+ const body = { repo: (opts.repo || repoInput || st.repo || '').trim() }
3918
+ if (opts.clearToken) {
3919
+ body.clearToken = true
3920
+ body.clearEnv = Boolean(opts.clearEnv)
3921
+ } else if (opts.tokenEnv) {
3922
+ body.tokenEnv = String(opts.tokenEnv).trim()
3923
+ } else if (token.trim()) {
3924
+ body.token = token.trim()
3925
+ }
3926
+ const res = await callFeedback(body, { query: { action: 'token' } })
3687
3927
  setToken('')
3688
3928
  setAskToken(false)
3689
- setMsg(M('令牌已存到本机(不进仓库),连接正常。', 'Token saved locally (never committed); connection works.'))
3690
- await load()
3929
+ if (opts.clearToken) {
3930
+ setMsg(M('已清除本机保存的明文令牌(后续优先读本机环境变量或 git 凭据,绝不推送进同步仓库)。', 'Cleared the stored plaintext token (env vars / git credential will be used instead, never pushed).'))
3931
+ } else if (res && res.tokenSource === 'env') {
3932
+ setMsg(M(`已绑定环境变量 ${res.tokenEnv || ''}(实时读取,不写入明文令牌,绝不推送进同步仓库)。`, `Bound env var ${res.tokenEnv || ''} (read dynamically, no plaintext token saved or pushed).`))
3933
+ } else {
3934
+ setMsg(M('已保存到本机私有配置(绝不推送进同步仓库),连接正常。', 'Saved locally (never committed or pushed); connection works.'))
3935
+ }
3936
+ await load(true)
3691
3937
  } catch (e) {
3692
3938
  setErr(String((e && e.message) || e))
3693
3939
  } finally { setBusy(false) }
@@ -3744,40 +3990,109 @@ window.__ModuleLoader__.load({
3744
3990
  onClick: () => setFilter(key),
3745
3991
  }, label)
3746
3992
 
3993
+ const tokenSourceHint = () => {
3994
+ if (st.note) return st.note
3995
+ if (st.tokenSource === 'env' && st.tokenEnv) {
3996
+ return M(
3997
+ `令牌来源:本机环境变量 ${st.tokenEnv}(实时读取,不落盘、绝不推送进同步仓库);仓库记在 ${st.ghFile || 'config-sync-gh.json'}`,
3998
+ `Token source: local env var ${st.tokenEnv} (read dynamically, never saved or pushed); repo lives in ${st.ghFile || 'config-sync-gh.json'}`,
3999
+ )
4000
+ }
4001
+ if (st.tokenSource === 'git-credential') {
4002
+ return M(
4003
+ `令牌来源:本机 git 凭据(仅内存使用,不落盘、绝不推送进同步仓库);仓库记在 ${st.ghFile || 'config-sync-gh.json'}`,
4004
+ `Token source: local git credential (memory only, never saved or pushed); repo lives in ${st.ghFile || 'config-sync-gh.json'}`,
4005
+ )
4006
+ }
4007
+ if (st.tokenSource === 'gh-cli') {
4008
+ return M(
4009
+ `令牌来源:本机 GitHub CLI(gh auth token,仅内存使用,不落盘、绝不推送进同步仓库);仓库记在 ${st.ghFile || 'config-sync-gh.json'}`,
4010
+ `Token source: local GitHub CLI (gh auth token, memory only, never saved or pushed); repo lives in ${st.ghFile || 'config-sync-gh.json'}`,
4011
+ )
4012
+ }
4013
+ if (st.tokenSaved) {
4014
+ return M(
4015
+ `令牌/仓库记在 ${st.ghFile || 'config-sync-gh.json'}(本机私有,绝不推送进同步仓库;也可改用 $GITHUB_TOKEN)`,
4016
+ `Token and repo live in ${st.ghFile || 'config-sync-gh.json'} (local only, never pushed; or switch to $GITHUB_TOKEN)`,
4017
+ )
4018
+ }
4019
+ return M(
4020
+ `支持读取本机环境变量(DSH_CONFIG_SYNC_GH_TOKEN / GITHUB_TOKEN / GH_TOKEN);只存仓库与变量名于 ${st.ghFile || 'config-sync-gh.json'}(绝不推送令牌)`,
4021
+ `Supports local env vars (DSH_CONFIG_SYNC_GH_TOKEN / GITHUB_TOKEN / GH_TOKEN); only repo/var name live in ${st.ghFile || 'config-sync-gh.json'} (tokens never pushed)`,
4022
+ )
4023
+ }
4024
+
3747
4025
  return h('div', { style: S.card },
3748
4026
  h('div', { style: S.cardHead },
3749
4027
  h('div', { style: S.cardTitle }, M('问题反馈', 'Feedback')),
3750
4028
  h('div', { style: { flex: 1 } }, null),
3751
4029
  h('span', { style: S.chip }, M(`${open} 待处理 / 共 ${total}`, `${open} open / ${total} total`)),
3752
- h('button', { type: 'button', style: S.btn, disabled: busy, onClick: load }, busy ? M('刷新中…', 'Refreshing…') : M('刷新', 'Refresh')),
4030
+ h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => load(true) }, busy ? M('刷新中…', 'Refreshing…') : M('刷新', 'Refresh')),
3753
4031
  ),
3754
4032
  h('div', { style: S.kvRow },
3755
4033
  h('div', { style: S.kvKey }, M('连接', 'Connect')),
3756
4034
  h('div', { style: S.kvVal },
3757
4035
  h('div', null,
3758
- dot(st.canClose ? 'var(--dsw-alias-state-success-primary, #35a854)' : (st.items.length ? 'var(--dsw-alias-state-warning-primary, #d97706)' : 'var(--dsw-alias-state-error-primary)')),
3759
- st.canClose
4036
+ dot(st.canClose && st.connected ? 'var(--dsw-alias-state-success-primary, #35a854)' : ((st.items.length || st.tokenPresent) ? 'var(--dsw-alias-state-warn-primary, #d97706)' : 'var(--dsw-alias-state-error-primary)')),
4037
+ st.canClose && st.connected
3760
4038
  ? M(`GitHub ${st.repo} · 已用 ${st.login} 登录(可提交、可关单)`, `GitHub ${st.repo} · signed in as ${st.login} (can submit and close)`)
3761
4039
  : st.connected
3762
4040
  ? M(`GitHub ${st.repo} · 令牌属于 ${st.login || '?'},不是仓库所有者,只能读和提交`, `GitHub ${st.repo} · token belongs to ${st.login || '?'}, not the repo owner: read and submit only`)
3763
4041
  : st.readAnon
3764
4042
  ? M(`GitHub ${st.repo} · 匿名读取(公开仓库,不需要令牌;提交走浏览器)`, `GitHub ${st.repo} · anonymous read (public repo, no token; submit via browser)`)
3765
- : M('还没连上 GitHub(令牌没取到或网络不通)', 'Not connected to GitHub (no token or no network)'),
4043
+ : st.tokenPresent
4044
+ ? M(`GitHub ${st.repo || st.defaultRepo || 'huanyu-a/dsh-profile-config-sync'} · 已读取本机令牌${st.login ? `(${st.login})` : ''},但连不上 GitHub API(请检查网络/代理)`, `GitHub ${st.repo || st.defaultRepo || 'huanyu-a/dsh-profile-config-sync'} · local token loaded${st.login ? ` (${st.login})` : ''}, but cannot reach GitHub API (check network/proxy)`)
4045
+ : M('还没连上 GitHub(令牌没取到或网络不通)', 'Not connected to GitHub (no token or no network)'),
3766
4046
  ),
3767
- h('div', { style: S.footnote },
3768
- st.note || (st.ghFile ? M(`令牌/仓库记在 ${st.ghFile}(本机私有,不进仓库)`, `Token and repo live in ${st.ghFile} (local only, never committed)`) : null)),
4047
+ h('div', { style: S.footnote }, tokenSourceHint()),
3769
4048
  ),
3770
4049
  ),
3771
- (askToken || !st.connected)
3772
- ? h('div', { style: S.kvRow },
3773
- h('div', { style: S.kvKey }, M('令牌', 'Token')),
3774
- h('div', { style: { ...S.kvVal, display: 'flex', gap: '8px' } },
3775
- h('input', {
3776
- type: 'password', style: S.input, value: token, spellCheck: false, autoComplete: 'off',
3777
- placeholder: M('粘贴 GitHub 令牌(一次即可;留空则读本机 git 凭据)', 'Paste a GitHub token (once); leave empty to reuse the local git credential'),
3778
- onChange: (e) => setToken(e.target.value),
3779
- }),
3780
- h('button', { type: 'button', style: S.btnPrimary, disabled: busy || !token.trim(), onClick: saveToken }, M('保存', 'Save')),
4050
+ (askToken || (!st.connected && !st.tokenPresent))
4051
+ ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
4052
+ h('div', { style: S.kvRow },
4053
+ h('div', { style: S.kvKey }, M('仓库', 'Repo')),
4054
+ h('div', { style: { ...S.kvVal, display: 'flex', gap: '8px', alignItems: 'center' } },
4055
+ h('input', {
4056
+ type: 'text', style: S.input, value: repoInput, spellCheck: false,
4057
+ placeholder: st.defaultRepo || 'huanyu-a/dsh-profile-config-sync',
4058
+ onChange: (e) => setRepoInput(e.target.value),
4059
+ }),
4060
+ st.defaultRepo && repoInput.trim() !== st.defaultRepo
4061
+ ? h('button', {
4062
+ type: 'button', style: S.btn, disabled: busy,
4063
+ onClick: () => { setRepoInput(st.defaultRepo); saveToken({ repo: st.defaultRepo }) },
4064
+ }, M(`改用 ${st.defaultRepo}`, `Use ${st.defaultRepo}`))
4065
+ : null,
4066
+ ),
4067
+ ),
4068
+ h('div', { style: S.kvRow },
4069
+ h('div', { style: S.kvKey }, M('令牌', 'Token')),
4070
+ h('div', { style: { ...S.kvVal, display: 'flex', flexDirection: 'column', gap: '6px' } },
4071
+ h('div', { style: { display: 'flex', gap: '8px' } },
4072
+ h('input', {
4073
+ type: 'password', style: S.input, value: token, spellCheck: false, autoComplete: 'off',
4074
+ placeholder: M('填 $GITHUB_TOKEN / env:GH_TOKEN 读环境变量,或粘贴令牌(留空也可只改仓库)', 'Enter $GITHUB_TOKEN / env:GH_TOKEN for env var, or paste a token'),
4075
+ onChange: (e) => setToken(e.target.value),
4076
+ }),
4077
+ h('button', {
4078
+ type: 'button', style: S.btnPrimary,
4079
+ disabled: busy || (!token.trim() && repoInput.trim() === String(st.repo || '')),
4080
+ onClick: () => saveToken(),
4081
+ }, M('保存', 'Save')),
4082
+ ),
4083
+ h('div', { style: { display: 'flex', gap: '6px', flexWrap: 'wrap', alignItems: 'center' } },
4084
+ ...(Array.isArray(st.envCandidates) ? st.envCandidates : []).map((envName) => h('button', {
4085
+ key: envName, type: 'button', style: S.btn, disabled: busy,
4086
+ onClick: () => saveToken({ tokenEnv: envName }),
4087
+ }, M(`使用环境变量 ${envName}`, `Use env ${envName}`))),
4088
+ st.tokenSaved
4089
+ ? h('button', {
4090
+ type: 'button', style: S.btn, disabled: busy,
4091
+ onClick: () => saveToken({ clearToken: true }),
4092
+ }, M('清除已存令牌(改用环境变量)', 'Clear saved token (use env)'))
4093
+ : null,
4094
+ ),
4095
+ ),
3781
4096
  ),
3782
4097
  )
3783
4098
  : null,
@@ -3914,7 +4229,7 @@ window.__ModuleLoader__.load({
3914
4229
 
3915
4230
  const head = h('div', { style: S.head },
3916
4231
  h('div', { style: S.headText },
3917
- h('div', { style: S.title }, M('配置同步', 'Config Sync')),
4232
+ h('div', { style: S.title }, M('配置备份与同步', 'Config Backup & Sync')),
3918
4233
  h('div', { style: S.sub }, busy ? M('检测中…', 'Checking…') : summary.text),
3919
4234
  data ? h('div', { style: S.sub }, `app ${data.version.local || '?'} / ${M('契约', 'contract')} ${data.version.contract || '?'}`) : null,
3920
4235
  ),
@@ -3937,7 +4252,9 @@ window.__ModuleLoader__.load({
3937
4252
  data ? h(Kv, {
3938
4253
  k: M('仓库', 'Repo'),
3939
4254
  v: data.repo.exists
3940
- ? `${data.repo.path} (${data.repo.branch || '?'} @ ${data.repo.head || '?'})`
4255
+ ? (data.repo.branch || data.repo.head
4256
+ ? `${data.repo.path} (${data.repo.branch || '?'} @ ${data.repo.head || '?'})`
4257
+ : `${data.repo.path}${data.webdav && data.webdav.active ? M('(WebDAV 模式,无 git 分支)', ' (WebDAV mode, no git branch)') : ''}`)
3941
4258
  : M('还没配置(请到面板里设置)', 'Not configured (set it in the panel)'),
3942
4259
  }) : null,
3943
4260
  data ? h(Kv, {
@@ -4057,7 +4374,7 @@ window.__ModuleLoader__.load({
4057
4374
  method: 'POST',
4058
4375
  cache: 'no-store',
4059
4376
  credentials: 'same-origin',
4060
- headers: jsonHeaders,
4377
+ headers: jsonHeaders(),
4061
4378
  body: JSON.stringify({ action: 'busy', sessionId: sessionId || '' }),
4062
4379
  })
4063
4380
  if (!res.ok) return false
@@ -4108,7 +4425,7 @@ window.__ModuleLoader__.load({
4108
4425
  name: 'sidebar.panellist',
4109
4426
  id: PANEL_ID,
4110
4427
  order: 35,
4111
- label: () => M('配置同步', 'Config Sync'),
4428
+ label: () => M('配置备份与同步', 'Config Backup & Sync'),
4112
4429
  locale: 'config-sync',
4113
4430
  }, SidebarIcon)
4114
4431
  return () => {