Skip to content

Commit

Permalink
Added Quick Information in header section (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Nov 30, 2024
1 parent 1a9119a commit 0bdb10f
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 293 deletions.
210 changes: 197 additions & 13 deletions InternetTest/InternetTest/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -257,20 +257,204 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="1" Grid.ColumnSpan="3">
<TextBlock
Grid.Column="1"
Margin="0 10 0 0"
FontSize="36"
FontWeight="ExtraBold"
Text="{x:Static lang:Resources.InternetTest}" />
<TextBlock
x:Name="HelloTxt"
<Grid Grid.Column="1" Grid.ColumnSpan="3">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock
Grid.Column="1"
Margin="0 10 0 0"
FontSize="36"
FontWeight="ExtraBold"
Text="{x:Static lang:Resources.InternetTest}" />
<TextBlock
x:Name="HelloTxt"
Grid.Column="1"
FontSize="16"
FontWeight="ExtraBold"
Text="{x:Static lang:Resources.InternetTest}" />
</StackPanel>
<StackPanel
Grid.Column="1"
FontSize="16"
FontWeight="ExtraBold"
Text="{x:Static lang:Resources.InternetTest}" />
</StackPanel>
VerticalAlignment="Center"
Orientation="Horizontal" Margin="0,0,10,0">
<Border
x:Name="StatusBorder"
Margin="0"
Padding="5 2"
CornerRadius="5"
MouseEnter="StatusBorder_MouseEnter"
MouseLeave="StatusBorder_MouseLeave">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock
x:Name="StatusIconTxt"
VerticalAlignment="Center"
FontFamily="/Fonts/#FluentSystemIcons-Filled"
FontSize="32"
Foreground="{DynamicResource Accent}"
Text="&#xF648;" />
<StackPanel
Grid.Column="1"
Margin="5 0 0 0"
VerticalAlignment="Center">
<TextBlock
VerticalAlignment="Center"
FontSize="14"
FontWeight="ExtraBold"
Text="{x:Static lang:Resources.Status}" />
<TextBlock
x:Name="StatusTxt"
FontSize="10"
FontWeight="SemiBold"
Text="{x:Static lang:Resources.Unknown}" />
</StackPanel>
<Button
x:Name="RefreshStatusBtn"
Grid.Column="2"
Margin="2 0"
Background="Transparent"
Click="RefreshStatusBtn_Click"
Content="&#xF191;"
FontFamily="/Fonts/#FluentSystemIcons-Regular"
Foreground="{DynamicResource Foreground1}"
Style="{DynamicResource ToolButton}"
Visibility="Hidden" />
</Grid>
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource CardBackground}" />
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
<Border
x:Name="NetworkBorder"
Margin="0"
Padding="5 2"
CornerRadius="5"
MouseEnter="NetworkBorder_MouseEnter"
MouseLeave="NetworkBorder_MouseLeave">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock
x:Name="NetworkIconTxt"
VerticalAlignment="Center"
FontFamily="/Fonts/#FluentSystemIcons-Filled"
FontSize="32"
Foreground="{DynamicResource Accent}"
Text="&#xF8C5;" />
<StackPanel
Grid.Column="1"
Margin="5 0 0 0"
VerticalAlignment="Center">
<TextBlock
x:Name="NetworkTitleTxt"
VerticalAlignment="Center"
FontSize="14"
FontWeight="ExtraBold"
Text="{x:Static lang:Resources.Network}" />
<TextBlock
x:Name="NetworkTxt"
FontSize="10"
FontWeight="SemiBold"
Text="{x:Static lang:Resources.ConnectedS}" />
</StackPanel>
<Button
x:Name="RefreshNetworkBtn"
Grid.Column="2"
Margin="2 0"
Background="Transparent"
Click="RefreshNetworkBtn_Click"
Content="&#xF191;"
FontFamily="/Fonts/#FluentSystemIcons-Regular"
Foreground="{DynamicResource Foreground1}"
Style="{DynamicResource ToolButton}"
Visibility="Hidden" />
</Grid>
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource CardBackground}" />
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
<Border
x:Name="MyIpBorder"
MinWidth="180"
Margin="0"
Padding="5 2"
CornerRadius="5"
MouseEnter="MyIpBorder_MouseEnter"
MouseLeave="MyIpBorder_MouseLeave">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock
x:Name="MyIpIconTxt"
VerticalAlignment="Center"
FontFamily="/Fonts/#FluentSystemIcons-Filled"
FontSize="32"
Foreground="{DynamicResource Accent}"
Text="&#xF3DA;" />
<StackPanel
Grid.Column="1"
Margin="5 0 0 0"
VerticalAlignment="Center">
<TextBlock
VerticalAlignment="Center"
FontSize="14"
FontWeight="ExtraBold"
Text="{x:Static lang:Resources.MyIP}" />
<TextBlock
x:Name="MyIpTxt"
FontSize="10"
FontWeight="SemiBold"
Text="{x:Static lang:Resources.HoverToReveal}" />
</StackPanel>
<Button
x:Name="RefreshMyIpBtn"
Grid.Column="2"
Margin="2 0"
Background="Transparent"
Click="RefreshMyIpBtn_Click"
Content="&#xF191;"
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
Foreground="{DynamicResource Foreground1}"
Style="{DynamicResource ToolButton}"
Visibility="Hidden" />
</Grid>
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource CardBackground}" />
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
</StackPanel>
</Grid>
<StackPanel
x:Name="SideBar"
Grid.Row="1"
Expand Down
90 changes: 89 additions & 1 deletion InternetTest/InternetTest/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using InternetTest.Enums;
using InternetTest.Pages;
using InternetTest.UserControls;
using PeyrSharp.Core;
using PeyrSharp.Env;
using System;
using System.Windows;
Expand Down Expand Up @@ -58,7 +59,7 @@ public MainWindow()
Duration = new Duration(TimeSpan.FromSeconds(0.2)),
};

private void InitUI()
private async void InitUI()
{
#if PORTABLE
VersionTxt.Text = Global.Version + " (Portable)";
Expand Down Expand Up @@ -154,6 +155,15 @@ private void InitUI()
Width = Global.Settings.MainWindowSize?.Item1 ?? 950;
Height = Global.Settings.MainWindowSize?.Item2 ?? 600;
}

// Load "Status" section
if (Global.Settings.TestOnStart) LoadStatusCard();

// Load "Network" section
LoadNetworkCard();

// Load "My IP" section
ip = (await Global.GetIPInfoAsync(""))?.Query ?? "";
}

private void PageCard_OnCardClick(object? sender, PageEventArgs e)
Expand Down Expand Up @@ -476,4 +486,82 @@ private void RequestsPageBtn_Click(object sender, RoutedEventArgs e)
PageDisplayer.Content = Global.RequestsPage; // Display the IP config page
Global.SynethiaConfig.PagesInfo[8].EnterUnixTime = Sys.UnixTime; // Update the last entered time
}

private void StatusBorder_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
RefreshStatusBtn.Visibility = Visibility.Visible;
}

private void StatusBorder_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
RefreshStatusBtn.Visibility = Visibility.Hidden;
}

private void NetworkBorder_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
RefreshNetworkBtn.Visibility = Visibility.Visible;
}

private void NetworkBorder_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
RefreshNetworkBtn.Visibility = Visibility.Hidden;
}


private void RefreshStatusBtn_Click(object sender, RoutedEventArgs e)
{
StatusTxt.Text = Properties.Resources.Checking;
LoadStatusCard();
}

bool connected = true;
internal async void LoadStatusCard()
{
connected = await Internet.IsAvailableAsync(Global.Settings.TestSite); // Check if Internet is available
StatusTxt.Text = connected ? Properties.Resources.ConnectedS : Properties.Resources.NotConnectedS; // Set text
StatusIconTxt.Text = connected ? "\uF299" : "\uF36E";
StatusIconTxt.Foreground = connected ? Global.GetBrushFromResource("Green") : Global.GetBrushFromResource("Red");
}

internal void LoadNetworkCard()
{
try
{
string ssid = Global.GetCurrentWifiSSID();

NetworkTxt.Text = (ssid == null || !connected) ? Properties.Resources.NotConnectedS : ssid;
NetworkTitleTxt.Text = Properties.Resources.WiFi;
NetworkIconTxt.Text = (ssid == null || !connected) ? "\uFC27" : "\uF8C5";

}
catch // If there is no WiFi
{
NetworkIconTxt.Text = connected ? "\uF35A" : "\uFC27";
NetworkTxt.Text = connected ? Properties.Resources.Ethernet : Properties.Resources.NotConnectedS;
NetworkTitleTxt.Text = Properties.Resources.Network;
}
}

private void RefreshNetworkBtn_Click(object sender, RoutedEventArgs e)
{
LoadNetworkCard();
}

string ip = "";
private async void RefreshMyIpBtn_Click(object sender, RoutedEventArgs e)
{
ip = (await Global.GetIPInfoAsync(""))?.Query ?? "";
}

private void MyIpBorder_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
MyIpTxt.Text = ip;
RefreshMyIpBtn.Visibility = Visibility.Visible;
}

private void MyIpBorder_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
MyIpTxt.Text = Properties.Resources.HoverToReveal;
RefreshMyIpBtn.Visibility = Visibility.Hidden;
}
}
Loading

0 comments on commit 0bdb10f

Please sign in to comment.