From 89453287a2ccb39a71cbc329849c73edda66cacb Mon Sep 17 00:00:00 2001 From: steven-mpawulo Date: Mon, 18 Aug 2025 12:28:07 +0300 Subject: [PATCH 1/3] checks for posthog availability --- Cargo.lock | 1 + crates/network/Cargo.toml | 1 + crates/network/src/lib.rs | 25 +++++++++++++------------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d71084c9e..5d70ba42a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9182,6 +9182,7 @@ name = "network" version = "0.1.0" dependencies = [ "pinger", + "reqwest 0.12.22", ] [[package]] diff --git a/crates/network/Cargo.toml b/crates/network/Cargo.toml index 0ec636968..c22ac03c9 100644 --- a/crates/network/Cargo.toml +++ b/crates/network/Cargo.toml @@ -5,3 +5,4 @@ edition = "2021" [dependencies] pinger = { git = "https://github.com/orf/gping", package = "pinger" } +reqwest.workspace = true diff --git a/crates/network/src/lib.rs b/crates/network/src/lib.rs index 31d7cae06..22ffe04d6 100644 --- a/crates/network/src/lib.rs +++ b/crates/network/src/lib.rs @@ -1,16 +1,17 @@ +use reqwest::Client; +use std::time::Duration; + pub async fn is_online() -> bool { - let target = "8.8.8.8".to_string(); - let interval = std::time::Duration::from_secs(1); - let options = pinger::PingOptions::new(target, interval, None); + let client = Client::builder() + .timeout(Duration::from_secs(8)) + .build() + .unwrap(); - if let Ok(stream) = pinger::ping(options) { - if let Some(message) = stream.into_iter().next() { - match message { - pinger::PingResult::Pong(_, _) => return true, - _ => return false, - } - } - } - false + let url = "https://posthog.com/"; + + match client.get(url).send().await { + Ok(resp) if resp.status().is_success() => true, + _ => false, + } } From 66e4ef16eb64fbb5f82abdc64ccf3d5b28b1bb19 Mon Sep 17 00:00:00 2001 From: steven-mpawulo Date: Mon, 18 Aug 2025 13:04:16 +0300 Subject: [PATCH 2/3] rectifies to use a single client instance --- crates/analytics/src/lib.rs | 3 ++- crates/network/src/lib.rs | 11 +---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/crates/analytics/src/lib.rs b/crates/analytics/src/lib.rs index 496e58a79..bf3d8cfd0 100644 --- a/crates/analytics/src/lib.rs +++ b/crates/analytics/src/lib.rs @@ -20,7 +20,8 @@ impl AnalyticsClient { } pub async fn event(&self, payload: AnalyticsPayload) -> Result<(), Error> { - if !hypr_network::is_online().await { + + if !hypr_network::is_online(&self.client).await { return Ok(()); } diff --git a/crates/network/src/lib.rs b/crates/network/src/lib.rs index 22ffe04d6..5d8f9c2af 100644 --- a/crates/network/src/lib.rs +++ b/crates/network/src/lib.rs @@ -1,13 +1,4 @@ -use reqwest::Client; -use std::time::Duration; - -pub async fn is_online() -> bool { - let client = Client::builder() - .timeout(Duration::from_secs(8)) - .build() - .unwrap(); - - +pub async fn is_online(client: &reqwest::Client) -> bool { let url = "https://posthog.com/"; match client.get(url).send().await { From 6f811393e6141b0d7b07c6e4c00779372db4deb4 Mon Sep 17 00:00:00 2001 From: steven-mpawulo Date: Mon, 18 Aug 2025 13:05:38 +0300 Subject: [PATCH 3/3] changes how reqwest is added to the toml file --- crates/network/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/network/Cargo.toml b/crates/network/Cargo.toml index c22ac03c9..5477a2eb7 100644 --- a/crates/network/Cargo.toml +++ b/crates/network/Cargo.toml @@ -5,4 +5,4 @@ edition = "2021" [dependencies] pinger = { git = "https://github.com/orf/gping", package = "pinger" } -reqwest.workspace = true +reqwest = { workspace = true }