fix sync indicator turning blue after startup sync

https://forums.ankiweb.net/t/why-is-my-sync-button-blue/2078/26?u=dae
This commit is contained in:
Damien Elmes 2020-12-22 10:46:50 +10:00
parent 86108cca55
commit b48451610f

View file

@ -1541,13 +1541,19 @@ impl Backend {
// fetch and cache result
let rt = self.runtime_handle();
let time_at_check_begin = TimestampSecs::now();
let remote: SyncMeta = rt.block_on(get_remote_sync_meta(input.into()))?;
let response = self.with_col(|col| col.get_sync_status(remote).map(Into::into))?;
{
let mut guard = self.state.lock().unwrap();
guard.remote_sync_status.last_check = TimestampSecs::now();
guard.remote_sync_status.last_response = response;
// On startup, the sync status check will block on network access, and then automatic syncing begins,
// taking hold of the mutex. By the time we reach here, our network status may be out of date,
// so we discard it if stale.
if guard.remote_sync_status.last_check < time_at_check_begin {
guard.remote_sync_status.last_check = time_at_check_begin;
guard.remote_sync_status.last_response = response;
}
}
Ok(response.into())