diff options
author | Jesse Luehrs <doy@tozt.net> | 2023-07-18 23:12:34 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2023-07-18 23:12:34 -0400 |
commit | 7a0eae68c1f3496a1d421b61f66115a7889d7e92 (patch) | |
tree | d8c1bf89e3a5ba014241e622a0a506ab85dd199f /src/bin/rbw-agent/actions.rs | |
parent | c641445f05d107c6317c99123046cef6b47f22c7 (diff) | |
download | rbw-7a0eae68c1f3496a1d421b61f66115a7889d7e92.tar.gz rbw-7a0eae68c1f3496a1d421b61f66115a7889d7e92.zip |
reconnect to websockets after every successful sync
rather than scattering it around various parts of the code
Diffstat (limited to 'src/bin/rbw-agent/actions.rs')
-rw-r--r-- | src/bin/rbw-agent/actions.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs index b7295f8..4c7f6fb 100644 --- a/src/bin/rbw-agent/actions.rs +++ b/src/bin/rbw-agent/actions.rs @@ -205,10 +205,6 @@ pub async fn login( } } } - - if let Err(e) = subscribe_to_notifications(state.clone()).await { - eprintln!("failed to subscribe to notifications: {e}"); - } } respond_ack(sock).await?; @@ -332,7 +328,7 @@ async fn login_success( db.protected_key = Some(protected_key.to_string()); save_db(&db).await?; - sync(None).await?; + sync(None, state.clone()).await?; let db = load_db().await?; let Some(protected_private_key) = db.protected_private_key @@ -501,6 +497,7 @@ pub async fn check_lock( pub async fn sync( sock: Option<&mut crate::sock::Sock>, + state: std::sync::Arc<tokio::sync::Mutex<crate::agent::State>>, ) -> anyhow::Result<()> { let mut db = load_db().await?; @@ -529,6 +526,10 @@ pub async fn sync( db.entries = entries; save_db(&db).await?; + if let Err(e) = subscribe_to_notifications(state.clone()).await { + eprintln!("failed to subscribe to notifications: {e}"); + } + if let Some(sock) = sock { respond_ack(sock).await?; } @@ -688,9 +689,6 @@ pub async fn subscribe_to_notifications( return Ok(()); } - // access token might be out of date, so we do a sync to refresh it - sync(None).await?; - let config = rbw::config::Config::load_async() .await .context("Config is missing")?; |