|
6 | 6 | using System.Security.Cryptography; |
7 | 7 | using System.Security.Principal; |
8 | 8 | using System.Text; |
| 9 | +using Windows.Networking.Connectivity; |
9 | 10 | using UniGetUI.Core.Classes; |
10 | 11 | using UniGetUI.Core.Data; |
11 | 12 | using UniGetUI.Core.Language; |
@@ -639,42 +640,27 @@ public static ProcessStartInfo UpdateEnvironmentVariables(ProcessStartInfo info) |
639 | 640 | /// Pings the update server and 3 well-known sites to check for internet availability |
640 | 641 | /// </summary> |
641 | 642 | public static async Task WaitForInternetConnection() |
642 | | - => await (await TaskRecycler<Task>.RunOrAttachAsync(_waitForInternetConnection)); |
| 643 | + => await TaskRecycler<int>.RunOrAttachAsync_VOID(_waitForInternetConnection); |
643 | 644 |
|
644 | | - public static async Task _waitForInternetConnection() |
| 645 | + public static void _waitForInternetConnection() |
645 | 646 | { |
646 | 647 | if (Settings.Get("DisableWaitForInternetConnection")) return; |
647 | 648 |
|
648 | | - Logger.Debug("Checking for internet connectivity. Pinging google.com, microsoft.com, couldflare.com and marticliment.com"); |
649 | | - string[] hosts = ["google.com", "microsoft.com", "cloudflare.com", "github.com"]; |
650 | | - while (true) |
| 649 | + Logger.Debug("Checking for internet connectivity..."); |
| 650 | + bool internetLost = false; |
| 651 | + |
| 652 | + var profile = NetworkInformation.GetInternetConnectionProfile(); |
| 653 | + while (profile is null || profile.GetNetworkConnectivityLevel() is not NetworkConnectivityLevel.InternetAccess) |
651 | 654 | { |
652 | | - foreach (var host in hosts) |
| 655 | + Thread.Sleep(1000); |
| 656 | + profile = NetworkInformation.GetInternetConnectionProfile(); |
| 657 | + if (!internetLost) |
653 | 658 | { |
654 | | - using (var pinger = new Ping()) |
655 | | - { |
656 | | - try |
657 | | - { |
658 | | - PingReply reply = await pinger.SendPingAsync(host, 10); |
659 | | - if (reply.Status is IPStatus.Success) |
660 | | - { |
661 | | - Logger.Debug( |
662 | | - $"{host} responded successfully to ping, internet connection was validated."); |
663 | | - return; |
664 | | - } |
665 | | - |
666 | | - Logger.Debug($"Could not ping {host}!"); |
667 | | - } |
668 | | - catch (Exception ex) |
669 | | - { |
670 | | - Logger.Debug( |
671 | | - $"Could not ping {host} with error {ex.Message}. Are you connected to the internet?"); |
672 | | - } |
673 | | - } |
| 659 | + Logger.Warn("User is not connected to the internet, waiting for an internet connectio to be available..."); |
| 660 | + internetLost = true; |
674 | 661 | } |
675 | | - |
676 | | - await Task.Delay(TimeSpan.FromSeconds(5)); |
677 | 662 | } |
| 663 | + Logger.Debug("Internet connectivity was established."); |
678 | 664 | } |
679 | 665 |
|
680 | 666 | public static string TextProgressGenerator(int length, int progressPercent, string? extra) |
|
0 commit comments