Skip to content

Commit

Permalink
Fixed: InternetTest shows error if there isn't internet (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Apr 12, 2021
1 parent 7036107 commit 42cf21c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 60 deletions.
93 changes: 50 additions & 43 deletions InternetTest/InternetTest/Pages/LocalizeIPPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ MIT License
*/
using InternetTest.Classes;
using InternetTest.Enums;
using LeoCorpLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -40,51 +41,57 @@ MIT License

namespace InternetTest.Pages
{
/// <summary>
/// Interaction logic for LocalizeIPPage.xaml
/// </summary>
public partial class LocalizeIPPage : Page
{
public LocalizeIPPage()
{
InitializeComponent();
}
private string lat, lon = "";
/// <summary>
/// Interaction logic for LocalizeIPPage.xaml
/// </summary>
public partial class LocalizeIPPage : Page
{
public LocalizeIPPage()
{
InitializeComponent();
}
private string lat, lon = "";

private async void LocalizeBtn_Click(object sender, RoutedEventArgs e)
{
var ip = await Global.GetIPInfo(IPTxt.Text); // Get IP info
lat = ip.Lat; // Define
lon = ip.Lon; // Define
IPInfoTxt.Text = ip.ToString(); // Show IP info
private async void LocalizeBtn_Click(object sender, RoutedEventArgs e)
{
if (await NetworkConnection.IsAvailableAsync())
{
var ip = await Global.GetIPInfo(IPTxt.Text); // Get IP info
lat = ip.Lat; // Define
lon = ip.Lon; // Define
IPInfoTxt.Text = ip.ToString(); // Show IP info

if (string.IsNullOrEmpty(IPTxt.Text))
{
IPTxt.Text = ip.Query;
}
}
if (string.IsNullOrEmpty(IPTxt.Text))
{
IPTxt.Text = ip.Query;
}
}
}

private void OpenMapBtn_Click(object sender, RoutedEventArgs e)
{
if (lat != "" && lon != "")
{
switch (Global.Settings.MapProvider)
{
case MapProviders.BingMaps: Global.OpenLinkInBrowser($"https://www.bing.com/maps?q={ lat} {lon}"); break;
case MapProviders.GoogleMaps: Global.OpenLinkInBrowser($"https://www.google.com/maps/place/{lat},{lon}"); break;
case MapProviders.OpenStreetMap: Global.OpenLinkInBrowser($"https://www.openstreetmap.org/#map=12/{lat}/{lon}"); break;
default: Global.OpenLinkInBrowser($"https://www.openstreetmap.org/#map=12/{lat}/{lon}"); break;
}
}
}
private void OpenMapBtn_Click(object sender, RoutedEventArgs e)
{
if (lat != "" && lon != "")
{
switch (Global.Settings.MapProvider)
{
case MapProviders.BingMaps: Global.OpenLinkInBrowser($"https://www.bing.com/maps?q={ lat} {lon}"); break;
case MapProviders.GoogleMaps: Global.OpenLinkInBrowser($"https://www.google.com/maps/place/{lat},{lon}"); break;
case MapProviders.OpenStreetMap: Global.OpenLinkInBrowser($"https://www.openstreetmap.org/#map=12/{lat}/{lon}"); break;
default: Global.OpenLinkInBrowser($"https://www.openstreetmap.org/#map=12/{lat}/{lon}"); break;
}
}
}

private async void MyIPBtn_Click(object sender, RoutedEventArgs e)
{
var ip = await Global.GetIPInfo(""); // Get IP info
lat = ip.Lat; // Define
lon = ip.Lon; // Define
IPInfoTxt.Text = ip.ToString(); // Show IP info
IPTxt.Text = ip.Query;
}
}
private async void MyIPBtn_Click(object sender, RoutedEventArgs e)
{
if (await NetworkConnection.IsAvailableAsync())
{
var ip = await Global.GetIPInfo(""); // Get IP info
lat = ip.Lat; // Define
lon = ip.Lon; // Define
IPInfoTxt.Text = ip.ToString(); // Show IP info
IPTxt.Text = ip.Query;
}
}
}
}
52 changes: 35 additions & 17 deletions InternetTest/InternetTest/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,26 @@ private async void InitUI()
// Load the TestSiteTxt
TestSiteTxt.Text = Global.Settings.TestSite; // Set text

// Update the UpdateStatusTxt
isAvailable = Update.IsAvailable(Global.Version, await Update.GetLastVersionAsync(Global.LastVersionLink));

UpdateStatusTxt.Text = isAvailable ? Properties.Resources.AvailableUpdates : Properties.Resources.UpToDate; // Set the text
InstallIconTxt.Text = isAvailable ? "\uF152" : "\uF191"; // Set text
InstallMsgTxt.Text = isAvailable ? Properties.Resources.Install : Properties.Resources.CheckUpdate; // Set text

LangApplyBtn.Visibility = Visibility.Hidden; // Hide
ThemeApplyBtn.Visibility = Visibility.Hidden; // Hide
TestSiteApplyBtn.Visibility = Visibility.Hidden; // Hide
MapProviderApplyBtn.Visibility = Visibility.Hidden; // Hide
// Update the UpdateStatusTxt
if (await NetworkConnection.IsAvailableAsync())
{
isAvailable = Update.IsAvailable(Global.Version, await Update.GetLastVersionAsync(Global.LastVersionLink));

UpdateStatusTxt.Text = isAvailable ? Properties.Resources.AvailableUpdates : Properties.Resources.UpToDate; // Set the text
InstallIconTxt.Text = isAvailable ? "\uF152" : "\uF191"; // Set text
InstallMsgTxt.Text = isAvailable ? Properties.Resources.Install : Properties.Resources.CheckUpdate; // Set text

LangApplyBtn.Visibility = Visibility.Hidden; // Hide
ThemeApplyBtn.Visibility = Visibility.Hidden; // Hide
TestSiteApplyBtn.Visibility = Visibility.Hidden; // Hide
MapProviderApplyBtn.Visibility = Visibility.Hidden; // Hide
}
else
{
UpdateStatusTxt.Text = Properties.Resources.UnableToCheckUpdates; // Set text
InstallMsgTxt.Text = Properties.Resources.CheckUpdate; // Set text
InstallIconTxt.Text = "\uF191"; // Set text
}
}
catch (Exception ex)
{
Expand All @@ -120,12 +129,21 @@ private async void RefreshInstallBtn_Click(object sender, RoutedEventArgs e)
}
else
{
// Update the UpdateStatusTxt
isAvailable = Update.IsAvailable(Global.Version, await Update.GetLastVersionAsync(Global.LastVersionLink));

UpdateStatusTxt.Text = isAvailable ? Properties.Resources.AvailableUpdates : Properties.Resources.UpToDate; // Set the text
InstallIconTxt.Text = isAvailable ? "\uF152" : "\uF191"; // Set text
InstallMsgTxt.Text = isAvailable ? Properties.Resources.Install : Properties.Resources.CheckUpdate; // Set text
if (await NetworkConnection.IsAvailableAsync())
{
// Update the UpdateStatusTxt
isAvailable = Update.IsAvailable(Global.Version, await Update.GetLastVersionAsync(Global.LastVersionLink));

UpdateStatusTxt.Text = isAvailable ? Properties.Resources.AvailableUpdates : Properties.Resources.UpToDate; // Set the text
InstallIconTxt.Text = isAvailable ? "\uF152" : "\uF191"; // Set text
InstallMsgTxt.Text = isAvailable ? Properties.Resources.Install : Properties.Resources.CheckUpdate; // Set text
}
else
{
UpdateStatusTxt.Text = Properties.Resources.UnableToCheckUpdates; // Set text
InstallMsgTxt.Text = Properties.Resources.CheckUpdate; // Set text
InstallIconTxt.Text = "\uF191"; // Set text
}
}
}

Expand Down

0 comments on commit 42cf21c

Please sign in to comment.