aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2023-07-18 23:12:34 -0400
committerJesse Luehrs <doy@tozt.net>2023-07-18 23:12:34 -0400
commit7a0eae68c1f3496a1d421b61f66115a7889d7e92 (patch)
treed8c1bf89e3a5ba014241e622a0a506ab85dd199f /src/bin
parentc641445f05d107c6317c99123046cef6b47f22c7 (diff)
downloadrbw-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')
-rw-r--r--src/bin/rbw-agent/actions.rs14
-rw-r--r--src/bin/rbw-agent/agent.rs25
2 files changed, 11 insertions, 28 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")?;
diff --git a/src/bin/rbw-agent/agent.rs b/src/bin/rbw-agent/agent.rs
index 131bab2..29e400b 100644
--- a/src/bin/rbw-agent/agent.rs
+++ b/src/bin/rbw-agent/agent.rs
@@ -89,13 +89,6 @@ impl Agent {
Sync(()),
}
- let err =
- crate::actions::subscribe_to_notifications(self.state.clone())
- .await;
- if let Err(e) = err {
- eprintln!("failed to subscribe to notifications: {e:#}");
- }
-
let c: tokio::sync::mpsc::UnboundedReceiver<
notifications::NotificationMessage,
> = {
@@ -160,18 +153,10 @@ impl Agent {
tokio::spawn(async move {
// this could fail if we aren't logged in, but we
// don't care about that
- match crate::actions::sync(None).await {
- Ok(()) => {
- if let Err(e) = crate::actions::subscribe_to_notifications(
- state,
- )
- .await {
- eprintln!("failed to subscribe to notifications: {e:#}");
- }
- }
- Err(e) => {
- eprintln!("failed to sync: {e:#}");
- }
+ if let Err(e) =
+ crate::actions::sync(None, state.clone()).await
+ {
+ eprintln!("failed to sync: {e:#}");
}
});
self.state.lock().await.set_sync_timeout();
@@ -223,7 +208,7 @@ async fn handle_request(
false
}
rbw::protocol::Action::Sync => {
- crate::actions::sync(Some(sock)).await?;
+ crate::actions::sync(Some(sock), state.clone()).await?;
false
}
rbw::protocol::Action::Decrypt {