diff --git a/Nickvision.Aura.Tests/NetworkTest.cs b/Nickvision.Aura.Tests/NetworkTest.cs index c76cf2b..30c3ba9 100644 --- a/Nickvision.Aura.Tests/NetworkTest.cs +++ b/Nickvision.Aura.Tests/NetworkTest.cs @@ -10,8 +10,8 @@ public class NetworkTest [SkippableFact] public async Task NetworkAccessTest() { + Environment.SetEnvironmentVariable("AURA_DISABLE_NETCHECK", "true"); var netmon = await NetworkMonitor.NewAsync(); - Skip.If(netmon == null); Assert.True(await netmon.GetStateAsync()); } diff --git a/Nickvision.Aura/Network/NetworkMonitor.cs b/Nickvision.Aura/Network/NetworkMonitor.cs index 0b2a19e..7a32582 100644 --- a/Nickvision.Aura/Network/NetworkMonitor.cs +++ b/Nickvision.Aura/Network/NetworkMonitor.cs @@ -12,6 +12,7 @@ namespace Nickvision.Aura.Network; public class NetworkMonitor : IDisposable { private bool _disposed; + private bool _noNetCheck; private Connection? _dbusConnection; private INetworkMonitor? _networkMonitorDBus; private string[]? _networkAddresses; @@ -28,6 +29,7 @@ public class NetworkMonitor : IDisposable private NetworkMonitor() { _disposed = false; + _noNetCheck = false; } /// @@ -37,25 +39,30 @@ private NetworkMonitor() public static async Task NewAsync() { var netmon = new NetworkMonitor(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + var noNetCheckVar = (Environment.GetEnvironmentVariable("AURA_DISABLE_NETCHECK") ?? "").ToLower(); + netmon._noNetCheck = !string.IsNullOrWhiteSpace(noNetCheckVar) && (noNetCheckVar == "true" || noNetCheckVar == "1" || noNetCheckVar == "t" || noNetCheckVar == "yes" || noNetCheckVar == "y"); + if(!netmon._noNetCheck) { - try + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - netmon._dbusConnection = new Connection(Address.Session); - await netmon._dbusConnection.ConnectAsync(); - netmon._networkMonitorDBus = netmon._dbusConnection.CreateProxy("org.freedesktop.portal.Desktop", new ObjectPath("/org/freedesktop/portal/desktop")); - await netmon._networkMonitorDBus.WatchchangedAsync(async () => netmon._stateChanged?.Invoke(netmon, await netmon._networkMonitorDBus.GetAvailableAsync())); + try + { + netmon._dbusConnection = new Connection(Address.Session); + await netmon._dbusConnection.ConnectAsync(); + netmon._networkMonitorDBus = netmon._dbusConnection.CreateProxy("org.freedesktop.portal.Desktop", new ObjectPath("/org/freedesktop/portal/desktop")); + await netmon._networkMonitorDBus.WatchchangedAsync(async () => netmon._stateChanged?.Invoke(netmon, await netmon._networkMonitorDBus.GetAvailableAsync())); + } + catch + { + netmon._networkMonitorDBus = null; + netmon.SetupPing(); + } } - catch + else { - netmon._networkMonitorDBus = null; netmon.SetupPing(); } } - else - { - netmon.SetupPing(); - } return netmon; } @@ -106,9 +113,13 @@ protected virtual void Dispose(bool disposing) /// /// Get current network state /// - /// True if internet connection, else false + /// True if internet connection available, else false public async Task GetStateAsync() { + if(_noNetCheck) + { + return true; + } if (_networkMonitorDBus != null) { return await _networkMonitorDBus.GetAvailableAsync(); diff --git a/Nickvision.Aura/Nickvision.Aura.csproj b/Nickvision.Aura/Nickvision.Aura.csproj index 64b6113..480e047 100644 --- a/Nickvision.Aura/Nickvision.Aura.csproj +++ b/Nickvision.Aura/Nickvision.Aura.csproj @@ -5,7 +5,7 @@ enable true Nickvision.Aura - 2023.11.1 + 2023.11.2 Nickvision Nickvision A cross-platform base for Nickvision applications @@ -14,7 +14,7 @@ (c) Nickvision 2021-2023 https://nickvision.org https://github.com/NickvisionApps/Aura - - Fixed an issue where Updater was rate limited + - If the AURA_DISABLE_NETCHECK env var is set, NetworkMonitor will always return true when checking connectivity state logo-r.png README.md