mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 21:10:48 +00:00
* fix: prevent empty vault from overwriting cloud data on startup (#679) Fixes a data-loss scenario where an empty local vault (caused by an update, storage corruption, or import failure) silently overwrites a non-empty cloud vault on startup via auto-sync. The root cause is a startup timing race: the debounced auto-sync effect (3s after data change) can fire before checkRemoteVersion (1s delay + async download) completes its remote pull. When the local vault is empty, this pushes an empty payload to the Gist, permanently erasing the user's data. Four complementary fixes: A. Empty vault push guard (useAutoSync syncNow): Auto-sync refuses to push a payload where hosts, keys, snippets, and identities are ALL empty. Manual sync from Settings is still allowed for the rare case where the user intentionally emptied everything. Prevents the most dangerous path. B. Skip redundant post-merge push (useAutoSync checkRemoteVersion): After applying a three-way merge result from the remote, set skipNextSyncRef so the data-change effect does not immediately re-upload the same payload. Removes one unnecessary API call per startup sync. C. Gate auto-sync on remote check completion (useAutoSync effect): Added remoteCheckDoneRef — the debounced auto-sync effect will not fire until checkRemoteVersion has completed (success or failure). This closes the timing window entirely: an empty vault can no longer race ahead of the remote pull. D. Empty-vault-vs-cloud confirmation dialog (App.tsx + useAutoSync): When checkRemoteVersion detects local is empty but cloud has data, it pauses and shows a root-level dialog with two options: - "Restore from Cloud" (recommended) — applies the remote payload - "Keep Empty" — starts fresh with an empty vault The dialog blocks the sync flow via a Promise that resolves when the user picks an option. This gives users explicit control over a situation that previously happened silently behind their backs. Also adds en + zh-CN i18n strings for the new dialog and toast messages. Closes #679 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address codex review on PR #683 P1-1: Unified isPayloadEffectivelyEmpty helper covering all synced entity arrays (hosts, keys, snippets, identities, customGroups, snippetPackages, portForwardingRules, knownHosts, groupConfigs). Replaces the three inline checks in syncNow and checkRemoteVersion that only covered hosts/keys/snippets/identities. P1-2: Replaced hand-rolled overlay div with the project's existing Dialog/DialogContent/DialogHeader/DialogFooter components. This adds role="dialog", aria-modal, focus trap, and ESC-key dismiss for free. Used lucide-react AlertTriangle/Download/Trash2 icons instead of inline SVGs. P2-1: Guard against double-resolve in resolveEmptyVaultConflict by nulling the ref immediately on first call. P2-2: Replaced hardcoded "N hosts, N keys, N snippets" with an i18n key using interpolation (cloudSummary) so the count text is properly translated in zh-CN. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address round-2 codex review on PR #683 P1: isPayloadEffectivelyEmpty now also checks the settings object. A vault with only settings (e.g. custom theme, font size) and zero hosts/keys/snippets is no longer treated as empty. P1: Dialog accessibility — use hideCloseButton to remove the non- functional close button, onEscapeKeyDown + onOpenChange prevent dismiss (the user MUST choose an option), and wrap the description in DialogDescription so aria-describedby is properly linked. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: use single-brace interpolation syntax for cloudSummary i18n key The project's i18n system uses single-brace placeholders ({var}), not double-brace ({{var}}). The double-brace syntax was rendering as raw text instead of being interpolated. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>