Skip to content

Commit 8d0e56b

Browse files
author
panwenbo
committed
One.Toolbox
新增网速测试功能小窗;
1 parent c4c3619 commit 8d0e56b

File tree

9 files changed

+183
-107
lines changed

9 files changed

+183
-107
lines changed

One.Toolbox/One.Toolbox.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<SelfContained>false</SelfContained>
1010
<UseWPF>true</UseWPF>
1111
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
12-
<Version>2.6.8</Version>
12+
<Version>2.7.0</Version>
1313
<ImplicitUsings>enable</ImplicitUsings>
1414
<SatelliteResourceLanguages>zh-Hans;en-us</SatelliteResourceLanguages>
1515
<ApplicationIcon>Icon.ico</ApplicationIcon>

One.Toolbox/ViewModels/NetSpeed/NetSpeedItemVM.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using One.Toolbox.ViewModels.Base;
22

3-
using System.Net.Mail;
43
using System.Net.NetworkInformation;
54

6-
using static System.Runtime.InteropServices.JavaScript.JSType;
7-
85
namespace One.Toolbox.ViewModels.NetSpeed;
96

107
public partial class NetSpeedItemVM : BaseVM

One.Toolbox/ViewModels/NetSpeed/NetSpeedPageVM.cs

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
using Microsoft.Extensions.DependencyInjection;
1+
using CommunityToolkit.Mvvm.Messaging;
2+
3+
using Microsoft.Extensions.DependencyInjection;
24

35
using One.Core.ExtensionMethods;
6+
using One.Toolbox.Messenger;
47
using One.Toolbox.Services;
58
using One.Toolbox.ViewModels.Base;
9+
using One.Toolbox.Views.NetSpeed;
610

711
using System.Collections.ObjectModel;
812
using System.Net.NetworkInformation;
@@ -21,43 +25,59 @@ public partial class NetSpeedPageVM : BaseVM
2125

2226
public NetSpeedPlotVM NetSpeedPlot { get; set; } = new NetSpeedPlotVM();
2327

28+
[ObservableProperty]
29+
private bool showSmallWnd;
30+
2431
public NetSpeedPageVM()
2532
{
33+
WeakReferenceMessenger.Default.Register<CloseMessage>(this, (r, m) =>
34+
{
35+
// Handle the message here, with r being the recipient and m being the input message. Using the recipient passed as input makes it so that the lambda expression doesn't capture "this", improving performance.
36+
37+
SaveSetting();
38+
});
39+
2640
var interfaces = NetworkInterface.GetAllNetworkInterfaces();
27-
NetSpeedItems.AddRange(interfaces.Select(i => new NetSpeedItemVM(i)).ToList());
2841

29-
NetSpeedItems.ForEach(i => i.Start(cts.Token));
30-
}
42+
foreach (var item in interfaces)
43+
{
44+
if (!item.OperationalStatus.Equals(OperationalStatus.Up) || item.NetworkInterfaceType == NetworkInterfaceType.Loopback)
45+
{
46+
WriteDebugLog($"Net interface {ToString()} is {item.OperationalStatus}");
47+
continue;
48+
}
3149

32-
public string LastAdapterName { get; set; }
50+
NetSpeedItems.Add(new NetSpeedItemVM(item));
51+
}
52+
53+
NetSpeedItems.ForEach(i => i.Start(cts.Token));
3354

34-
public override void InitializeViewModel()
35-
{
3655
LoadSetting();
3756
NetSpeedSelectItemVM = NetSpeedItems.FirstOrDefault(i => i.InterfaceName == LastAdapterName);
57+
NetSpeedSelectItemVM.SpeedAction += NetSpeedPlot.OnSpeedChange;
3858

39-
base.InitializeViewModel();
40-
}
41-
42-
public override void OnNavigatedLeave()
43-
{
44-
base.OnNavigatedLeave();
45-
46-
LastAdapterName = NetSpeedSelectItemVM.InterfaceName;
59+
if (ShowSmallWnd)
60+
{
61+
NetSpeedWnd.DataContext = NetSpeedSelectItemVM;
4762

48-
SaveSetting();
63+
NetSpeedWnd.Show();
64+
}
4965
}
5066

67+
public string LastAdapterName { get; set; }
68+
5169
private void LoadSetting()
5270
{
5371
var service = App.Current.Services.GetService<SettingService>();
5472
LastAdapterName = service.AllConfig.NetSpeedSetting.LastAdapterName;
73+
ShowSmallWnd = service.AllConfig.NetSpeedSetting.ShowSpeedWndDefault;
5574
}
5675

5776
private void SaveSetting()
5877
{
5978
var service = App.Current.Services.GetService<SettingService>();
60-
service.AllConfig.NetSpeedSetting.LastAdapterName = LastAdapterName;
79+
service.AllConfig.NetSpeedSetting.LastAdapterName = LastAdapterName = NetSpeedSelectItemVM.InterfaceName;
80+
service.AllConfig.NetSpeedSetting.ShowSpeedWndDefault = ShowSmallWnd;
6181
service.Save();
6282
}
6383

@@ -76,4 +96,19 @@ private void SelectedNetSpeedItemChanged(SelectionChangedEventArgs obj)
7696
//addItem.Start(cts.Token);
7797
}
7898
}
99+
100+
private NetSpeedWnd NetSpeedWnd = new();
101+
102+
partial void OnShowSmallWndChanged(bool value)
103+
{
104+
if (value)
105+
{
106+
NetSpeedWnd.DataContext = NetSpeedSelectItemVM;
107+
NetSpeedWnd.Show();
108+
}
109+
else
110+
{
111+
NetSpeedWnd.Hide();
112+
}
113+
}
79114
}

One.Toolbox/ViewModels/NetSpeed/NetSpeedPlotVM.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public NetSpeedPlotVM()
6565
};
6666

6767
XAxes = [customXAxis];
68-
YAxes = new Axis[] { new Axis { SeparatorsPaint = new SolidColorPaint(SKColors.Black.WithAlpha(20)),MinLimit=0 } };
68+
YAxes = new Axis[] { new Axis { SeparatorsPaint = new SolidColorPaint(SKColors.Black.WithAlpha(20)), MinLimit = 0 } };
6969
}
7070

7171
private static double[] GetSeparators()

One.Toolbox/ViewModels/Setting/AllConfigModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ public class EditFileInfo
2525
public class NetSpeedSettingModel
2626
{
2727
public string LastAdapterName { get; set; }
28+
public bool ShowSpeedWndDefault { get; set; }
2829
}

One.Toolbox/Views/DataProcess/StringConvertPage.xaml.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
using One.Toolbox.ViewModels.DataProcess;
44

5-
namespace One.Toolbox.Views.DataProcess
5+
namespace One.Toolbox.Views.DataProcess;
6+
7+
/// <summary> 编码转换工具页面 </summary>
8+
public partial class StringConvertPage
69
{
7-
/// <summary> 编码转换工具页面 </summary>
8-
public partial class StringConvertPage
9-
{
10-
public ViewModels.DataProcess.StringConvertPageVM ViewModel { get; }
10+
public ViewModels.DataProcess.StringConvertPageVM ViewModel { get; }
1111

12-
public StringConvertPage()
13-
{
14-
DataContext = ViewModel = App.Current.Services.GetService<StringConvertPageVM>();
12+
public StringConvertPage()
13+
{
14+
DataContext = ViewModel = App.Current.Services.GetService<StringConvertPageVM>();
1515

16-
InitializeComponent();
17-
}
16+
InitializeComponent();
1817
}
1918
}

One.Toolbox/Views/NetSpeed/NetSpeedPage.xaml

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:local="clr-namespace:One.Toolbox.Views.NetSpeed"
7+
xmlns:hc="https://handyorg.github.io/handycontrol"
78
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"
89
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
910
xmlns:o="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
@@ -14,60 +15,76 @@
1415
d:Height="548"
1516
d:Width="733"
1617
mc:Ignorable="d">
17-
<Grid>
18-
<Grid.Resources />
18+
<Border Style="{StaticResource BorderRegion}">
19+
<Grid>
20+
<Grid.Resources />
1921

20-
<Grid.ColumnDefinitions>
21-
<ColumnDefinition />
22-
<ColumnDefinition Width="3*" />
23-
</Grid.ColumnDefinitions>
24-
25-
<ListBox ItemsSource="{Binding NetSpeedItems}" SelectedItem="{Binding NetSpeedSelectItemVM}">
26-
<behaviors:Interaction.Triggers>
27-
<behaviors:EventTrigger EventName="SelectionChanged">
28-
<behaviors:InvokeCommandAction Command="{Binding SelectedNetSpeedItemChangedCommand}" PassEventArgsToCommand="True" />
29-
</behaviors:EventTrigger>
30-
</behaviors:Interaction.Triggers>
31-
<ListBox.ItemTemplate>
32-
<DataTemplate DataType="viewmodels:NetSpeedItemVM">
33-
<Grid>
34-
<TextBlock Text="{Binding InterfaceName}" />
35-
</Grid>
36-
</DataTemplate>
37-
</ListBox.ItemTemplate>
38-
</ListBox>
39-
40-
<Grid Grid.Column="1">
22+
<Grid.ColumnDefinitions>
23+
<ColumnDefinition />
24+
<ColumnDefinition Width="3*" />
25+
</Grid.ColumnDefinitions>
4126
<Grid.RowDefinitions>
42-
<RowDefinition Height="auto"/>
43-
<RowDefinition />
27+
<RowDefinition >
28+
29+
</RowDefinition>
30+
<RowDefinition Height="auto"></RowDefinition>
4431
</Grid.RowDefinitions>
32+
<ListBox ItemsSource="{Binding NetSpeedItems}" SelectedItem="{Binding NetSpeedSelectItemVM}">
33+
<behaviors:Interaction.Triggers>
34+
<behaviors:EventTrigger EventName="SelectionChanged">
35+
<behaviors:InvokeCommandAction Command="{Binding SelectedNetSpeedItemChangedCommand}" PassEventArgsToCommand="True" />
36+
</behaviors:EventTrigger>
37+
</behaviors:Interaction.Triggers>
38+
<ListBox.ItemTemplate>
39+
<DataTemplate DataType="viewmodels:NetSpeedItemVM">
40+
<Grid>
41+
<TextBlock Text="{Binding InterfaceName}" />
42+
</Grid>
43+
</DataTemplate>
44+
</ListBox.ItemTemplate>
45+
</ListBox>
4546

47+
<Grid Grid.Column="1" Grid.RowSpan="2">
48+
<Grid.RowDefinitions>
49+
<RowDefinition Height="auto"/>
50+
<RowDefinition />
51+
</Grid.RowDefinitions>
4652

47-
<StackPanel Margin="10,5" DataContext="{Binding NetSpeedSelectItemVM}">
48-
<StackPanel Orientation="Horizontal">
49-
<TextBlock Text="上行:" />
50-
<TextBlock Text="{Binding SpeedSentHuman}" />
51-
</StackPanel>
52-
<StackPanel Orientation="Horizontal" >
53-
<TextBlock Text="下行:" />
54-
<TextBlock Text="{Binding SpeedReceivedHuman}" />
55-
</StackPanel>
5653

57-
</StackPanel>
54+
5855

59-
<Grid Grid.Row="1" DataContext="{Binding NetSpeedPlot}">
60-
<lvc:CartesianChart AnimationsSpeed="00:00:00.000" LegendPosition="Bottom"
61-
Series="{Binding SpeedSeries}" Sections="{Binding Sections}"
62-
SyncContext="{Binding Sync}"
63-
XAxes="{Binding XAxes}"
64-
YAxes="{Binding YAxes}" >
56+
<Grid Grid.Row="1" DataContext="{Binding NetSpeedPlot}">
57+
<lvc:CartesianChart AnimationsSpeed="00:00:00.000" LegendPosition="Bottom"
58+
Series="{Binding SpeedSeries}" Sections="{Binding Sections}"
59+
SyncContext="{Binding Sync}"
60+
XAxes="{Binding XAxes}"
61+
YAxes="{Binding YAxes}" >
6562

66-
</lvc:CartesianChart>
67-
</Grid>
63+
</lvc:CartesianChart>
64+
</Grid>
6865

69-
</Grid>
66+
</Grid>
67+
68+
<Grid Grid.Row="1" Margin="10,5" >
7069

70+
<Grid.ColumnDefinitions>
71+
<ColumnDefinition></ColumnDefinition>
72+
<ColumnDefinition Width="auto"></ColumnDefinition>
73+
</Grid.ColumnDefinitions>
74+
<StackPanel DataContext="{Binding NetSpeedSelectItemVM}">
75+
<StackPanel Orientation="Horizontal">
76+
<TextBlock Text="上行:" />
77+
<TextBlock Text="{Binding SpeedSentHuman}" />
78+
</StackPanel>
79+
<StackPanel Orientation="Horizontal" >
80+
<TextBlock Text="下行:" />
81+
<TextBlock Text="{Binding SpeedReceivedHuman}" />
82+
</StackPanel>
83+
</StackPanel>
84+
<ToggleButton Grid.Column="1" Style="{StaticResource ToggleButtonSwitch}" Content="Show" IsChecked="{Binding ShowSmallWnd}" ></ToggleButton>
7185

72-
</Grid>
86+
</Grid>
87+
</Grid>
88+
</Border>
89+
7390
</UserControl>
Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
1-
<hc:Window x:Class="One.Toolbox.Views.NetSpeed.NetSpeedWnd"
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:hc="https://handyorg.github.io/handycontrol"
6-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7-
xmlns:vm="clr-namespace:One.Toolbox.ViewModels.NetSpeed"
8-
ShowNonClientArea="False"
9-
Width="450"
10-
Height="490"
11-
d:DataContext="{d:DesignInstance Type=vm:NetSpeedPageVM}"
12-
WindowStartupLocation="CenterScreen"
13-
mc:Ignorable="d">
1+
<Window x:Class="One.Toolbox.Views.NetSpeed.NetSpeedWnd"
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:hc="https://handyorg.github.io/handycontrol"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
xmlns:vm="clr-namespace:One.Toolbox.ViewModels.NetSpeed"
8+
Width="110" ShowInTaskbar="False"
9+
Height="40"
10+
d:DataContext="{d:DesignInstance Type=vm:NetSpeedItemVM}"
11+
AllowsTransparency="True"
12+
Opacity="0.6"
13+
ResizeMode="NoResize"
14+
Topmost="True"
15+
WindowStartupLocation="CenterScreen"
16+
WindowStyle="None"
17+
mc:Ignorable="d">
18+
<Border x:Name="border" hc:WindowAttach.IsDragElement="True" BorderBrush="Gray" BorderThickness="1">
1419

15-
<Grid>
16-
<Grid.ColumnDefinitions>
17-
<ColumnDefinition />
18-
<ColumnDefinition />
19-
</Grid.ColumnDefinitions>
20-
<Grid.RowDefinitions>
21-
<RowDefinition Height="auto" />
22-
<RowDefinition Height="auto" />
20+
<Grid Grid.Row="1" Margin="5">
2321

24-
</Grid.RowDefinitions>
25-
<Grid.Resources>
22+
<Grid.ColumnDefinitions>
23+
<ColumnDefinition />
24+
<ColumnDefinition Width="auto" />
25+
</Grid.ColumnDefinitions>
26+
<StackPanel>
27+
<StackPanel Orientation="Horizontal">
28+
<TextBlock Text="上行:" />
29+
<TextBlock Text="{Binding SpeedSentHuman}" />
30+
</StackPanel>
31+
<StackPanel Orientation="Horizontal">
32+
<TextBlock Text="下行:" />
33+
<TextBlock Text="{Binding SpeedReceivedHuman}" />
34+
</StackPanel>
35+
</StackPanel>
2636

27-
<Style BasedOn="{StaticResource TextBlockBaseStyle}" TargetType="TextBlock">
28-
<Setter Property="Margin" Value="5" />
29-
<Setter Property="HorizontalAlignment" Value="Right" />
30-
</Style>
3137

32-
</Grid.Resources>
38+
</Grid>
39+
</Border>
3340

34-
</Grid>
35-
</hc:Window>
41+
42+
</Window>

0 commit comments

Comments
 (0)