diff --git a/watchers/src/report_client.rs b/watchers/src/report_client.rs index 24d8eb6..6f5edd3 100644 --- a/watchers/src/report_client.rs +++ b/watchers/src/report_client.rs @@ -41,18 +41,18 @@ impl ReportClient { Fut: Future>, E: std::error::Error + Send + Sync + 'static, { - for (attempt, &secs) in [1, 2].iter().enumerate() { + for (attempt, secs) in [0.01, 0.1, 1., 2.].iter().enumerate() { match f().await { - Ok(val) => return Ok(val), - Err(e) - if e.to_string() - .contains("tcp connect error: Connection refused") => - { - warn!("Failed to connect on attempt #{attempt}, retrying: {}", e); - - tokio::time::sleep(tokio::time::Duration::from_secs(secs)).await; + Ok(val) => { + if attempt > 0 { + debug!("OK at attempt #{}", attempt + 1); + } + return Ok(val); + } + Err(e) => { + warn!("Failed on attempt #{}, retrying in {:.1}s: {}", attempt + 1, secs, e); + tokio::time::sleep(tokio::time::Duration::from_secs_f64(*secs)).await; } - Err(e) => return Err(e), } } diff --git a/watchers/src/watchers/x11_window.rs b/watchers/src/watchers/x11_window.rs index 8e06f49..02a16fd 100644 --- a/watchers/src/watchers/x11_window.rs +++ b/watchers/src/watchers/x11_window.rs @@ -32,6 +32,10 @@ impl WindowWatcher { r#"Changed window app_id="{}", title="{}", wm_instance="{}""#, app_id, title, wm_instance ); + client + .send_active_window_with_instance(&self.last_app_id, &self.last_title, Some(&self.last_wm_instance)) + .await + .with_context(|| "Failed to send heartbeat for previous window")?; self.last_app_id = app_id.clone(); self.last_title = title.clone(); self.last_wm_instance = wm_instance.clone();