From b48451610fb94b34d7b6b0398c12a2e9e1872326 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 22 Dec 2020 10:46:50 +1000 Subject: [PATCH] fix sync indicator turning blue after startup sync https://forums.ankiweb.net/t/why-is-my-sync-button-blue/2078/26?u=dae --- rslib/src/backend/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rslib/src/backend/mod.rs b/rslib/src/backend/mod.rs index 23b124b01..db4a1802e 100644 --- a/rslib/src/backend/mod.rs +++ b/rslib/src/backend/mod.rs @@ -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())