Skip to content

Commit b2242d9

Browse files
committed
Fix: Refactor network connection & other dashboards
1 parent 66d6ff7 commit b2242d9

16 files changed

+82
-151
lines changed

Source/NETworkManager.Models/Generated Files/CsWinRT/WinRTEventHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
3-
// This file was generated by cswinrt.exe version 2.0.8.240703.1
3+
// This file was generated by cswinrt.exe version 2.1.3.240909.1
44
//
55
// Changes to this file may cause incorrect behavior and will be lost if
66
// the code is regenerated.

Source/NETworkManager.Settings/GlobalStaticConfiguration.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.IO;
3-
using System.Linq;
4-
using DnsClient;
1+
using DnsClient;
52
using Lextm.SharpSnmpLib.Messaging;
63
using NETworkManager.Models;
74
using NETworkManager.Models.Export;
@@ -10,6 +7,9 @@
107
using NETworkManager.Models.PuTTY;
118
using NETworkManager.Models.RemoteDesktop;
129
using NETworkManager.Utilities;
10+
using System;
11+
using System.IO;
12+
using System.Linq;
1313

1414
// ReSharper disable InconsistentNaming
1515

@@ -22,8 +22,8 @@ public static class GlobalStaticConfiguration
2222
// Type to search (average type speed --> 187 chars/min)
2323
public static TimeSpan SearchDispatcherTimerTimeSpan => new(0, 0, 0, 0, 750);
2424

25-
// Status window delay in ms
26-
public static int StatusWindowDelayBeforeOpen => 5000;
25+
// Network config
26+
public static int NetworkChangeDetectionDelay => 5000;
2727

2828
// Profile config
2929
public static bool Profile_ExpandProfileView => true;

Source/NETworkManager/Generated Files/CsWinRT/WinRTEventHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
3-
// This file was generated by cswinrt.exe version 2.0.8.240703.1
3+
// This file was generated by cswinrt.exe version 2.1.3.240909.1
44
//
55
// Changes to this file may cause incorrect behavior and will be lost if
66
// the code is regenerated.

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
using System;
1+
using log4net;
2+
using MahApps.Metro.Controls.Dialogs;
3+
using NETworkManager.Controls;
4+
using NETworkManager.Documentation;
5+
using NETworkManager.Localization;
6+
using NETworkManager.Localization.Resources;
7+
using NETworkManager.Models;
8+
using NETworkManager.Models.AWS;
9+
using NETworkManager.Models.EventSystem;
10+
using NETworkManager.Models.Network;
11+
using NETworkManager.Models.PowerShell;
12+
using NETworkManager.Models.PuTTY;
13+
using NETworkManager.Profiles;
14+
using NETworkManager.Settings;
15+
using NETworkManager.Update;
16+
using NETworkManager.Utilities;
17+
using NETworkManager.ViewModels;
18+
using NETworkManager.Views;
19+
using System;
220
using System.Collections.Generic;
321
using System.Collections.ObjectModel;
422
using System.ComponentModel;
@@ -19,24 +37,6 @@
1937
using System.Windows.Interop;
2038
using System.Windows.Markup;
2139
using System.Windows.Threading;
22-
using log4net;
23-
using MahApps.Metro.Controls.Dialogs;
24-
using NETworkManager.Controls;
25-
using NETworkManager.Documentation;
26-
using NETworkManager.Localization;
27-
using NETworkManager.Localization.Resources;
28-
using NETworkManager.Models;
29-
using NETworkManager.Models.AWS;
30-
using NETworkManager.Models.EventSystem;
31-
using NETworkManager.Models.Network;
32-
using NETworkManager.Models.PowerShell;
33-
using NETworkManager.Models.PuTTY;
34-
using NETworkManager.Profiles;
35-
using NETworkManager.Settings;
36-
using NETworkManager.Update;
37-
using NETworkManager.Utilities;
38-
using NETworkManager.ViewModels;
39-
using NETworkManager.Views;
4040
using Application = System.Windows.Application;
4141
using ContextMenu = System.Windows.Controls.ContextMenu;
4242
using MouseEventArgs = System.Windows.Forms.MouseEventArgs;
@@ -701,7 +701,7 @@ private void LoadApplicationList()
701701
// Select the application
702702
// Set application via command line, or select the default one, fallback to the first visible one
703703
var applicationList = Applications.Cast<ApplicationInfo>().ToArray();
704-
704+
705705
if (CommandLineManager.Current.Application != ApplicationName.None)
706706
SelectedApplication = applicationList.FirstOrDefault(x => x.Name == CommandLineManager.Current.Application);
707707
else
@@ -1952,7 +1952,7 @@ private async void OnNetworkHasChanged()
19521952
_isNetworkChanging = true;
19531953

19541954
// Wait, because the event may be triggered several times.
1955-
await Task.Delay(GlobalStaticConfiguration.StatusWindowDelayBeforeOpen);
1955+
await Task.Delay(GlobalStaticConfiguration.NetworkChangeDetectionDelay);
19561956

19571957
Log.Info("Network availability or address has changed!");
19581958

@@ -1962,7 +1962,10 @@ private async void OnNetworkHasChanged()
19621962

19631963
// Show status window on network change
19641964
if (SettingsManager.Current.Status_ShowWindowOnNetworkChange)
1965-
await Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate { OpenStatusWindow(true); }));
1965+
await Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate
1966+
{
1967+
OpenStatusWindow(true);
1968+
}));
19661969

19671970
_isNetworkChanging = false;
19681971
}

Source/NETworkManager/StatusWindow.xaml.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Windows.Forms;
55
using System.Windows.Input;
66
using System.Windows.Threading;
7+
using log4net;
78
using NETworkManager.Settings;
89
using NETworkManager.Utilities;
910
using NETworkManager.Views;
@@ -42,7 +43,7 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null)
4243
#endregion
4344

4445
#region Variables
45-
46+
4647
// Set priority to make the ui smoother
4748
private readonly DispatcherTimer _dispatcherTimerClose = new(DispatcherPriority.Normal);
4849

@@ -102,7 +103,7 @@ public int Time
102103

103104
private void ReloadAction()
104105
{
105-
Reload();
106+
Check();
106107
}
107108

108109
public ICommand ShowMainWindowCommand => new RelayCommand(_ => ShowMainWindowAction());
@@ -126,9 +127,9 @@ private void CloseAction()
126127

127128
#region Methods
128129

129-
private void Reload()
130+
private void Check()
130131
{
131-
_networkConnectionView.Reload();
132+
_networkConnectionView.Check();
132133
}
133134

134135
/// <summary>
@@ -137,19 +138,28 @@ private void Reload()
137138
/// <param name="enableCloseTimer">Automatically close the window after a certain time.</param>
138139
public void ShowWindow(bool enableCloseTimer = false)
139140
{
140-
// Show on primary screen in left/bottom corner
141+
// Set window position on primary screen
141142
// ToDo: User setting...
142-
Left = Screen.PrimaryScreen.WorkingArea.Right - Width - 10;
143-
Top = Screen.PrimaryScreen.WorkingArea.Bottom - Height - 10;
143+
if (Screen.PrimaryScreen != null)
144+
{
145+
Left = Screen.PrimaryScreen.WorkingArea.Right - Width - 10;
146+
Top = Screen.PrimaryScreen.WorkingArea.Bottom - Height - 10;
147+
}
144148

149+
// Show the window
145150
Show();
146-
151+
152+
// Check the network connection
153+
Check();
154+
155+
// Close the window after a certain time
147156
if (enableCloseTimer)
148157
{
149158
SetupCloseTimer();
150159
return;
151160
}
152161

162+
// Focus the window
153163
Activate();
154164
}
155165

Source/NETworkManager/ViewModels/DashboardViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ public DashboardViewModel()
99

1010
private void LoadSettings()
1111
{
12+
1213
}
1314

1415
public void OnViewVisible()
1516
{
17+
1618
}
1719

1820
public void OnViewHide()
1921
{
22+
2023
}
2124
}

Source/NETworkManager/ViewModels/IPApiDNSResolverWidgetViewModel.cs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.ComponentModel;
2-
using System.Net.NetworkInformation;
3-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
42
using System.Windows.Input;
53
using NETworkManager.Models.IPApi;
64
using NETworkManager.Settings;
@@ -10,23 +8,6 @@ namespace NETworkManager.ViewModels;
108

119
public class IPApiDNSResolverWidgetViewModel : ViewModelBase
1210
{
13-
#region Events
14-
15-
private void SettingsManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
16-
{
17-
switch (e.PropertyName)
18-
{
19-
case nameof(SettingsInfo.Dashboard_CheckIPApiDNSResolver):
20-
// Check if enabled via settings
21-
if (SettingsManager.Current.Dashboard_CheckIPApiDNSResolver)
22-
Check();
23-
24-
break;
25-
}
26-
}
27-
28-
#endregion
29-
3011
#region Variables
3112

3213
private bool _isRunning;
@@ -65,18 +46,12 @@ private set
6546

6647
public IPApiDNSResolverWidgetViewModel()
6748
{
68-
// Detect if network address or status changed...
69-
NetworkChange.NetworkAvailabilityChanged += (_, _) => Check();
70-
NetworkChange.NetworkAddressChanged += (_, _) => Check();
71-
7249
LoadSettings();
73-
74-
// Detect if settings have changed...
75-
SettingsManager.Current.PropertyChanged += SettingsManager_PropertyChanged;
7650
}
7751

7852
private void LoadSettings()
7953
{
54+
8055
}
8156

8257
#endregion

Source/NETworkManager/ViewModels/IPApiIPGeolocationWidgetViewModel.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.ComponentModel;
2-
using System.Net.NetworkInformation;
3-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
42
using System.Windows.Input;
53
using log4net;
64
using NETworkManager.Models.IPApi;
@@ -11,23 +9,6 @@ namespace NETworkManager.ViewModels;
119

1210
public class IPApiIPGeolocationWidgetViewModel : ViewModelBase
1311
{
14-
#region Events
15-
16-
private void SettingsManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
17-
{
18-
switch (e.PropertyName)
19-
{
20-
case nameof(SettingsInfo.Dashboard_CheckIPApiIPGeolocation):
21-
// Check if enabled via settings
22-
if (SettingsManager.Current.Dashboard_CheckIPApiIPGeolocation)
23-
Check();
24-
25-
break;
26-
}
27-
}
28-
29-
#endregion
30-
3112
#region Variables
3213

3314
private static readonly ILog Log = LogManager.GetLogger(typeof(IPApiIPGeolocationWidgetViewModel));
@@ -68,14 +49,7 @@ private set
6849

6950
public IPApiIPGeolocationWidgetViewModel()
7051
{
71-
// Detect if network address or status changed...
72-
NetworkChange.NetworkAvailabilityChanged += (_, _) => Check();
73-
NetworkChange.NetworkAddressChanged += (_, _) => Check();
74-
7552
LoadSettings();
76-
77-
// Detect if settings have changed...
78-
SettingsManager.Current.PropertyChanged += SettingsManager_PropertyChanged;
7953
}
8054

8155
private void LoadSettings()

0 commit comments

Comments
 (0)