diff --git a/CHANGELOG.md b/CHANGELOG.md index b72ba378c4e6..d7d7fb1c063f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ Line wrap the file at 100 chars. Th ### Added - Add header containing OS version to version-check API call to enable OS specific compatibility and vulnerability checks. +- Add `TALPID_DISABLE_OFFLINE_MONITOR` environment variable to allow users to disable offline + detection. #### Android - Allow to configure the tunnel to use custom DNS servers. diff --git a/README.md b/README.md index ed265bc2109c..a1967330d383 100644 --- a/README.md +++ b/README.md @@ -369,6 +369,8 @@ echo "org.gradle.jvmargs=-Xmx4608M" >> ~/.gradle/gradle.properties * `TALPID_FORCE_USERSPACE_WIREGUARD` - Forces the daemon to use the userspace implementation of WireGuard on Linux. +* `TALPID_DISABLE_OFFLINE_MONITOR` - Forces the daemon to always assume the host is online. + ## Building and running the desktop Electron GUI app diff --git a/talpid-core/src/offline/mod.rs b/talpid-core/src/offline/mod.rs index 9a6ce1dae5a1..d77b3583c863 100644 --- a/talpid-core/src/offline/mod.rs +++ b/talpid-core/src/offline/mod.rs @@ -20,13 +20,23 @@ mod imp; #[path = "android.rs"] mod imp; +lazy_static::lazy_static! { + /// Disables offline monitor + static ref FORCE_DISABLE_OFFLINE_MONITOR: bool = std::env::var("TALPID_FORCE_USERSPACE_WIREGUARD") + .map(|v| v != "0") + .unwrap_or(false); +} + pub use self::imp::Error; -pub struct MonitorHandle(imp::MonitorHandle); +pub struct MonitorHandle(Option); impl MonitorHandle { pub async fn is_offline(&mut self) -> bool { - self.0.is_offline().await + match self.0.as_mut() { + Some(monitor) => monitor.is_offline().await, + None => false, + } } } @@ -34,12 +44,18 @@ pub async fn spawn_monitor( sender: Weak>, #[cfg(target_os = "android")] android_context: AndroidContext, ) -> Result { - Ok(MonitorHandle( - imp::spawn_monitor( - sender, - #[cfg(target_os = "android")] - android_context, + let monitor = if !*FORCE_DISABLE_OFFLINE_MONITOR { + Some( + imp::spawn_monitor( + sender, + #[cfg(target_os = "android")] + android_context, + ) + .await?, ) - .await?, - )) + } else { + None + }; + + Ok(MonitorHandle(monitor)) }