Skip to content

Commit

Permalink
Added the possibility to show the IP on a map (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Aug 14, 2022
1 parent eb78dde commit 53a9b81
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions InternetTest/InternetTest/Pages/MyIpPage.xaml
Expand Up @@ -28,6 +28,7 @@
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button x:Name="GetMyIPBtn" Click="GetMyIPBtn_Click" Cursor="Hand" Content="{x:Static lang:Resources.MyIP}" Margin="5 10" Padding="5 2" BorderThickness="0" Background="{Binding Source={StaticResource AccentColor}}" Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}" FontWeight="ExtraBold" Style="{DynamicResource PrimaryButton}"/>
<Button x:Name="MapBtn" Click="MapBtn_Click" Cursor="Hand" Content="{x:Static lang:Resources.ShowOnMap}" Margin="5 10" Padding="5 2" BorderThickness="0" Background="{Binding Source={StaticResource LightAccentColor}}" Foreground="{Binding Source={StaticResource AccentColor}}" FontWeight="ExtraBold" Style="{DynamicResource PrimaryButton}"/>
<Button x:Name="CopyBtn" Click="CopyBtn_Click" Cursor="Hand" Content="&#xF32C;" Margin="5 10" Padding="5 2" BorderThickness="0" Background="{Binding Source={StaticResource LightAccentColor}}" Foreground="{Binding Source={StaticResource AccentColor}}" FontFamily="../Fonts/#FluentSystemIcons-Regular" FontWeight="ExtraBold" Style="{DynamicResource PrimaryButton}"/>
</StackPanel>
</StackPanel>

Expand Down
21 changes: 17 additions & 4 deletions InternetTest/InternetTest/Pages/MyIpPage.xaml.cs
Expand Up @@ -24,6 +24,7 @@ MIT License
using InternetTest.Classes;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -54,7 +55,7 @@ private void InitUI()
GetMyIP(); // Locate the current IP
TitleTxt.Text = $"{Properties.Resources.IPTools} > {Properties.Resources.MyIP}";
}

private void GetMyIPBtn_Click(object sender, RoutedEventArgs e)
{
GetMyIP();
Expand All @@ -65,7 +66,7 @@ internal async void GetMyIP()
StatusIconTxt.Text = "\uF4AB";
StatusIconTxt.Foreground = new SolidColorBrush(Global.GetColorFromResource("Gray"));
MyIPTxt.Text = Properties.Resources.IPShowHere;

var ipInfo = await Global.GetIPInfoAsync(""); // Giving an empty IP returns the user's current IP
if (ipInfo is not null)
{
Expand All @@ -74,8 +75,8 @@ internal async void GetMyIP()
RegionTxt.Text = ipInfo.RegionName;
CityTxt.Text = ipInfo.City;
ZipCodeTxt.Text = ipInfo.Zip;
LatTxt.Text = ipInfo.Lat.ToString();
LongitudeTxt.Text = ipInfo.Lon.ToString();
LatTxt.Text = ipInfo.Lat.ToString().Replace(",", ".");
LongitudeTxt.Text = ipInfo.Lon.ToString().Replace(",", ".");
TimezoneTxt.Text = ipInfo.Timezone;
IspTxt.Text = ipInfo.Isp;

Expand All @@ -91,6 +92,18 @@ internal async void GetMyIP()

private void MapBtn_Click(object sender, RoutedEventArgs e)
{
//TODO: Add different map providers
var lat = LatTxt.Text;
var lon = LongitudeTxt.Text;
Process.Start("explorer.exe", $"\"https://www.openstreetmap.org/directions?engine=graphhopper_foot&route={lat}%2C{lon}%3B{lat}%2C{lon}#map=12/{lat}/{lon}\"");
}

private void CopyBtn_Click(object sender, RoutedEventArgs e)
{
try
{
Clipboard.SetDataObject(MyIPTxt.Text); // Copy to clipboard
}
catch { }
}
}

0 comments on commit 53a9b81

Please sign in to comment.