Skip to content

Sync with Dropbox on the desktop - #372

Merged
tiendc merged 3 commits into
mainfrom
sync/dropbox
Dec 5, 2026
Merged

tiendc merged 3 commits into
mainfrom
sync/dropbox

Conversation

@tiendc

@tiendc tiendc commented Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator

This PR builds step 2 of the Dropbox design (#370): the backend and desktop sign-in. Dropbox is offered in Settings › Sync as the last of the clouds: Google Drive, OneDrive, iCloud (through the web), then Dropbox.

Backend (crates/remote/src/dropbox.rs)

  • Listing: list_folder (recursive) the first time, then list_folder/continue with its cursor. A reset cursor lists the whole folder again.
  • Reads: files/download. The rev comes from Dropbox-API-Result, and a read is kept until the rev changes. parallel() is 16.
  • Writes:
    • A new name is uploaded with mode: add.
    • A known file uses update with the rev this device last read or wrote. A 409 means Ok(false), and the file is looked up again.
    • format.json uses overwrite.
    • A name the listing says is gone is written with add again (the deleted-file-comes-back trap).
  • One write at a time. Uploads, commits and removals wait for each other, since Dropbox answers 429 to writes sent together.
  • Batches: batch() is 1000. replace_all sends upload sessions 16 at once, then one finish_batch_v2 commits them. Each entry keeps its own condition. Entries that failed for another reason are retried one by one.
  • Errors: 401 refreshes the token once; invalid_grant means signed out; 429 and 5xx wait for Retry-After; insufficient_space says the account is full.
  • Account: another account than the place's is refused (users/get_current_account).
  • Revoke: dropbox::revoke is called on Stop syncing.

Sign-in: PKCE with token_access_type=offline. Dropbox refuses any unregistered port, so the app has three registered: http://localhost:52819/, …:52820/ and …:52821/. This adds Loopback::bind_registered, which tries them in turn. It takes each port on both 127.0.0.1 and [::1], because localhost is IPv6 too on macOS and Windows and a browser may try that first. A port another program holds on either side is passed over. A wrong-state request is answered 400, and the listener keeps waiting. When all three ports are taken, the reason shows beside the button.

App

  • [sync] dropbox = { account, account_id }.
  • DROPBOX_ACCOUNT, so signing in to another account is asked about first.
  • Dropbox offers Start over here in the join step.
  • The phones map it to nothing for now.

Tests

  • 17 tests against a fake Dropbox. They cover two devices sharing a vault, a stale rev, an add race, a batch with stale entries, the deleted name, a paged listing and a cursor reset, the token, another account, 429 waits, writes from several threads, revoke, and sign-in (exact redirect, stale-state page, port fallback, missing write scope).
  • against_the_real_dropbox runs when SHELLWING_DROPBOX_REFRESH is set. It passed against the real API: a vault of 21 hosts started in 6.6 s, and a second device joined and synced in 7.3 s.
  • UI scenarios: Dropbox sign-in opens Dropbox with the registered redirect, another Dropbox account is asked about, and Dropbox offers to start over. The pill indexes for Git and Server moved by one, and both Dropbox scenarios take port 52818 as a lock, since one of them holds all three ports.

Local checks: make lint, cargo clippy -p shellwing --features ui-tests --all-targets, i18n.py check, cargo test --workspace, and the ui_tests::sync scenarios all pass. Not done: a sign-in in the real app, which needs a person to allow it in the browser.

🤖 Generated with Claude Code

tiendc and others added 3 commits December 5, 2026 12:54
A Dropbox backend for the app folder (`crates/remote/src/dropbox.rs`),
as designed in #370:

- Listing through `list_folder` and its cursor.
- New names are uploaded with `add`, and replaces with `update` by the
  rev this device last read or wrote.
- Writes go one at a time, since Dropbox answers 429 to writes sent
  together. The records of a sync go up as upload sessions, sent 16 at
  once, and are committed by one `finish_batch_v2` through the
  `batch`/`replace_all` hook, each entry keeping its own condition.
- A name the listing says is gone is written with `add` again.

Desktop sign-in: PKCE through a loopback on the port registered with
Dropbox (52819), since Dropbox takes no other.
Settings › Sync › Dropbox; another account is asked about; Stop syncing
revokes the token.

Tested against a fake Dropbox, and once against the real one
(SHELLWING_DROPBOX_REFRESH): a vault of 21 hosts started in 6.6 s, and
a second device joined and synced in 7.3 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Dropbox takes only the redirects registered on the app, so a port
another program holds stopped signing in. Ports 52820 and 52821 are now
registered too, after 52819, and each is tried in turn.

`localhost` is [::1] as well on macOS and Windows, and a browser may try
it first. A program holding the port there alone would get the code
while shellwing waited until signing in timed out. Now the port is taken
on [::1] too where the machine has IPv6, so a browser coming back that
way is answered. A port held on either side is passed over. When all
three are taken, the reason shows beside the button.

Tests: a port held on IPv6 alone is passed over, and a browser coming
back over IPv6 is answered; both fail without the change. A UI scenario
holds the three ports and checks the reason shows and no browser opens.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The order of the cloud pills is now Google Drive, OneDrive, iCloud
(where it goes through the web), Dropbox. On a Mac, iCloud comes first
and Dropbox follows OneDrive.

The two Dropbox UI scenarios take port 52818 as a lock before using the
registered ports. Scenarios run at once in processes of their own, and
the one that holds all three ports could make the sign-in scenario find
none free.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tiendc
tiendc merged commit 32da603 into main Dec 5, 2026
5 checks passed
@tiendc
tiendc deleted the sync/dropbox branch December 5, 2026 06:21
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