Skip to content

Bank Sync: one Bank on all your devices and browser (optional, off by default) - #51

Open
YoruDev-Ryland wants to merge 3 commits into
sofianeelhor:devfrom
YoruDev-Ryland:pr/bank-sync
Open

YoruDev-Ryland wants to merge 3 commits into
sofianeelhor:devfrom
YoruDev-Ryland:pr/bank-sync

Conversation

@YoruDev-Ryland

Copy link
Copy Markdown

Related: #18

Bank Sync keeps one Bank in step across devices (handheld, phone, tablet) through a PKForge Sync server that users run themselves with Docker. It is off by default. Anyone who never opens it keeps today's app: the Bank stays in the same folder with the same files.

The server is GPL-3.0-or-later and is included as a submodule at external/pkforge-sync-server, like PKHeX.

How it works

  • Offline-first. Every device keeps its whole Bank and works without a network. Changes are sent about a second after they're made, when the app returns to the foreground, and every two minutes.
  • Nothing is silently lost. The server applies each change all or nothing. If two devices change the same Pokémon, the app asks which version to keep, or keeps both.
  • First sync. If the device and the server both have Pokémon, the user chooses to merge them or to replace the device's Bank with the server's. Before replacing, the app copies the Bank, and that copy can be restored from Restore points.
  • Connecting. Sign in with the server's address, or enter a pairing code shown on another device. The code can be typed or read from a QR code image, for devices without a camera.

Size

Files Lines
New code (src/PKForge.Sync, Bank Sync page, small services) 22 +3,112
Existing files 23 +428 / −40
New tests (tests/PKForge.Sync.Tests, 3 Domain test files) 23 +2,573

Three commits, each building on the last:

  1. Bank: FileBankService gains ApplyRemote, IsReadOnly and Reload. Box names, wallpapers and a new bank-settings.json are grouped in BankDecor and report local edits.
  2. Sync library: PKForge.Sync, with no UI. Its tests start the server in-process, so CI needs nothing running. build.yml gains one dotnet test line.
  3. App: the Bank Sync page, plus changes to App.cs, MauiProgram.cs, BankPage.cs, the Restore points page, LivingDexAutopilot.cs, the QR popup and the manifest (network permission).

Changes to existing behavior

  • Living dex start box moves once from device preferences into bank-settings.json, so every device fills the same boxes. The new value is written before the old preference is removed.
  • Returning to the app. Android can recreate the activity without calling OnResume, so the app never noticed it was back in the foreground. It now finishes that step when the window activates.
  • Restore points also list Bank copies, whatever save is open. Restoring one turns Bank Sync off first, so the old Bank isn't sent to the other devices.

Testing

  • dotnet test: Domain 626, Engine 953, Sync 142, all passing.
  • Used on an AYN Odin 3 and the Android emulator with a self-hosted server: moving and depositing Pokémon, Living Dex Autopilot, box names and wallpapers, pairing, going offline and back.

Two small fixes found along the way are separate PRs (the menu marquee crash and the popup scrollbar line). They don't depend on this one.

Additions the sync library builds on; Local mode behaves exactly as before.
- FileBankService.ApplyRemote: applies a batch from a sync server in one index
  write (checked first, so a refused batch changes nothing), plus IsReadOnly
  and Reload.
- BankDecor groups box names, wallpapers and a new BankSettings file
  (bank-settings.json beside the index) so they can sync as part of the Bank.
  Each raises Changed on local edits only, and can be replaced or reloaded.
… server

A library with no UI: every device keeps its full Bank and works offline;
changes go out in groups that the server applies all-or-nothing, and edits of
the same Pokémon on two devices become conflicts the user resolves instead of
silent overwrites. A copy of the Bank is taken before it is ever replaced.

The server (GPL-3.0-or-later, self-hostable with Docker) is a submodule at
external/pkforge-sync-server; the tests start it in-process, so CI needs no
running server.
- Bank Sync page: connect with an address and sign in, a pairing code (typed
  or from a QR picture, for devices without a camera), status, conflicts,
  devices and Stop syncing. Syncs a second after a change, when the app
  returns, and every two minutes.
- Restore points also list the Bank copies sync takes; restoring one turns
  Bank Sync off first so the old Bank isn't sent to other devices.
- The living dex start box moves once from device preferences into the Bank's
  settings, so every device fills the same boxes.
- App lifecycle: Android can recreate the activity without OnResume; the
  return to the foreground is now completed when the window activates.
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.

1 participant