Skip to content

Commit b126fab

Browse files
committed
Tray status window added
1 parent 03f31f9 commit b126fab

7 files changed

Lines changed: 140 additions & 2 deletions

File tree

Source/NETworkManager/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public partial class App
2121

2222
public App()
2323
{
24-
ShutdownMode = ShutdownMode.OnLastWindowClose;
24+
ShutdownMode = ShutdownMode.OnMainWindowClose;
2525
}
2626

2727
private void Application_Startup(object sender, StartupEventArgs e)

Source/NETworkManager/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<mahAppsControls:MetroWindow x:Name="MetroWindowMain" x:Class="NETworkManager.MainWindow"
1+
<mahAppsControls:MetroWindow x:Name="MetroMainWindow" x:Class="NETworkManager.MainWindow"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

Source/NETworkManager/NETworkManager.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@
309309
<Compile Include="GlobalStaticConfiguration.cs" />
310310
<Compile Include="ProfileViewInfo.cs" />
311311
<Compile Include="ProfileViewManager.cs" />
312+
<Compile Include="StatusWindow.xaml.cs">
313+
<DependentUpon>StatusWindow.xaml</DependentUpon>
314+
</Compile>
312315
<Compile Include="Utilities\CommonMethods.cs" />
313316
<Compile Include="Utilities\ArrayHelper.cs" />
314317
<Compile Include="Utilities\AutoRefreshTime.cs" />
@@ -751,6 +754,10 @@
751754
<SubType>Designer</SubType>
752755
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
753756
</Content>
757+
<Page Include="StatusWindow.xaml">
758+
<SubType>Designer</SubType>
759+
<Generator>MSBuild:Compile</Generator>
760+
</Page>
754761
<Page Include="Views\FirstRunDialog.xaml">
755762
<Generator>MSBuild:Compile</Generator>
756763
<SubType>Designer</SubType>

Source/NETworkManager/Resources/Localization/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/NETworkManager/Resources/Localization/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,4 +2271,7 @@ is disabled!</value>
22712271
<data name="HelpMessage_PublicICMPTestIPAddress" xml:space="preserve">
22722272
<value>IP address to test connection via ping (ICMP).</value>
22732273
</data>
2274+
<data name="Gateway" xml:space="preserve">
2275+
<value>Gateway</value>
2276+
</data>
22742277
</root>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<mahAppsControls:MetroWindow x:Class="NETworkManager.StatusWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:mahAppsControls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
7+
xmlns:localization="clr-namespace:NETworkManager.Resources.Localization"
8+
xmlns:networkManager="clr-namespace:NETworkManager"
9+
xmlns:converters="clr-namespace:NETworkManager.Converters"
10+
mc:Ignorable="d" d:DataContext="{d:DesignInstance networkManager:StatusWindow}"
11+
Title="{x:Static localization:StaticStrings.ProductName}" Height="350" Width="250" IsWindowDraggable="False" GotKeyboardFocus="MetroWindow_GotKeyboardFocus" LostKeyboardFocus="MetroWindow_LostKeyboardFocus" Style="{StaticResource DefaultWindow}" ShowMinButton="False" ShowMaxRestoreButton="False" ShowCloseButton="False">
12+
<mahAppsControls:MetroWindow.Resources>
13+
<converters:Bytes1000ToSpeedConverter x:Key="Bytes1000ToSpeedConverter" />
14+
<converters:IPAddressArrayToStringConverter x:Key="IPAddressArrayToStringConverter" />
15+
</mahAppsControls:MetroWindow.Resources>
16+
<Grid Margin="10">
17+
<StackPanel>
18+
<TextBlock Text="{x:Static localization:Strings.Network}" Style="{StaticResource HeaderTextBlock}" />
19+
<Grid>
20+
<Grid.Resources>
21+
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CenterTextBlock}" />
22+
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextBlockAsTextBox}">
23+
<Setter Property="ContextMenu" Value="{StaticResource CopyContextMenu}" />
24+
<Setter Property="TextWrapping" Value="NoWrap" />
25+
</Style>
26+
</Grid.Resources>
27+
<Grid.ColumnDefinitions>
28+
<ColumnDefinition Width="Auto" />
29+
<ColumnDefinition Width="10" />
30+
<ColumnDefinition Width="*" />
31+
</Grid.ColumnDefinitions>
32+
<Grid.RowDefinitions>
33+
<RowDefinition Height="Auto" />
34+
<RowDefinition Height="Auto" />
35+
<RowDefinition Height="Auto" />
36+
<RowDefinition Height="Auto" />
37+
</Grid.RowDefinitions>
38+
<TextBlock Grid.Column="0" Grid.Row="0" Text="{x:Static localization:Strings.IPAddress}" />
39+
<TextBox Grid.Column="2" Grid.Row="0" Text="{Binding NetworkInterfaceInfo.IPv4Address, Converter={StaticResource IPAddressArrayToStringConverter}}" />
40+
<TextBlock Grid.Column="0" Grid.Row="1" Text="{x:Static localization:Strings.Subnetmask}" />
41+
<TextBox Grid.Column="2" Grid.Row="1" Text="{Binding NetworkInterfaceInfo.Subnetmask, Converter={StaticResource IPAddressArrayToStringConverter}}" />
42+
<TextBlock Grid.Column="0" Grid.Row="2" Text="{x:Static localization:Strings.Gateway}" />
43+
<TextBox Grid.Column="2" Grid.Row="2" Text="{Binding NetworkInterfaceInfo.IPv4Gateway, Converter={StaticResource IPAddressArrayToStringConverter}}" />
44+
<TextBlock Grid.Column="0" Grid.Row="3" Text="{x:Static localization:Strings.Speed}" />
45+
<TextBox Grid.Column="2" Grid.Row="3" Text="{Binding NetworkInterfaceInfo.Speed, Converter={StaticResource Bytes1000ToSpeedConverter}}" />
46+
</Grid>
47+
</StackPanel>
48+
</Grid>
49+
</mahAppsControls:MetroWindow>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using MahApps.Metro.Controls;
2+
using NETworkManager.Models.Network;
3+
using System.ComponentModel;
4+
using System.Diagnostics;
5+
using System.Linq;
6+
using System.Net;
7+
using System.Runtime.CompilerServices;
8+
using System.Windows.Input;
9+
10+
namespace NETworkManager
11+
{
12+
public partial class StatusWindow : MetroWindow, INotifyPropertyChanged
13+
{
14+
#region PropertyChangedEventHandler
15+
public event PropertyChangedEventHandler PropertyChanged;
16+
17+
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
18+
{
19+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
20+
}
21+
#endregion
22+
23+
private NetworkInterfaceInfo _networkInterfaceInfo;
24+
public NetworkInterfaceInfo NetworkInterfaceInfo
25+
{
26+
get => _networkInterfaceInfo;
27+
set
28+
{
29+
if (value == _networkInterfaceInfo)
30+
return;
31+
32+
_networkInterfaceInfo = value;
33+
OnPropertyChanged();
34+
}
35+
}
36+
37+
public StatusWindow()
38+
{
39+
InitializeComponent();
40+
41+
DataContext = this;
42+
}
43+
44+
private void MetroWindow_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
45+
{
46+
Hide();
47+
}
48+
49+
private void MetroWindow_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
50+
{
51+
UpdateView();
52+
}
53+
54+
private void UpdateView()
55+
{
56+
RefreshNetwork();
57+
}
58+
59+
private async void RefreshNetwork()
60+
{
61+
var detectedIP = await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync(System.Net.IPAddress.Parse("1.1.1.1"));
62+
63+
foreach (NetworkInterfaceInfo info in await NetworkInterface.GetNetworkInterfacesAsync())
64+
{
65+
if (info.IPv4Address.Contains(detectedIP))
66+
NetworkInterfaceInfo = info;
67+
}
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)