dsh-config-sync-plugin 0.3.91 → 0.3.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +19 -2
- package/README.md +19 -2
- package/client.js +15 -16
- package/index.js +94 -3
- package/package.json +1 -1
- package/tools/clientcheck.mjs +7 -2
- package/tools/selftest.mjs +30 -0
package/README.en.md
CHANGED
|
@@ -257,6 +257,21 @@ Two display fixes on top of 0.3.77:
|
|
|
257
257
|
|
|
258
258
|
The "Plugin update" card now shows an **npm download URL** line with the actual fallback addresses (domestic mirror `registry.npmmirror.com` + official `registry.npmjs.org`). When the GitHub release download is unreachable (common in mainland China), the update package automatically falls back to npm. It is still verified against the authoritative sha256 in `version.json` — switching source never relaxes verification. The two sources back each other up: the mirror can briefly 404 during its first-sync window, and the official source takes over. The npm tarball is byte-identical to the GitHub release tgz (same sha256).
|
|
259
259
|
|
|
260
|
+
### Clicking × to close DSH now checks once for auto pull/push immediately (0.3.93)
|
|
261
|
+
|
|
262
|
+
With "Pull on startup" or "Push on exit" enabled, the only queues used to be the 8-second startup check and the 2-minute re-check. If you made changes between two re-checks and then clicked the top-right × to close DSH, no watcher was waiting for the exit at that moment, so nothing ran after closing. A quit hook now covers it: when the last visible window closes (the × click), the plugin checks once and queues the watcher **before** the client exits; once the DSH processes are gone the watcher runs the pull/push immediately.
|
|
263
|
+
|
|
264
|
+
1. **Check once on exit**: when no visible windows remain, call `triggerAutoSyncOnClose(config)`, which reads the `autoPull`/`autoPush` switches; an in-flight watcher is reused rather than relaunched; with an empty local repo only autoPull can queue (first clone).
|
|
265
|
+
2. **Same criteria as the re-check**: pull takes priority (behind > 0 → queue pull, no confirmation dialog on the close path); push queues when any of "commits ahead / uncommitted changes / local data newer than last sync" hits; `autoRestart` semantics unified to `!== false` (relaunch by default).
|
|
266
|
+
3. **Queue before quit**: the queue must be awaited **before** `app.quit()` — the plugin dies with the main process, so checking after quit is too late. With both switches off / nothing to sync the function returns quickly and does not slow down closing; a successful queue logs "queued pull/push before exit …: runs right after DSH exits".
|
|
267
|
+
|
|
268
|
+
### Remote "uncommitted" now includes local pending changes + Refresh really fetches (0.3.92)
|
|
269
|
+
|
|
270
|
+
Root cause found by measurement for "remote info still not updating": the git-level behind/ahead really is 0 (local HEAD matches the gitee cloud), while what the user means by "not updated" is the runtime-generated changes on this machine not yet captured into the repo. Two substantive fixes:
|
|
271
|
+
|
|
272
|
+
1. **"Uncommitted" = git work-tree changes + local pending**: the status `repo` object gains `pending` (local session/config changes not yet synced) and `uncommitted` (`dirty + pending`). Both "Remote" Kv rows in the panel use `uncommitted` for the uncommitted figure and append "(N pending on this machine)" when there are pending items. New local sessions/config changes show up immediately without waiting for DSH exit + capture.
|
|
273
|
+
2. **"Refresh" button actually fetches**: the summary-row "Refresh" button previously only re-read status (no git fetch, so behind/ahead stayed the same). It now runs `refreshRemoteNow`: first `/config-sync/auto {action:'check'}` to trigger `git fetch` and refresh remote refs, then refresh the snapshot. The 30-second auto-refresh while expanded shares the same chain.
|
|
274
|
+
|
|
260
275
|
### Settings → General → Config Sync: live remote info + Pull/Push now buttons (0.3.91)
|
|
261
276
|
|
|
262
277
|
Two adjustments to the "Settings → General → Config Sync" summary row:
|
|
@@ -577,8 +592,8 @@ Default exclusions (50 entries, edit freely): `*.db` / `*.db-*` / `*.sqlite*` /
|
|
|
577
592
|
|
|
578
593
|
| Switch | Behaviour |
|
|
579
594
|
|---|---|
|
|
580
|
-
| Pull on startup | 8 s after start, a read-only `git fetch` comparison; behind > 0 → system confirmation dialog (Yes/No) → "Yes" **exits the whole client family right away** (measured: processes gone within 5 s) → a visible window runs the pull → relaunches automatically |
|
|
581
|
-
| Push on exit | **queued when any of three sources hit**: local commits ahead, uncommitted changes, local data newer than the last sync (new sessions etc). Re-checked every 2 minutes after start, no duplicate watcher while queued; pushes only after DSH fully exits, then relaunches |
|
|
595
|
+
| Pull on startup | 8 s after start, a read-only `git fetch` comparison; behind > 0 → system confirmation dialog (Yes/No) → "Yes" **exits the whole client family right away** (measured: processes gone within 5 s) → a visible window runs the pull → relaunches automatically. Clicking × to close also checks once and queues (0.3.93; no confirmation dialog on the close path — behind > 0 queues the pull) |
|
|
596
|
+
| Push on exit | **queued when any of three sources hit**: local commits ahead, uncommitted changes, local data newer than the last sync (new sessions etc). Re-checked every 2 minutes after start, and checked once more when × closes the window (0.3.93), no duplicate watcher while queued; pushes only after DSH fully exits, then relaunches |
|
|
582
597
|
|
|
583
598
|
- The work is done by `runtime\post-exit.ps1 -Phase wait`, which the plugin launches as a **hidden** process to watch for the client exiting; only after it really exits does it start a **visible** `-Phase run` window titled "DSH 配置同步 · 拉取/推送". **No window while queued** — otherwise an empty window would sit in the way from boot to shutdown.
|
|
584
599
|
- When the repo is not in place yet (empty folder included) the startup check simply skips and does **not** record a failure — an empty folder is only waiting for the first pull.
|
|
@@ -697,6 +712,8 @@ The log shows which path ran: `文件比较(快筛):比对 N 个,深哈
|
|
|
697
712
|
|
|
698
713
|
| Date | Version | Summary |
|
|
699
714
|
|---|---|---|
|
|
715
|
+
| 2026-11-24 | 0.3.93 | Clicking × to close DSH now checks once for auto pull/push and queues the watcher immediately (no more waiting for the 2-minute window); autoRestart semantics unified to !== false |
|
|
716
|
+
| 2026-11-24 | 0.3.92 | Remote "uncommitted" now includes local pending data (pending); Refresh button really triggers git fetch; fixes "remote figures always 0" |
|
|
700
717
|
| 2026-11-24 | 0.3.91 | Settings summary row fetches before refreshing remote info (no longer stale, auto-refresh every 30s); four generate-script buttons replaced with Pull/Push now (closes DSH) sharing the automation queue |
|
|
701
718
|
| 2026-11-24 | 0.3.90 | Jump tabs highlight the current section; "Local data" label removed from To-do; To-do expands to concrete session names and local profile files |
|
|
702
719
|
| 2026-11-24 | 0.3.89 | Plugin update card shows an "npm download URL"; falls back to two npm sources (mirror + official) when GitHub release is unreachable, still verified against the authoritative sha256 |
|
package/README.md
CHANGED
|
@@ -277,6 +277,21 @@ pwsh -File runtime\sync.ps1 pull `
|
|
|
277
277
|
|
|
278
278
|
「插件更新」卡新增一行 **npm 下载路径**,直接显示实际兜底地址(国内镜像 `registry.npmmirror.com` + 官方 `registry.npmjs.org` 两个源)。GitHub release 整段不通时(国内常见),更新包会自动兜底从 npm 下载;仍按 `version.json` 里的权威 sha256 校验,换源不放宽校验。两个源互为备份:镜像首发同步窗口期会短暂 404,官方源随即兜上。实测 npm tarball 与 GitHub release tgz 是同一份产物、sha256 完全一致。
|
|
279
279
|
|
|
280
|
+
### 点 × 关闭 DSH 时立即判一次自动拉取/推送(0.3.93)
|
|
281
|
+
|
|
282
|
+
勾了「启动时自动拉取」或「退出时自动推送」后,原来只有启动后的 8 秒首检 + 每 2 分钟复查会排队。如果你在两次复查之间做了改动就点右上角 × 关闭,那一刻没有 watcher 在等退出,关闭后什么都不会执行。现在补上退出钩子:点 ×(最后一个可见窗口关闭)时插件先判一次并排好 watcher,再退出客户端;DSH 进程归零后 watcher 立刻执行拉取/推送。
|
|
283
|
+
|
|
284
|
+
1. **退出前判一次**:无可见窗口时调用 `triggerAutoSyncOnClose(config)`,读 `autoPull`/`autoPush` 开关;已有在途 watcher 就复用、不重复拉起;本机仓库为空时只有 autoPull 能排队(首次 clone)。
|
|
285
|
+
2. **判据与复查完全一致**:拉取优先(云端领先 > 0 就排 pull,关闭时不弹确认框);推送按「领先提交 / 未提交改动 / 本机资料比上次同步新」三来源任一命中就排 push;`autoRestart` 语义统一为 `!== false`(默认重启)。
|
|
286
|
+
3. **排队先于 quit**:必须在 `app.quit()` 之前 `await` 排队——插件随主进程退出而消失,quit 后再判就来不及。开关都关 / 无待同步内容时该函数很快返回,不影响关闭速度;排队成功写日志「退出前已排队 …:DSH 退出后立即执行」。
|
|
287
|
+
|
|
288
|
+
### 远端「未提交」纳入本机待同步 + 刷新按钮真正 fetch(0.3.92)
|
|
289
|
+
|
|
290
|
+
针对「远端信息还是没更新」的实测根因:git 层的「落后/领先」确实是 0(本机 HEAD 与云端 gitee 一致),用户说的「没更新」其实是本机运行期新产生、还没 capture 进仓库的待同步数据。这次做两处实质性改动:
|
|
291
|
+
|
|
292
|
+
1. **「未提交」= git 工作树改动 + 本机待同步**:后端 status 的 `repo` 对象新增 `pending`(本机还没同步的会话/配置改动数)与 `uncommitted`(`dirty + pending`)两个字段。面板两处「远端」Kv 的「未提交」改用 `uncommitted`,并在有待同步项时追加「(本机待同步 N)」。这样本机有新会话/配置改动时数字立刻可见,不用等退出 DSH capture。
|
|
293
|
+
2. **「刷新」按钮真正 fetch**:原来摘要行的「刷新」只重读 status(不触发 git fetch,落后/领先数照旧)。现在刷新按钮走 `refreshRemoteNow`:先 `/config-sync/auto {action:'check'}` 触发 `git fetch` 更新远端引用,再刷新快照;展开时的 30 秒自动刷新统一复用这条链。
|
|
294
|
+
|
|
280
295
|
### 设置-通用-配置同步:远端信息自动刷新 + 立即拉取/推送按钮(0.3.91)
|
|
281
296
|
|
|
282
297
|
「设置 → 通用设置 → 配置同步」摘要行两处调整:
|
|
@@ -555,8 +570,8 @@ DSH 的会话标题会演进:先产生 fallback 临时标题(首条消息截
|
|
|
555
570
|
|
|
556
571
|
| 开关 | 行为 |
|
|
557
572
|
|---|---|
|
|
558
|
-
| 启动时自动拉取 | 启动 8 秒后只读 `git fetch` 比对;落后 > 0 → 系统确认框 → 选"是"**当场把客户端整族退出**(实测 5 秒内进程归零)→ 可见窗口跑拉取 →
|
|
559
|
-
| 退出时自动推送 | **三个来源任意命中就排队**:本地领先提交、未提交改动、本机资料比上次同步新(新会话等)。启动后每 2
|
|
573
|
+
| 启动时自动拉取 | 启动 8 秒后只读 `git fetch` 比对;落后 > 0 → 系统确认框 → 选"是"**当场把客户端整族退出**(实测 5 秒内进程归零)→ 可见窗口跑拉取 → 拉完自动重启。手动点 × 关闭时也会判一次并排队(0.3.93,关闭场景不弹确认框,云端领先就排) |
|
|
574
|
+
| 退出时自动推送 | **三个来源任意命中就排队**:本地领先提交、未提交改动、本机资料比上次同步新(新会话等)。启动后每 2 分钟复查,点 × 关闭时也会立即判一次(0.3.93),已排队不重复拉起;等 DSH 完全退出后才 push,推完自动重启 |
|
|
560
575
|
|
|
561
576
|
- 动手由插件拉起 `runtime\post-exit.ps1 -Phase wait`(**隐藏**)盯退出;真退了才用 `-WindowStyle Normal` 起 `-Phase run` 的**可见**窗口,标题「DSH 配置同步 · 拉取/推送」。**排队期间不弹窗**。
|
|
562
577
|
- 仓库还没就位(含空目录)时首检直接跳过,且不记成"检查失败"。
|
|
@@ -679,6 +694,8 @@ pwsh -File sync.ps1 push -ScanHistory
|
|
|
679
694
|
|
|
680
695
|
| 日期 | 版本 | 要点 |
|
|
681
696
|
|---|---|---|
|
|
697
|
+
| 2026-11-24 | 0.3.93 | 点 × 关闭 DSH 时立即判一次自动拉取/推送并排队 watcher,不再等 2 分钟复查窗口;autoRestart 语义统一为 !== false |
|
|
698
|
+
| 2026-11-24 | 0.3.92 | 远端「未提交」纳入本机待同步数据(pending),刷新按钮真正触发 git fetch;解决「远端数字一直是 0」 |
|
|
682
699
|
| 2026-11-24 | 0.3.91 | 设置-通用-配置同步摘要行展开时先 fetch 再刷新远端信息(不再陈旧、每 30 秒自动刷新);四个生成脚本按钮换成「立即拉取/推送(会关闭 DSH)」两个,走自动同步同一队列 |
|
|
683
700
|
| 2026-11-24 | 0.3.90 | 顶部跳转按钮跟随当前位置高亮;待办去掉「本机数据」字眼、可展开看具体会话记录名与本机 profile |
|
|
684
701
|
| 2026-11-24 | 0.3.89 | 插件更新卡新增「npm 下载路径」;npm 双源(镜像+官方)兜底下载,仍按权威 sha256 校验 |
|
package/client.js
CHANGED
|
@@ -696,8 +696,8 @@ window.__ModuleLoader__.load({
|
|
|
696
696
|
k: M('远端', 'Remote'),
|
|
697
697
|
v: repo.exists
|
|
698
698
|
? M(
|
|
699
|
-
`落后 ${repo.behind ?? '?'} · 领先 ${repo.ahead ?? '?'} · 未提交 ${repo.dirty ?? '?'}
|
|
700
|
-
`behind ${repo.behind ?? '?'} · ahead ${repo.ahead ?? '?'} ·
|
|
699
|
+
`落后 ${repo.behind ?? '?'} · 领先 ${repo.ahead ?? '?'} · 未提交 ${repo.uncommitted ?? repo.dirty ?? '?'}` + (repo.pending ? `(本机待同步 ${repo.pending})` : ''),
|
|
700
|
+
`behind ${repo.behind ?? '?'} · ahead ${repo.ahead ?? '?'} · uncommitted ${repo.uncommitted ?? repo.dirty ?? '?'}` + (repo.pending ? ` (${repo.pending} pending on this machine)` : ''),
|
|
701
701
|
)
|
|
702
702
|
: (repo.empty ? M('(拉取之后才有得比)', '(available after the first pull)') : M('(不可用)', '(unavailable)')),
|
|
703
703
|
}),
|
|
@@ -3466,21 +3466,20 @@ window.__ModuleLoader__.load({
|
|
|
3466
3466
|
const canPull = repo.pullAllowed === true
|
|
3467
3467
|
const canPush = repo.pushAllowed === true
|
|
3468
3468
|
|
|
3469
|
-
//
|
|
3470
|
-
//
|
|
3471
|
-
//
|
|
3472
|
-
//
|
|
3469
|
+
// 远端数字不刷新的根因有两层:
|
|
3470
|
+
// 1) 落后/领先来自 git tracking ref,必须 fetch 才更新 —— check 动作会 fetch;
|
|
3471
|
+
// 2) 用户说的「没更新」还包括本机还没 capture 进仓库的待同步数据 —— 后端已并进 repo.uncommitted/pending。
|
|
3472
|
+
// 「刷新」按钮与展开时的自动刷新都走这条链:先 check(fetch),再 refresh 拉新快照。
|
|
3473
|
+
const refreshRemoteNow = react.useCallback(async () => {
|
|
3474
|
+
try { await callAuto({ action: 'check' }) } catch { /* 离线就按本机缓存显示,不打扰 */ }
|
|
3475
|
+
refresh()
|
|
3476
|
+
}, [refresh])
|
|
3473
3477
|
react.useEffect(() => {
|
|
3474
3478
|
if (!open) return
|
|
3475
|
-
let alive = true
|
|
3476
|
-
const refreshRemoteNow = async () => {
|
|
3477
|
-
try { await callAuto({ action: 'check' }) } catch { /* 离线就按本机缓存显示,不打扰 */ }
|
|
3478
|
-
if (alive) refresh()
|
|
3479
|
-
}
|
|
3480
3479
|
refreshRemoteNow()
|
|
3481
3480
|
const timer = setInterval(refreshRemoteNow, 30000)
|
|
3482
|
-
return () => {
|
|
3483
|
-
}, [open,
|
|
3481
|
+
return () => { clearInterval(timer) }
|
|
3482
|
+
}, [open, refreshRemoteNow])
|
|
3484
3483
|
|
|
3485
3484
|
// 立即拉取 / 立即推送:和大面板「自动同步」卡同一条 /config-sync/auto 队列,
|
|
3486
3485
|
// 点完排队、关掉 DSH 后由 post-exit.ps1 真正执行(本进程不自己动手)。
|
|
@@ -3504,7 +3503,7 @@ window.__ModuleLoader__.load({
|
|
|
3504
3503
|
h('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', flexShrink: 0 } },
|
|
3505
3504
|
h('span', { style: chipStyle(summary.kind) }, chipLabel(summary.kind)),
|
|
3506
3505
|
h('button', { type: 'button', style: S.btn, onClick: () => setOpen((v) => !v) }, open ? M('收起', 'Collapse') : M('查看', 'View')),
|
|
3507
|
-
h('button', { type: 'button', style: S.btn, disabled: busy, onClick:
|
|
3506
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: refreshRemoteNow }, busy ? M('刷新中…', 'Refreshing…') : M('刷新', 'Refresh')),
|
|
3508
3507
|
),
|
|
3509
3508
|
)
|
|
3510
3509
|
|
|
@@ -3528,8 +3527,8 @@ window.__ModuleLoader__.load({
|
|
|
3528
3527
|
v: data.repo.behind === null
|
|
3529
3528
|
? M('读不到', 'Unavailable')
|
|
3530
3529
|
: M(
|
|
3531
|
-
`落后 ${data.repo.behind} · 领先 ${data.repo.ahead} · 未提交 ${data.repo.dirty}
|
|
3532
|
-
`behind ${data.repo.behind} · ahead ${data.repo.ahead} ·
|
|
3530
|
+
`落后 ${data.repo.behind} · 领先 ${data.repo.ahead} · 未提交 ${data.repo.uncommitted ?? data.repo.dirty}` + (data.repo.pending ? `(本机待同步 ${data.repo.pending})` : ''),
|
|
3531
|
+
`behind ${data.repo.behind} · ahead ${data.repo.ahead} · uncommitted ${data.repo.uncommitted ?? data.repo.dirty}` + (data.repo.pending ? ` (${data.repo.pending} pending on this machine)` : ''),
|
|
3533
3532
|
),
|
|
3534
3533
|
}) : null,
|
|
3535
3534
|
data ? h(Kv, {
|
package/index.js
CHANGED
|
@@ -1119,6 +1119,10 @@ async function inspect(config) {
|
|
|
1119
1119
|
dirty,
|
|
1120
1120
|
ahead,
|
|
1121
1121
|
behind,
|
|
1122
|
+
// 本机待同步(还没 capture 进仓库的会话/配置改动),与 git 工作树 dirty 是两件事。
|
|
1123
|
+
pending: (local && local.pending) || 0,
|
|
1124
|
+
// 面板上用户理解的「未提交」= git 工作树改动 + 本机还没同步的改动,反映「还没进云端的本机改动总数」。
|
|
1125
|
+
uncommitted: (dirty || 0) + ((local && local.pending) || 0),
|
|
1122
1126
|
},
|
|
1123
1127
|
version: { local: localVersion, contract: contractVersion, electron: electronVersion, match: versionMatch },
|
|
1124
1128
|
// 本机数据侧:上次同步时间 + 「之后又写过多少文件」,与 repo.dirty 是两件事
|
|
@@ -3521,6 +3525,84 @@ function scheduleAutoStart(config) {
|
|
|
3521
3525
|
} catch { }
|
|
3522
3526
|
}
|
|
3523
3527
|
|
|
3528
|
+
/**
|
|
3529
|
+
* 用户点右上角 × 关闭 DSH 时,立即判一次自动拉取/推送并排好 watcher(0.3.93)。
|
|
3530
|
+
*
|
|
3531
|
+
* 为什么要单独做:原来开关只在 scheduleAutoStart 的 8 秒首检 + 每 2 分钟复查里判,
|
|
3532
|
+
* 用户勾了开关、做了改动,没等到下一次复查就点 × 关掉 —— 那一刻没有任何 watcher 在排队,
|
|
3533
|
+
* 退出后自然什么都不执行,看着就像"勾了没用"。现在把「判一次并排队」接到关闭钩子上:
|
|
3534
|
+
* 点 × → 这里同步判一次 → 拉起独立 watcher → app.quit(),watcher 在 DSH 退出后照常执行,
|
|
3535
|
+
* 语义和手动「立即拉取/推送」完全一致。
|
|
3536
|
+
*
|
|
3537
|
+
* 关闭场景窗口都在关了,不弹确认框;autoPull 仍只在云端确实领先(或本机仓库还没内容)时才排队,
|
|
3538
|
+
* 免得没更新也白拉一次还把客户端重启回来。和 scheduleAutoStart 一样「拉取优先,二者只排一个」。
|
|
3539
|
+
*/
|
|
3540
|
+
async function triggerAutoSyncOnClose(config) {
|
|
3541
|
+
const dshHome = config?.dshHome || process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
3542
|
+
try {
|
|
3543
|
+
const settings = readSettings(dshHome)
|
|
3544
|
+
if (!settings.autoPull && !settings.autoPush) return { queued: false }
|
|
3545
|
+
// 已经排过队(2 分钟复查 / 手动按钮)就别重复拉起 watcher:spawnWatcher 的锁也会挡,这里先省一次开销
|
|
3546
|
+
if (autoState.pending && isProcessAlive(autoState.pending.watcherPid)) {
|
|
3547
|
+
return { queued: false, reused: true, mode: autoState.pending.mode }
|
|
3548
|
+
}
|
|
3549
|
+
const repo = resolveRepo(config?.repoPath, dshHome).repo || ''
|
|
3550
|
+
if (!repo) return { queued: false }
|
|
3551
|
+
const appRoot = resolveAppRoot(config?.appRoot) || ''
|
|
3552
|
+
const phase = repoPhase(repo)
|
|
3553
|
+
|
|
3554
|
+
// 本机仓库还没内容:autoPull 可以直接排队(sync.ps1 首次 clone),autoPush 不行(要先确认云端为空)
|
|
3555
|
+
if (phase !== 'ok') {
|
|
3556
|
+
if (settings.autoPull && phase === 'empty') {
|
|
3557
|
+
const restart = settings.autoRestart !== false
|
|
3558
|
+
const started = await spawnWatcher({ mode: 'pull', repo, appRoot, dshHome, restart })
|
|
3559
|
+
if (!started.ok) return { queued: false, error: started.error }
|
|
3560
|
+
autoState.pending = { mode: 'pull', at: Date.now(), reasonZh: '本机仓库为空,拉取初始化', reasonEn: 'Empty local repo — pull to initialize', restart, watcherPid: started.pid }
|
|
3561
|
+
return { queued: true, mode: 'pull' }
|
|
3562
|
+
}
|
|
3563
|
+
return { queued: false }
|
|
3564
|
+
}
|
|
3565
|
+
|
|
3566
|
+
const drift = await checkDrift(repo)
|
|
3567
|
+
if (!drift) return { queued: false }
|
|
3568
|
+
|
|
3569
|
+
// 拉取优先,和 scheduleAutoStart 一致;关闭时不再弹确认框,云端领先就排
|
|
3570
|
+
if (settings.autoPull && drift.behind > 0) {
|
|
3571
|
+
const restart = settings.autoRestart !== false
|
|
3572
|
+
const started = await spawnWatcher({ mode: 'pull', repo, appRoot, dshHome, restart })
|
|
3573
|
+
if (!started.ok) return { queued: false, error: started.error }
|
|
3574
|
+
autoState.pending = {
|
|
3575
|
+
mode: 'pull', at: Date.now(), restart, watcherPid: started.pid,
|
|
3576
|
+
reasonZh: `退出前检查:云端领先 ${drift.behind} 个提交`, reasonEn: `Checked on exit: ${drift.behind} commit(s) behind`,
|
|
3577
|
+
}
|
|
3578
|
+
return { queued: true, mode: 'pull' }
|
|
3579
|
+
}
|
|
3580
|
+
|
|
3581
|
+
if (settings.autoPush) {
|
|
3582
|
+
// 判据和 scheduleAutoStart 完全相同:领先提交 / 未提交改动 / 本机资料比上次同步新
|
|
3583
|
+
let dirty = 0
|
|
3584
|
+
const raw = await git(repo, ['status', '--porcelain'])
|
|
3585
|
+
if (raw) dirty = raw.split('\n').filter((l) => l.trim()).length
|
|
3586
|
+
const syncState = readSyncState(dshHome)
|
|
3587
|
+
const lp = localPending(dshHome, syncState.lastSyncAt, config?.profileName, { repo, appRoot })
|
|
3588
|
+
const shouldPush = drift.ahead > 0 || dirty > 0 || (lp.known && lp.pending > 0)
|
|
3589
|
+
if (shouldPush) {
|
|
3590
|
+
const restart = settings.autoRestart !== false
|
|
3591
|
+
const reasonZh = drift.ahead > 0 ? `领先 ${drift.ahead} 个提交` : dirty > 0 ? `未提交 ${dirty} 项` : `本机 ${lp.pending} 个文件比上次同步新`
|
|
3592
|
+
const reasonEn = drift.ahead > 0 ? `${drift.ahead} commit(s) ahead` : dirty > 0 ? `${dirty} uncommitted change(s)` : `${lp.pending} file(s) newer than the last sync`
|
|
3593
|
+
const started = await spawnWatcher({ mode: 'push', repo, appRoot, dshHome, restart })
|
|
3594
|
+
if (!started.ok) return { queued: false, error: started.error }
|
|
3595
|
+
autoState.pending = { mode: 'push', at: Date.now(), reason: reasonZh, reasonZh, reasonEn, restart, watcherPid: started.pid }
|
|
3596
|
+
return { queued: true, mode: 'push' }
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
return { queued: false }
|
|
3600
|
+
} catch (error) {
|
|
3601
|
+
logLaunch(dshHome, `退出前自动同步排队失败:${(error && error.message) || error}`)
|
|
3602
|
+
return { queued: false }
|
|
3603
|
+
}
|
|
3604
|
+
}
|
|
3605
|
+
|
|
3524
3606
|
async function handlePrepare(req, res, config) {
|
|
3525
3607
|
if (req.method !== 'POST') { sendJson(res, 405, { ok: false, error: 'POST only' }); return }
|
|
3526
3608
|
if (!originAllowed(req)) { sendJson(res, 403, { ok: false, error: 'cross-origin request rejected' }); return }
|
|
@@ -4620,7 +4702,7 @@ export function apply(ctx, config) {
|
|
|
4620
4702
|
// 云端探测预热:插件一装上就去探一次(不阻塞、不 await)。这样面板打开时缓存多半已经热了,
|
|
4621
4703
|
// status 不用再为首屏那 2.5 秒的 ls-remote 埋单。
|
|
4622
4704
|
typeof setTimeout === 'function' ? setTimeout(() => { try { warmRemoteProbe(config) } catch { } }, 300) : null
|
|
4623
|
-
installQuitWhenAllWindowsClosed(ctx)
|
|
4705
|
+
installQuitWhenAllWindowsClosed(ctx, config)
|
|
4624
4706
|
// 0.3.76:会话投影缓存守卫的定时扫描(默认开,设置里可关)
|
|
4625
4707
|
scheduleCacheGuard(config)
|
|
4626
4708
|
} catch (error) {
|
|
@@ -4637,7 +4719,7 @@ export function apply(ctx, config) {
|
|
|
4637
4719
|
* 而「退出后自动推送」的守护进程只认"主进程 pid 消失"——于是永远等不到,推送不执行。
|
|
4638
4720
|
* 这里在窗口 closed 后查一遍:一个可见窗口都没有了就 app.quit()。
|
|
4639
4721
|
*/
|
|
4640
|
-
function installQuitWhenAllWindowsClosed(ctx) {
|
|
4722
|
+
function installQuitWhenAllWindowsClosed(ctx, config) {
|
|
4641
4723
|
try {
|
|
4642
4724
|
const el = electronApp()
|
|
4643
4725
|
if (!el) return
|
|
@@ -4647,11 +4729,20 @@ function installQuitWhenAllWindowsClosed(ctx) {
|
|
|
4647
4729
|
el.app.on('browser-window-created', (_event, win) => {
|
|
4648
4730
|
try {
|
|
4649
4731
|
win.on('closed', () => {
|
|
4650
|
-
setTimeout(() => {
|
|
4732
|
+
setTimeout(async () => {
|
|
4651
4733
|
try {
|
|
4652
4734
|
const alive = el.BrowserWindow.getAllWindows().filter((w) => w && !w.isDestroyed())
|
|
4653
4735
|
const visible = alive.filter((w) => { try { return w.isVisible() } catch { return false } })
|
|
4654
4736
|
if (visible.length === 0) {
|
|
4737
|
+
// 0.3.93:退出前判一次自动拉取/推送并排好 watcher,再 quit。
|
|
4738
|
+
// 必须在 app.quit() 之前 await:插件随主进程退出而消失,quit 后再判就来不及排队了。
|
|
4739
|
+
// 开关都关 / 没有待同步内容时这个函数很快返回,不影响关闭速度。
|
|
4740
|
+
try {
|
|
4741
|
+
const r = await triggerAutoSyncOnClose(config)
|
|
4742
|
+
if (r && r.queued) {
|
|
4743
|
+
try { ctx.logger?.info?.(`[${PACKAGE_ID}] 退出前已排队 ${r.mode}(自动同步):DSH 退出后立即执行`) } catch { }
|
|
4744
|
+
}
|
|
4745
|
+
} catch { }
|
|
4655
4746
|
try { ctx.logger?.info?.(`[${PACKAGE_ID}] 已无可见窗口,退出客户端(好让退出后同步开始)`) } catch { }
|
|
4656
4747
|
el.app.quit()
|
|
4657
4748
|
}
|
package/package.json
CHANGED
package/tools/clientcheck.mjs
CHANGED
|
@@ -118,9 +118,14 @@ check('面板有「提交说明」输入(生成推送脚本时带上)', sour
|
|
|
118
118
|
check('按钮文案用中文(推送 / 拉取)', source.includes("'只生成推送'") && source.includes("'只生成拉取'"))
|
|
119
119
|
// 0.3.91:设置 → 通用 摘要行的远端信息会刷新,按钮换成「立即拉取/推送(会关闭 DSH)」
|
|
120
120
|
check('设置摘要行展开时 fetch 远端再刷新(远端信息不陈旧)',
|
|
121
|
-
source.includes('const refreshRemoteNow = async () =>')
|
|
121
|
+
source.includes('const refreshRemoteNow = react.useCallback(async () =>')
|
|
122
122
|
&& source.includes("callAuto({ action: 'check' })")
|
|
123
|
-
&& source.includes('setInterval(refreshRemoteNow, 30000)')
|
|
123
|
+
&& source.includes('setInterval(refreshRemoteNow, 30000)')
|
|
124
|
+
&& source.includes('onClick: refreshRemoteNow'))
|
|
125
|
+
check('远端「未提交」纳入本机待同步、刷新按钮触发 fetch(0.3.92)',
|
|
126
|
+
source.includes('repo.uncommitted ?? repo.dirty')
|
|
127
|
+
&& source.includes('data.repo.uncommitted ?? data.repo.dirty')
|
|
128
|
+
&& source.includes('本机待同步 ${data.repo.pending}'))
|
|
124
129
|
check('设置摘要行两个立即按钮走 pull-now / push-now 队列',
|
|
125
130
|
source.includes("actNow('pull-now')")
|
|
126
131
|
&& source.includes("actNow('push-now')")
|
package/tools/selftest.mjs
CHANGED
|
@@ -1776,5 +1776,35 @@ console.log('== 0.3.86:本机数据挪进待办 + 会话显示会话名 + 按
|
|
|
1776
1776
|
&& idxSrc.includes("'plugin-data': ['插件数据', 'Plugin data']")
|
|
1777
1777
|
&& idxSrc.includes("mnemon: ['记忆数据', 'Memory data']"), '分组口径')
|
|
1778
1778
|
}
|
|
1779
|
+
console.log('')
|
|
1780
|
+
console.log('== 0.3.93:点 × 关闭时判一次并排队自动拉取/推送 ==')
|
|
1781
|
+
{
|
|
1782
|
+
const idxSrc = existsSync(join(pluginRootSelf, 'index.js')) ? readFileSync(join(pluginRootSelf, 'index.js'), 'utf8') : ''
|
|
1783
|
+
// 1) 新增退出前排队函数:读开关 / 复用在途 watcher / 空仓只拉 / 拉取优先 / 判据同 scheduleAutoStart
|
|
1784
|
+
check('退出前排队函数存在且读 autoPull/autoPush 开关',
|
|
1785
|
+
/async function triggerAutoSyncOnClose\(config\)/.test(idxSrc)
|
|
1786
|
+
&& /if \(!settings\.autoPull && !settings\.autoPush\) return/.test(idxSrc), 'index.js triggerAutoSyncOnClose')
|
|
1787
|
+
check('已有在途 watcher 时复用、不重复拉起',
|
|
1788
|
+
/autoState\.pending[\s\S]{0,200}isProcessAlive\(autoState\.pending\.watcherPid\)[\s\S]{0,120}reused: true/.test(idxSrc), 'index.js 复用守卫')
|
|
1789
|
+
check('本机仓库为空时仅 autoPull 可排队初始化',
|
|
1790
|
+
/phase !== 'ok'[\s\S]{0,320}settings\.autoPull && phase === 'empty'/.test(idxSrc), 'index.js 空仓分支')
|
|
1791
|
+
check('退出前拉取优先:云端领先就排 pull(且不弹确认框)',
|
|
1792
|
+
/settings\.autoPull && drift\.behind > 0[\s\S]{0,420}mode: 'pull'/.test(idxSrc)
|
|
1793
|
+
&& /退出前检查:云端领先/.test(idxSrc), 'index.js 拉取优先')
|
|
1794
|
+
check('退出前 push 判据与 scheduleAutoStart 一致(领先/未提交/本机待同步)',
|
|
1795
|
+
/const shouldPush = drift\.ahead > 0 \|\| dirty > 0 \|\| \(lp\.known && lp\.pending > 0\)/.test(idxSrc)
|
|
1796
|
+
&& /if \(shouldPush\)/.test(idxSrc), 'index.js push 判据')
|
|
1797
|
+
check('退出前排队的 restart 语义统一为 autoRestart !== false',
|
|
1798
|
+
/function triggerAutoSyncOnClose[\s\S]{0,2600}settings\.autoRestart !== false/.test(idxSrc)
|
|
1799
|
+
&& !/function triggerAutoSyncOnClose[\s\S]{0,2600}settings\.autoRestart === true/.test(idxSrc), 'index.js autoRestart')
|
|
1800
|
+
// 2) 关闭钩子:接 config、quit 之前 await 排队、再 quit;apply 内传 config
|
|
1801
|
+
check('关闭钩子接住 config(installQuitWhenAllWindowsClosed(ctx, config))',
|
|
1802
|
+
/function installQuitWhenAllWindowsClosed\(ctx, config\)/.test(idxSrc)
|
|
1803
|
+
&& /installQuitWhenAllWindowsClosed\(ctx, config\)/.test(idxSrc), 'index.js 钩子签名与调用点')
|
|
1804
|
+
check('点 × 无可见窗口时先 await 退出前排队、再 app.quit()',
|
|
1805
|
+
/await triggerAutoSyncOnClose\(config\)[\s\S]{0,600}el\.app\.quit\(\)/.test(idxSrc), 'index.js 排队先于 quit')
|
|
1806
|
+
check('排队成功写日志:退出后立即执行',
|
|
1807
|
+
/退出前已排队 \$\{r\.mode\}(自动同步)/.test(idxSrc), 'index.js 排队日志')
|
|
1808
|
+
}
|
|
1779
1809
|
process.exit(failures === 0 ? 0 : 1)
|
|
1780
1810
|
|