Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Refactor network connection & other dashboards #2846

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This file was generated by cswinrt.exe version 2.0.8.240703.1
// This file was generated by cswinrt.exe version 2.1.3.240909.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down
12 changes: 6 additions & 6 deletions Source/NETworkManager.Settings/GlobalStaticConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.IO;
using System.Linq;
using DnsClient;
using DnsClient;
using Lextm.SharpSnmpLib.Messaging;
using NETworkManager.Models;
using NETworkManager.Models.Export;
Expand All @@ -10,6 +7,9 @@
using NETworkManager.Models.PuTTY;
using NETworkManager.Models.RemoteDesktop;
using NETworkManager.Utilities;
using System;
using System.IO;
using System.Linq;

// ReSharper disable InconsistentNaming

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

// Status window delay in ms
public static int StatusWindowDelayBeforeOpen => 5000;
// Network config
public static int NetworkChangeDetectionDelay => 5000;

// Profile config
public static bool Profile_ExpandProfileView => true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This file was generated by cswinrt.exe version 2.0.8.240703.1
// This file was generated by cswinrt.exe version 2.1.3.240909.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
<mah:FlyoutsControl>
<mah:Flyout IsKeyboardFocusWithinChanged="FlyoutRunCommand_IsKeyboardFocusWithinChanged"
IsOpen="{Binding FlyoutRunCommandIsOpen, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
AreAnimationsEnabled="{Binding FlyoutRunCommandAreAnimationsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
AreAnimationsEnabled="False"
Visibility="{Binding FlyoutRunCommandIsOpen, Converter={StaticResource BooleanToVisibilityConverter}}"
Position="Top"
TitleVisibility="Collapsed"
Expand Down
72 changes: 26 additions & 46 deletions Source/NETworkManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
using System;
using log4net;
using MahApps.Metro.Controls.Dialogs;
using NETworkManager.Controls;
using NETworkManager.Documentation;
using NETworkManager.Localization;
using NETworkManager.Localization.Resources;
using NETworkManager.Models;
using NETworkManager.Models.AWS;
using NETworkManager.Models.EventSystem;
using NETworkManager.Models.Network;
using NETworkManager.Models.PowerShell;
using NETworkManager.Models.PuTTY;
using NETworkManager.Profiles;
using NETworkManager.Settings;
using NETworkManager.Update;
using NETworkManager.Utilities;
using NETworkManager.ViewModels;
using NETworkManager.Views;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
Expand All @@ -19,24 +37,6 @@
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Threading;
using log4net;
using MahApps.Metro.Controls.Dialogs;
using NETworkManager.Controls;
using NETworkManager.Documentation;
using NETworkManager.Localization;
using NETworkManager.Localization.Resources;
using NETworkManager.Models;
using NETworkManager.Models.AWS;
using NETworkManager.Models.EventSystem;
using NETworkManager.Models.Network;
using NETworkManager.Models.PowerShell;
using NETworkManager.Models.PuTTY;
using NETworkManager.Profiles;
using NETworkManager.Settings;
using NETworkManager.Update;
using NETworkManager.Utilities;
using NETworkManager.ViewModels;
using NETworkManager.Views;
using Application = System.Windows.Application;
using ContextMenu = System.Windows.Controls.ContextMenu;
using MouseEventArgs = System.Windows.Forms.MouseEventArgs;
Expand Down Expand Up @@ -329,21 +329,6 @@ public bool FlyoutRunCommandIsOpen
}
}

private bool _flyoutRunCommandAreAnimationsEnabled;

public bool FlyoutRunCommandAreAnimationsEnabled
{
get => _flyoutRunCommandAreAnimationsEnabled;
set
{
if (value == _flyoutRunCommandAreAnimationsEnabled)
return;

_flyoutRunCommandAreAnimationsEnabled = value;
OnPropertyChanged();
}
}

private bool _isRestartRequired;

public bool IsRestartRequired
Expand Down Expand Up @@ -701,7 +686,7 @@ private void LoadApplicationList()
// Select the application
// Set application via command line, or select the default one, fallback to the first visible one
var applicationList = Applications.Cast<ApplicationInfo>().ToArray();

if (CommandLineManager.Current.Application != ApplicationName.None)
SelectedApplication = applicationList.FirstOrDefault(x => x.Name == CommandLineManager.Current.Application);
else
Expand Down Expand Up @@ -1244,7 +1229,6 @@ private void OpenRunAction()
{
ConfigurationManager.OnDialogOpen();

FlyoutRunCommandAreAnimationsEnabled = true;
FlyoutRunCommandIsOpen = true;
}

Expand All @@ -1259,7 +1243,7 @@ private void RunCommandDoAction()

private void RunCommandCloseAction()
{
RunCommandFlyoutClose().ConfigureAwait(false);
RunCommandFlyoutClose();
}

#endregion
Expand Down Expand Up @@ -1321,28 +1305,24 @@ private void RunCommandDo()
}

// Close the flyout
RunCommandFlyoutClose(true).ConfigureAwait(false);
RunCommandFlyoutClose(true);
}

/// <summary>
/// Close the run command flyout and clear the search.
/// </summary>
private async Task RunCommandFlyoutClose(bool clearSearch = false)
private void RunCommandFlyoutClose(bool clearSearch = false)
{
if (!FlyoutRunCommandIsOpen)
return;

FlyoutRunCommandAreAnimationsEnabled = false;

FlyoutRunCommandIsOpen = false;

ConfigurationManager.OnDialogClose();

// Clear the search
if (clearSearch)
{
await Task.Delay(500); // Wait for the animation to finish
RunCommandSearch = string.Empty;
}
}

#endregion
Expand All @@ -1360,7 +1340,7 @@ private void FlyoutRunCommand_IsKeyboardFocusWithinChanged(object sender, Depend
if (e.NewValue is not false)
return;

RunCommandFlyoutClose().ConfigureAwait(false);
RunCommandFlyoutClose();
}

#endregion
Expand Down Expand Up @@ -1946,7 +1926,7 @@ private async void OnNetworkHasChanged()
_isNetworkChanging = true;

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

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

Expand Down
26 changes: 18 additions & 8 deletions Source/NETworkManager/StatusWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Threading;
using log4net;
using NETworkManager.Settings;
using NETworkManager.Utilities;
using NETworkManager.Views;
Expand Down Expand Up @@ -42,7 +43,7 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null)
#endregion

#region Variables

// Set priority to make the ui smoother
private readonly DispatcherTimer _dispatcherTimerClose = new(DispatcherPriority.Normal);

Expand Down Expand Up @@ -102,7 +103,7 @@ public int Time

private void ReloadAction()
{
Reload();
Check();
}

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

#region Methods

private void Reload()
private void Check()
{
_networkConnectionView.Reload();
_networkConnectionView.Check();
}

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

// Show the window
Show();


// Check the network connection
Check();

// Close the window after a certain time
if (enableCloseTimer)
{
SetupCloseTimer();
return;
}

// Focus the window
Activate();
}

Expand Down
3 changes: 3 additions & 0 deletions Source/NETworkManager/ViewModels/DashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ public DashboardViewModel()

private void LoadSettings()
{

}

public void OnViewVisible()
{

}

public void OnViewHide()
{

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.ComponentModel;
using System.Net.NetworkInformation;
using System.Threading.Tasks;
using System.Threading.Tasks;
using System.Windows.Input;
using NETworkManager.Models.IPApi;
using NETworkManager.Settings;
Expand All @@ -10,23 +8,6 @@ namespace NETworkManager.ViewModels;

public class IPApiDNSResolverWidgetViewModel : ViewModelBase
{
#region Events

private void SettingsManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(SettingsInfo.Dashboard_CheckIPApiDNSResolver):
// Check if enabled via settings
if (SettingsManager.Current.Dashboard_CheckIPApiDNSResolver)
Check();

break;
}
}

#endregion

#region Variables

private bool _isRunning;
Expand Down Expand Up @@ -65,18 +46,12 @@ private set

public IPApiDNSResolverWidgetViewModel()
{
// Detect if network address or status changed...
NetworkChange.NetworkAvailabilityChanged += (_, _) => Check();
NetworkChange.NetworkAddressChanged += (_, _) => Check();

LoadSettings();

// Detect if settings have changed...
SettingsManager.Current.PropertyChanged += SettingsManager_PropertyChanged;
}

private void LoadSettings()
{

}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.ComponentModel;
using System.Net.NetworkInformation;
using System.Threading.Tasks;
using System.Threading.Tasks;
using System.Windows.Input;
using log4net;
using NETworkManager.Models.IPApi;
Expand All @@ -11,23 +9,6 @@ namespace NETworkManager.ViewModels;

public class IPApiIPGeolocationWidgetViewModel : ViewModelBase
{
#region Events

private void SettingsManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(SettingsInfo.Dashboard_CheckIPApiIPGeolocation):
// Check if enabled via settings
if (SettingsManager.Current.Dashboard_CheckIPApiIPGeolocation)
Check();

break;
}
}

#endregion

#region Variables

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

public IPApiIPGeolocationWidgetViewModel()
{
// Detect if network address or status changed...
NetworkChange.NetworkAvailabilityChanged += (_, _) => Check();
NetworkChange.NetworkAddressChanged += (_, _) => Check();

LoadSettings();

// Detect if settings have changed...
SettingsManager.Current.PropertyChanged += SettingsManager_PropertyChanged;
}

private void LoadSettings()
Expand Down
Loading