Skip to content

feat(save): add local auto-backup snapshots, corruption recovery, and restore UI - #330

Merged
chattymin merged 4 commits into
chattymin:mainfrom
KillianHzr:feat/local-auto-backup-snapshots
Sep 25, 2026
Merged

chattymin merged 4 commits into
chattymin:mainfrom
KillianHzr:feat/local-auto-backup-snapshots

Conversation

@KillianHzr

Copy link
Copy Markdown
Contributor

Summary

This PR introduces an automated local snapshot backup and recovery mechanism for CompanionState without modifying the core state schema or depending on external cloud providers.

Key enhancements:

  • Periodic automatic snapshots with rotation: Takes point-in-time snapshots of the companion state into <stateDir>/snapshots/ at an interval of at least 12 hours during regular play and saves. Retains the newest 10 snapshots automatically and prunes older ones.
  • Automatic corruption self-healing: If companion-state.json is corrupted or fails to decode at startup, the app preserves the corrupted file as .corrupt and automatically restores from the latest valid snapshot instead of starting from a blank state.
  • Settings UI & 1-click rollback: Adds an "Automatic Backups (Snapshots)" section within the Settings Backup & Transfer group:
    • Instant "Create snapshot" button for manual restore points.
    • Snapshot list displaying companion sprite, creation timestamp, Pokédex count, and lifetime tokens.
    • "Restore" button triggering a safety confirmation dialog comparing target vs current progress, taking a pre-restore backup snapshot, and seamlessly applying the rollback.
  • Full 7-language localization & safety: All strings are routed through Localization.swift across all 7 supported languages (ko, en, ja, es, fr, pt, de), without Hangul string literals in UI sources. CompanionState stored properties remain unmodified, strictly preserving SaveTransferTests field classification.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Documentation
  • Other:

UI changes

Before After
The Settings Backup & Transfer section only provided manual "Export save" and "Import save" buttons requiring manual JSON file management via system file dialogs. The Settings Backup & Transfer section now includes an "Automatic Backups (Snapshots)" panel with a "Create snapshot" button and a scrollable list of recent restore points showing companion thumbnails, timestamp, Pokédex count, token count, and a 1-click "Restore" button with safety confirmation.

Checklist

  • swift build and swift test pass locally
  • PR title and description are written in English
  • UI changes are described above (before/after — images optional)
  • No copyrighted assets, secrets, or private tooling references are committed (see CONTRIBUTING)
  • Tests were added or updated for this change

@chattymin chattymin left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the 10-snapshot restore boundary. When exactly 10 snapshots exist and the user restores the oldest one, creating the pre-restore snapshot prunes the selected file before it is read. Read and validate the selected snapshot into memory before creating/pruning the safety snapshot, then restore from that data. Please add a regression test for restoring the oldest entry at the retention limit.

@KillianHzr
KillianHzr force-pushed the feat/local-auto-backup-snapshots branch from cc4a75d to c1e8b65 Compare September 24, 2026 06:36
At the 10-snapshot retention limit, the pre-restore safety snapshot pruned
the oldest file before it was read, so restoring the oldest entry failed.
Load and validate the selection first, then restore from memory.
@KillianHzr
KillianHzr force-pushed the feat/local-auto-backup-snapshots branch from c1e8b65 to 572a923 Compare September 24, 2026 07:02
@KillianHzr

Copy link
Copy Markdown
Contributor Author

@chattymin Fixed: the selected snapshot is now read before the safety snapshot is created. Added a regression test for restoring the oldest one at the 10-snapshot limit. Also rebased on main.

@chattymin
chattymin merged commit 13e3bf2 into chattymin:main Sep 25, 2026
2 checks passed
@chattymin

Copy link
Copy Markdown
Owner

Thank you for your contribution!

LuceteYang added a commit to LuceteYang/PikaTokenBar that referenced this pull request Sep 25, 2026
- New usage recap shots (en/ko/ja) rendered from the production RecapCard in
  ScreenshotGenTests, with Gen 1 graduates, plus a tour row in each README (chattymin#332).
- Pace-marker shots pick bar and percent colors with PaceTier like quotaRow does
  (chattymin#349); the pace row explains the six tiers.
- Settings shots gain automatic backup snapshots under Backup & Transfer (chattymin#330)
  and a per-account session key row under Advanced (chattymin#346); footer bumped to 1.9.0.
- "Also in the box" lists Pokedex search/filters (chattymin#329, chattymin#343) and save backups.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Strongorange added a commit to Strongorange/PokeTokenBar-windows that referenced this pull request Oct 19, 2026
… restore UI

Port macOS chattymin#330: snapshots of the save state live under
<stateDir>/.snapshots/<stateFileName>/ in the save-transfer envelope
format, keep the newest ten, and gate automatic snapshots to one per 12
hours (only once the save has progress). A state file that no longer
decodes is moved to .corrupt and the newest valid snapshot is restored
in its place on the next launch. The restore flow validates the chosen
envelope BEFORE taking the pre-restore safety snapshot — at the
retention limit that extra file prunes the oldest entry, which may be
the one being restored (upstream regression). Settings gains an
automatic-backups section with create/restore and a history that starts
collapsed (upstream chattymin#446).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants