Skip to content

Commit bca6208

Browse files
committed
代码规范
1 parent c9a031f commit bca6208

28 files changed

+382
-319
lines changed

cat2/CAT2.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<UseWPF>true</UseWPF>
55
<Version>1.1.8.0</Version>
66
<OutputType>WinExe</OutputType>
7-
<FileVersion>0.0.3.0</FileVersion>
7+
<FileVersion>0.0.3.1</FileVersion>
88
<LangVersion>preview</LangVersion>
99
<ApplicationIcon>logo.ico</ApplicationIcon>
1010
<TargetFramework>net9.0-windows</TargetFramework>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.IO;
22
using System.Reflection;
33

4-
namespace CAT2.Models;
4+
namespace CAT2.Common;
55

66
public static class Constants
77
{
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using Wpf.Ui;
1+
using System;
2+
using Wpf.Ui;
23
using Wpf.Ui.Extensions;
34

4-
namespace CAT2.Models;
5+
namespace CAT2.Common;
56

6-
public static class Services
7+
public static class DialogService
78
{
89
public static readonly SnackbarService SnackBarService = new();
910

cat2/GlobalUsings.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
global using System;
2-
global using System.Diagnostics;
3-
global using System.Threading.Tasks;
1+
global using System.Threading.Tasks;
42
global using System.Windows;
53
global using CAT2.ViewModels;
64
global using CommunityToolkit.Mvvm.ComponentModel;
7-
global using CommunityToolkit.Mvvm.Input;
85
global using Wpf.Ui.Controls;
9-
global using static CAT2.Models.Constants;
10-
global using static CAT2.Models.Services;
11-
global using static ChmlFrp.SDK.SetPath;
12-
global using static ChmlFrp.SDK.TunnelActions;
6+
global using static CAT2.Common.DialogService;
7+
global using static ChmlFrp.SDK.SetPath;

cat2/Models/Items.cs

Lines changed: 0 additions & 178 deletions
This file was deleted.

cat2/ViewModels/Controls/AddTunnelContentDialogViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System.Collections.Generic;
22
using System.Collections.ObjectModel;
33
using System.Linq;
4+
using CAT2.ViewModels.Items;
45
using ChmlFrp.SDK;
5-
using static CAT2.Models.Items;
66

77
namespace CAT2.ViewModels.Controls;
88

@@ -13,11 +13,11 @@ public partial class AddTunnelContentDialogViewModel : ObservableObject
1313
[ObservableProperty] private string _localPort;
1414
[ObservableProperty] private int _maximum;
1515
[ObservableProperty] private int _minimum;
16-
[ObservableProperty] private ObservableCollection<NodeItem> _nodeDataContext = [];
17-
[ObservableProperty] private NodeItem _selectedItem;
16+
[ObservableProperty] private ObservableCollection<NodeViewModel> _nodeDataContext = [];
1817

1918
[ObservableProperty] private Visibility _numberBoxVisibility = Visibility.Visible;
2019
[ObservableProperty] private string _remotePort;
20+
[ObservableProperty] private NodeViewModel _selectedItem;
2121
[ObservableProperty] private Visibility _textBoxVisibility = Visibility.Collapsed;
2222
[ObservableProperty] private string _tunnelType = "tcp";
2323

@@ -36,7 +36,7 @@ partial void OnTunnelTypeChanged(string value)
3636
}
3737
}
3838

39-
async partial void OnSelectedItemChanged(NodeItem value)
39+
async partial void OnSelectedItemChanged(NodeViewModel value)
4040
{
4141
var nodeInfo = await NodeActions.GetNodeInfoAsync(value.Name);
4242
if (nodeInfo == null) return;

cat2/ViewModels/Controls/UpdateTunnelContentDialogViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class UpdateTunnelContentDialogViewModel(
66
Classes.TunnelInfoClass tunnelInfo
77
) : AddTunnelContentDialogViewModel
88
{
9-
public async override void LoadNodes(object sender, RoutedEventArgs e)
9+
public override async void LoadNodes(object sender, RoutedEventArgs e)
1010
{
1111
LocalIp = tunnelInfo.localip;
1212
LocalPort = tunnelInfo.nport.ToString();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using CAT2.Views.Controls;
2+
using ChmlFrp.SDK;
3+
using CommunityToolkit.Mvvm.Input;
4+
5+
namespace CAT2.ViewModels.Items;
6+
7+
public partial class NodeInfoViewModel(
8+
Classes.NodeInfoClass nodeInfo
9+
) : ObservableObject
10+
{
11+
[ObservableProperty]
12+
private string _id = $"#{nodeInfo.id}";
13+
14+
[ObservableProperty]
15+
private float _load15 = nodeInfo.load15 * 100;
16+
17+
[ObservableProperty]
18+
private string _name = $"{nodeInfo.name}({(nodeInfo.nodegroup == "vip" ? "VIP" : "普通")},{(nodeInfo.state == "online" ? "在线" : "离线")})";
19+
20+
[ObservableProperty]
21+
private string _notes = $"[IP地址:{nodeInfo.ip}]\n[CPU:{nodeInfo.cpu_info}]\n[介绍:{nodeInfo.notes}]";
22+
23+
[ObservableProperty]
24+
private string _totalTrafficIn = $"[下载流量:{nodeInfo.total_traffic_in / 1024 / 1024 / 1024:0.0}GB]";
25+
26+
[ObservableProperty]
27+
private string _totalTrafficOut = $"[上传流量: {nodeInfo.total_traffic_out / 1024 / 1024 / 1024:0.0}GB]";
28+
29+
[RelayCommand]
30+
private async Task ShowAddTunnelDialogAsync()
31+
{
32+
await new AddTunnelContentDialog(ContentDialogService.GetDialogHost()).ShowAsync();
33+
}
34+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using ChmlFrp.SDK;
2+
3+
namespace CAT2.ViewModels.Items;
4+
5+
public partial class NodeViewModel(
6+
Classes.NodeDataClass nodeData
7+
) : ObservableObject
8+
{
9+
[ObservableProperty]
10+
private string _content = $"{nodeData.name} ({nodeData.nodegroup}{nodeData.udp}{nodeData.web})";
11+
12+
[ObservableProperty]
13+
private string _name = nodeData.name;
14+
15+
[ObservableProperty]
16+
private string _notes = $"{nodeData.notes}";
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using ChmlFrp.SDK;
2+
3+
namespace CAT2.ViewModels.Items;
4+
5+
public partial class TunnelStartedViewModel(
6+
Classes.TunnelInfoClass tunnelInfo,
7+
bool isStarted
8+
) : ObservableObject
9+
{
10+
[ObservableProperty]
11+
private bool _isStarted = isStarted;
12+
13+
[ObservableProperty]
14+
private string _name = $"{tunnelInfo.name}({tunnelInfo.type.ToUpperInvariant()})";
15+
}

0 commit comments

Comments
 (0)