Skip to content

Commit 10f8aaa

Browse files
authored
Feature: Refresh button (#3447)
* Feature: Refresh button * Chore: Copilot feedback * Chore: Add tooltip * Chore: Add tooltips
1 parent 175665c commit 10f8aaa

19 files changed

Lines changed: 170 additions & 121 deletions

‎Source/NETworkManager/StatusWindow.xaml‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,7 @@
6060
</mah:WindowCommands>
6161
</mah:MetroWindow.LeftWindowCommands>
6262
<mah:MetroWindow.RightWindowCommands>
63-
<mah:WindowCommands ShowSeparators="False">
64-
<Button Command="{Binding Path=ReloadCommand}"
65-
ToolTip="{x:Static Member=localization:Strings.Reload}"
66-
Cursor="Hand"
67-
Focusable="False"
68-
Margin="0,0,5,0">
69-
<StackPanel Orientation="Horizontal">
70-
<Rectangle Width="16" Height="16"
71-
Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
72-
<Rectangle.OpacityMask>
73-
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=Refresh}" />
74-
</Rectangle.OpacityMask>
75-
</Rectangle>
76-
</StackPanel>
77-
</Button>
63+
<mah:WindowCommands ShowSeparators="False">
7864
<Button Command="{Binding Path=ShowMainWindowCommand}"
7965
ToolTip="{x:Static Member=localization:Strings.Show}"
8066
Cursor="Hand"

‎Source/NETworkManager/StatusWindow.xaml.cs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,6 @@ public double Time
9696

9797
#region ICommands & Actions
9898

99-
public ICommand ReloadCommand => new RelayCommand(_ => ReloadAction());
100-
101-
private void ReloadAction()
102-
{
103-
Check();
104-
}
105-
10699
public ICommand ShowMainWindowCommand => new RelayCommand(_ => ShowMainWindowAction());
107100

108101
private void ShowMainWindowAction()

‎Source/NETworkManager/ViewModels/IPApiDNSResolverWidgetViewModel.cs‎

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
22
using System.Windows.Input;
33
using NETworkManager.Models.IPApi;
44
using NETworkManager.Settings;
@@ -55,6 +55,7 @@ private set
5555
public IPApiDNSResolverWidgetViewModel()
5656
{
5757
LoadSettings();
58+
Check();
5859
}
5960

6061
/// <summary>
@@ -70,17 +71,9 @@ private void LoadSettings()
7071
#region ICommands & Actions
7172

7273
/// <summary>
73-
/// Gets the command to check via hotkey.
74+
/// Gets the command to check the DNS resolver.
7475
/// </summary>
75-
public ICommand CheckViaHotkeyCommand => new RelayCommand(_ => CheckViaHotkeyAction());
76-
77-
/// <summary>
78-
/// Action to check via hotkey.
79-
/// </summary>
80-
private void CheckViaHotkeyAction()
81-
{
82-
Check();
83-
}
76+
public ICommand CheckCommand => new RelayCommand(_ => Check(), _ => !IsRunning);
8477

8578
#endregion
8679

@@ -89,7 +82,7 @@ private void CheckViaHotkeyAction()
8982
/// <summary>
9083
/// Checks the DNS resolver.
9184
/// </summary>
92-
public void Check()
85+
private void Check()
9386
{
9487
_ = CheckAsync();
9588
}
@@ -103,14 +96,10 @@ private async Task CheckAsync()
10396
if (!SettingsManager.Current.Dashboard_CheckIPApiDNSResolver)
10497
return;
10598

106-
// Don't check multiple times if already running
107-
if (IsRunning)
108-
return;
109-
11099
IsRunning = true;
111100
Result = null;
112101

113-
// Make the user happy, let him see a reload animation (and he cannot spam the reload command)
102+
// Make the user happy, let him see a reload animation (and he cannot spam the reload command)
114103
await Task.Delay(GlobalStaticConfiguration.ApplicationUIRefreshInterval);
115104

116105
Result = await DNSResolverService.GetInstance().GetDNSResolverAsync();

‎Source/NETworkManager/ViewModels/IPApiIPGeolocationWidgetViewModel.cs‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ private set
5858
public IPApiIPGeolocationWidgetViewModel()
5959
{
6060
LoadSettings();
61+
Check();
6162
}
6263

6364
/// <summary>
@@ -72,17 +73,9 @@ private void LoadSettings()
7273
#region ICommands & Actions
7374

7475
/// <summary>
75-
/// Gets the command to check via hotkey.
76+
/// Gets the command to check the IP geolocation.
7677
/// </summary>
77-
public ICommand CheckViaHotkeyCommand => new RelayCommand(_ => CheckViaHotkeyAction());
78-
79-
/// <summary>
80-
/// Action to check via hotkey.
81-
/// </summary>
82-
private void CheckViaHotkeyAction()
83-
{
84-
Check();
85-
}
78+
public ICommand CheckCommand => new RelayCommand(_ => Check(), _ => !IsRunning);
8679

8780
#endregion
8881

@@ -91,7 +84,7 @@ private void CheckViaHotkeyAction()
9184
/// <summary>
9285
/// Checks the IP geolocation.
9386
/// </summary>
94-
public void Check()
87+
private void Check()
9588
{
9689
_ = CheckAsync();
9790
}
@@ -105,10 +98,6 @@ private async Task CheckAsync()
10598
if (!SettingsManager.Current.Dashboard_CheckIPApiIPGeolocation)
10699
return;
107100

108-
// Don't check multiple times if already running
109-
if (IsRunning)
110-
return;
111-
112101
IsRunning = true;
113102
Result = null;
114103

‎Source/NETworkManager/ViewModels/NetworkConnectionWidgetViewModel.cs‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,22 @@ private set
476476
/// </summary>
477477
public bool CheckPublicIPAddressEnabled => SettingsManager.Current.Dashboard_CheckPublicIPAddress;
478478

479+
/// <summary>
480+
/// Gets or sets a value indicating whether a check is currently running.
481+
/// </summary>
482+
public bool IsChecking
483+
{
484+
get;
485+
private set
486+
{
487+
if (value == field)
488+
return;
489+
490+
field = value;
491+
OnPropertyChanged();
492+
}
493+
}
494+
479495
#endregion
480496

481497
#region Constructor, load settings
@@ -486,6 +502,7 @@ private set
486502
public NetworkConnectionWidgetViewModel()
487503
{
488504
LoadSettings();
505+
Check();
489506
}
490507

491508
/// <summary>
@@ -500,17 +517,9 @@ private void LoadSettings()
500517
#region ICommands & Actions
501518

502519
/// <summary>
503-
/// Gets the command to check connections via hotkey.
520+
/// Gets the command to check connections.
504521
/// </summary>
505-
public ICommand CheckViaHotkeyCommand => new RelayCommand(_ => CheckViaHotkeyAction());
506-
507-
/// <summary>
508-
/// Executes the check via hotkey action.
509-
/// </summary>
510-
private void CheckViaHotkeyAction()
511-
{
512-
Check();
513-
}
522+
public ICommand CheckCommand => new RelayCommand(_ => Check());
514523

515524
#endregion
516525

@@ -564,6 +573,8 @@ private async Task CheckAsync()
564573
_cancellationTokenSource = new CancellationTokenSource();
565574
var wasCanceled = false;
566575

576+
IsChecking = true;
577+
567578
try
568579
{
569580
_checkTask = RunTask(_cancellationTokenSource.Token);
@@ -576,6 +587,9 @@ private async Task CheckAsync()
576587
}
577588
finally
578589
{
590+
IsChecking = false;
591+
_cancellationTokenSource.Dispose();
592+
579593
if (!wasCanceled)
580594
Log.Info("Network connection check completed.");
581595
}

‎Source/NETworkManager/Views/ConnectionsView.xaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
</ComboBox>
6868
<Button Command="{Binding Path=RefreshCommand}"
6969
Style="{StaticResource CleanButton}"
70+
ToolTip="{x:Static localization:Strings.Refresh}"
7071
Margin="0,0,10,0">
7172
<Rectangle Width="16" Height="16"
7273
wpfHelpers:ReloadAnimationHelper.IsReloading="{Binding IsRefreshing}">

‎Source/NETworkManager/Views/DashboardView.xaml.cs‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,18 @@ public DashboardView()
2222
ContentControlIPApiIPGeolocation.Content = _ipApiIPGeolocationWidgetView;
2323
ContentControlIPApiDNSResolver.Content = _ipApiDNSResolverWidgetView;
2424
ContentControlSpeedTest.Content = _speedTestWidgetView;
25-
26-
// Check all widgets
27-
Check();
2825
}
2926

3027
public void OnViewVisible()
3128
{
3229
_viewModel.OnViewVisible();
3330

34-
// Check all widgets
35-
Check();
31+
// Check network connection
32+
_networkConnectionWidgetView.Check();
3633
}
3734

3835
public void OnViewHide()
3936
{
4037
_viewModel.OnViewHide();
4138
}
42-
43-
/// <summary>
44-
/// Check all widgets
45-
/// </summary>
46-
private void Check()
47-
{
48-
_networkConnectionWidgetView.Check();
49-
_ipApiIPGeolocationWidgetView.Check();
50-
_ipApiDNSResolverWidgetView.Check();
51-
}
52-
}
39+
}

‎Source/NETworkManager/Views/FirewallView.xaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
HorizontalAlignment="Right">
5858
<Button Command="{Binding Path=RefreshCommand}"
5959
Style="{StaticResource CleanButton}"
60+
ToolTip="{x:Static localization:Strings.Refresh}"
6061
Margin="0,0,10,0">
6162
<Rectangle Width="16" Height="16"
6263
wpfHelpers:ReloadAnimationHelper.IsReloading="{Binding IsRefreshing}">

‎Source/NETworkManager/Views/HostsFileEditorView.xaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
HorizontalAlignment="Right">
5252
<Button Command="{Binding Path=RefreshCommand}"
5353
Style="{StaticResource CleanButton}"
54+
ToolTip="{x:Static localization:Strings.Refresh}"
5455
Margin="0,0,10,0">
5556
<Rectangle Width="16" Height="16"
5657
wpfHelpers:ReloadAnimationHelper.IsReloading="{Binding IsRefreshing}">

‎Source/NETworkManager/Views/IPApiDNSResolverWidgetView.xaml‎

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
xmlns:settings="clr-namespace:NETworkManager.Settings;assembly=NETworkManager.Settings"
1111
xmlns:viewModels="clr-namespace:NETworkManager.ViewModels"
1212
xmlns:system="clr-namespace:System;assembly=mscorlib"
13+
xmlns:wpfHelpers="clr-namespace:NETworkManager.Utilities.WPF;assembly=NETworkManager.Utilities.WPF"
1314
mc:Ignorable="d" MinHeight="200"
1415
d:DataContext="{d:DesignInstance viewModels:IPApiDNSResolverWidgetViewModel}">
1516
<UserControl.InputBindings>
16-
<KeyBinding Key="F5" Command="{Binding CheckViaHotkeyCommand}" />
17+
<KeyBinding Key="F5" Command="{Binding CheckCommand}" />
1718
</UserControl.InputBindings>
1819
<UserControl.Resources>
1920
<converters:BooleanReverseToVisibilityCollapsedConverter x:Key="BooleanReverseToVisibilityCollapsedConverter" />
@@ -37,15 +38,43 @@
3738
<RowDefinition Height="Auto" />
3839
<RowDefinition Height="*" />
3940
</Grid.RowDefinitions>
40-
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Left" Margin="10">
41-
<Rectangle Width="32" Height="32" Fill="{DynamicResource MahApps.Brushes.Gray3}">
42-
<Rectangle.OpacityMask>
43-
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=SearchWeb}" />
44-
</Rectangle.OpacityMask>
45-
</Rectangle>
46-
<TextBlock Text="{x:Static localization:Strings.DNSResolver}"
47-
Style="{StaticResource MessageTextBlock}" Margin="10,0,0,0" />
48-
</StackPanel>
41+
<Grid Grid.Row="0" Margin="10">
42+
<Grid.ColumnDefinitions>
43+
<ColumnDefinition Width="Auto" />
44+
<ColumnDefinition Width="*" />
45+
<ColumnDefinition Width="Auto" />
46+
</Grid.ColumnDefinitions>
47+
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
48+
<Rectangle Width="32" Height="32" Fill="{DynamicResource MahApps.Brushes.Gray3}">
49+
<Rectangle.OpacityMask>
50+
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=SearchWeb}" />
51+
</Rectangle.OpacityMask>
52+
</Rectangle>
53+
<TextBlock Text="{x:Static localization:Strings.DNSResolver}"
54+
Style="{StaticResource MessageTextBlock}" Margin="10,0,0,0" />
55+
</StackPanel>
56+
<Button Grid.Column="2" Command="{Binding CheckCommand}"
57+
Style="{StaticResource CleanButton}"
58+
ToolTip="{x:Static localization:Strings.Refresh}"
59+
VerticalAlignment="Center">
60+
<Rectangle Width="20" Height="20"
61+
wpfHelpers:ReloadAnimationHelper.IsReloading="{Binding IsRunning}">
62+
<Rectangle.OpacityMask>
63+
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=Refresh}" />
64+
</Rectangle.OpacityMask>
65+
<Rectangle.Style>
66+
<Style TargetType="{x:Type Rectangle}">
67+
<Setter Property="Fill" Value="{DynamicResource MahApps.Brushes.Gray3}" />
68+
<Style.Triggers>
69+
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Button}}, Path=IsMouseOver}" Value="True">
70+
<Setter Property="Fill" Value="{DynamicResource MahApps.Brushes.Gray5}" />
71+
</DataTrigger>
72+
</Style.Triggers>
73+
</Style>
74+
</Rectangle.Style>
75+
</Rectangle>
76+
</Button>
77+
</Grid>
4978
<Grid Grid.Column="0" Grid.Row="2" Margin="10"
5079
Visibility="{Binding Source={x:Static Member=settings:SettingsManager.Current}, Path=Dashboard_CheckIPApiDNSResolver, Converter={StaticResource ResourceKey=BooleanToVisibilityCollapsedConverter}}">
5180
<!-- Result-->

0 commit comments

Comments
 (0)