When the sync server is unreachable (offline reading, intermittent WiFi,
server down), progress updates are now queued locally instead of being
silently dropped. Queued items are drained on the next successful network
connection.
Queue behavior:
- One entry per document per day (preserves daily reading statistics)
- Entries expire after 4 weeks
- Hard cap of 200 entries as safety net
- Auth failures (401) are not queued (won't resolve by retrying)
- Queue is cleared on logout
Integration points:
- updateProgress: queues on pcall failure or non-auth callback failure
- _onNetworkConnected: drains queue before pulling remote progress
- _onCloseDocument: queues immediately if offline instead of blocking
with goOnlineToRun (avoids WiFi prompts on document close)
Fixes#9267, fixes#10678, fixes#11105
Send a metadata object (filename, title, authors) with progress sync
requests when the user opts in via a new 'Send document metadata' toggle
(default off). The metadata is silently ignored by the official sync
server but can be used by custom sync servers.
Closes#13810
Ref: #8764
An attempt was made in the original code, but the whole thing was designed in the hope of actually switching to turbo, so it was super janky without it.
Anyway, we now actually have a sane way to set socket timeouts, so, use that, and set them very tight for now.
This is fairly critical right now, because the server is down, and the default timeouts are ~30s. That happens to be *above* the debounce threshold, so you can't even hope for that to help you. Meaning, right now, you get a 2 * 30s block on resume with auto sync. That's... Very Not Good(TM).
That becomes a single 2s one after this.
Currently the progress sent to the server can be either a string or an int (depending on whetther the document has pages).
The following are both payload sent from koreader to the server.
```
{"percentage":0.005,"device":"device_name","device_id":"B78EA04ACC3A453DBA220D720C0BE102","document":"348e34463a44ba68659fc6fe814a6778","progress":3}
```
where document `348e34463a44ba68659fc6fe814a6778` is a pdf file.
```
{"percentage":1,"device":"device_name","device_id":"B78EA04ACC3A453DBA220D720C0BE102","document":"4eb484b229696cb39cd8fe5495aa1bbe","progress":"\/body\/DocFragment[30]\/body\/p\/img.0"}
```
where document `4eb484b229696cb39cd8fe5495aa1bbe` is an epub file.
This may add extra work to the backend server. A few commits were added to my personal fork of [kosyncsrv](https://github.com/yeeac/kosyncsrv) (a kosync backend server). kosyncsrv initially tries to decode progress as a string. It then failed on document with pages (in which, progress is just integer page number). I then change the field's type, only to [revert it later](https://github.com/contrun/kosyncsrv/commit/8a642e31a0bcb061a04ececd4af57a27836b7928).
I believe it is more appropriate for us to fix the progress type to string.
This reverts commit d90e221a17. Reverts #6489 since it introduced problems for people having [*]Auto sync now and in the furture & Action when wifi off: prompt.
The 'KOSync' plugin will synchronize furthest reading progress
across different koreader devices after users registering their
devices.
The synchronizing service is open-sourced as the project
[koreader/koreader-sync-server](https://github.com/koreader/koreader-sync-server).