From 91efcd5a023b5719b816ffe97d088d4649940ccc Mon Sep 17 00:00:00 2001 From: Nick Logozzo Date: Wed, 8 Nov 2023 14:10:10 -0500 Subject: [PATCH 1/4] Network - NoNetCheck Var --- Nickvision.Aura/Network/NetworkMonitor.cs | 37 +++++++++++++++-------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/Nickvision.Aura/Network/NetworkMonitor.cs b/Nickvision.Aura/Network/NetworkMonitor.cs index 0b2a19e..2eb892c 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(); From fdc1d6ccbc09dac2c815d7b95ddc1f673c2b59cb Mon Sep 17 00:00:00 2001 From: Nick Logozzo Date: Wed, 8 Nov 2023 14:10:15 -0500 Subject: [PATCH 2/4] V2023.11.2 --- Nickvision.Aura/Nickvision.Aura.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 4afb5180816d2fb19b476b9bf1b24640fe78e111 Mon Sep 17 00:00:00 2001 From: Nick Logozzo Date: Wed, 8 Nov 2023 14:13:40 -0500 Subject: [PATCH 3/4] Network - Fix Null Error --- Nickvision.Aura.Tests/NetworkTest.cs | 1 - Nickvision.Aura/Network/NetworkMonitor.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Nickvision.Aura.Tests/NetworkTest.cs b/Nickvision.Aura.Tests/NetworkTest.cs index c76cf2b..1c650e9 100644 --- a/Nickvision.Aura.Tests/NetworkTest.cs +++ b/Nickvision.Aura.Tests/NetworkTest.cs @@ -11,7 +11,6 @@ public class NetworkTest public async Task NetworkAccessTest() { 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 2eb892c..7a32582 100644 --- a/Nickvision.Aura/Network/NetworkMonitor.cs +++ b/Nickvision.Aura/Network/NetworkMonitor.cs @@ -39,7 +39,7 @@ private NetworkMonitor() public static async Task NewAsync() { var netmon = new NetworkMonitor(); - var noNetCheckVar = Environment.GetEnvironmentVariable("AURA_DISABLE_NETCHECK").ToLower(); + 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) { From 044dd38f258547d917e5f384aaeb0745a0aaaf0c Mon Sep 17 00:00:00 2001 From: Nick Logozzo Date: Wed, 8 Nov 2023 14:15:37 -0500 Subject: [PATCH 4/4] Fix Tests --- Nickvision.Aura.Tests/NetworkTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Nickvision.Aura.Tests/NetworkTest.cs b/Nickvision.Aura.Tests/NetworkTest.cs index 1c650e9..30c3ba9 100644 --- a/Nickvision.Aura.Tests/NetworkTest.cs +++ b/Nickvision.Aura.Tests/NetworkTest.cs @@ -10,6 +10,7 @@ public class NetworkTest [SkippableFact] public async Task NetworkAccessTest() { + Environment.SetEnvironmentVariable("AURA_DISABLE_NETCHECK", "true"); var netmon = await NetworkMonitor.NewAsync(); Assert.True(await netmon.GetStateAsync()); }