Skip to content

Commit 903a28f

Browse files
committed
add: 关于页面的功能完成
1 parent dafd4b0 commit 903a28f

File tree

6 files changed

+149
-22
lines changed

6 files changed

+149
-22
lines changed

llcomNext/LLCOM/LLCOM.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<ApplicationManifest>app.manifest</ApplicationManifest>
88
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
99
<ApplicationIcon>Assets\Images\logo.ico</ApplicationIcon>
10+
<AssemblyVersion>2.0.0.0</AssemblyVersion>
11+
<FileVersion>2.0.0.0</FileVersion>
1012
</PropertyGroup>
1113

1214
<ItemGroup>
@@ -30,7 +32,9 @@
3032
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
3133
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.3" />
3234
<PackageReference Include="NLua" Version="1.7.4" />
35+
<PackageReference Include="RestSharp" Version="112.1.0" />
3336
<PackageReference Include="Semi.Avalonia" Version="11.2.1.5" />
37+
<PackageReference Include="System.Text.Json" Version="9.0.3" />
3438
</ItemGroup>
3539

3640

llcomNext/LLCOM/Services/Utils.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.IO;
34
using System.Threading.Tasks;
45
using Avalonia;
@@ -20,7 +21,7 @@ public static string Version
2021
if (_version is null)
2122
{
2223
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version!;
23-
_version = $"{version.Major}.{version.Minor}.{version.Build}";
24+
_version = version.ToString();
2425
}
2526
return _version;
2627
}
@@ -45,6 +46,11 @@ public static void Initial()
4546
//初始化语言 TODO
4647
}
4748

49+
/// <summary>
50+
/// 复制文本到剪贴板
51+
/// </summary>
52+
/// <param name="txt">文本数据</param>
53+
/// <returns>是否复制成功</returns>
4854
public static async Task<bool> CopyString(string txt)
4955
{
5056
try
@@ -70,4 +76,25 @@ public static async Task<bool> CopyString(string txt)
7076
return false;
7177
}
7278
}
79+
80+
/// <summary>
81+
/// 打开网页链接
82+
/// </summary>
83+
/// <param name="url">网址</param>
84+
public static void OpenWebLink(string url)
85+
{
86+
try
87+
{
88+
var psi = new ProcessStartInfo
89+
{
90+
FileName = url,
91+
UseShellExecute = true
92+
};
93+
Process.Start(psi);
94+
}
95+
catch
96+
{
97+
// ignored
98+
}
99+
}
73100
}

llcomNext/LLCOM/ViewModels/MainWindowViewModel.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@
66
namespace LLCOM.ViewModels
77
{
88

9-
public partial class MainWindowViewModel(Func<Type, ViewModelBase> getService) : ViewModelBase
9+
public partial class MainWindowViewModel : ViewModelBase
1010
{
1111
[ObservableProperty]
12-
private MainViewModel _mainViewModel = (MainViewModel)getService(typeof(MainViewModel));
12+
private MainViewModel _mainViewModel;
13+
14+
[ObservableProperty]
15+
private string _title = "LLCOM";
16+
17+
public MainWindowViewModel(Func<Type, ViewModelBase> getService)
18+
{
19+
_mainViewModel = (MainViewModel)getService(typeof(MainViewModel));
20+
Title += $" - {Services.Utils.Version}";
21+
}
1322
}
1423
}
Lines changed: 88 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Threading.Tasks;
34
using CommunityToolkit.Mvvm.ComponentModel;
45
using CommunityToolkit.Mvvm.Input;
6+
using RestSharp;
57

68
namespace LLCOM.ViewModels;
79

@@ -15,26 +17,102 @@ public SettingPageViewModel() {}
1517
public SettingPageViewModel(Func<Type, ViewModelBase> getService)
1618
{
1719
_getService = getService;
18-
}
1920

20-
[ObservableProperty] private string _systemInfo =
21-
$"LLCOM: {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version}\n\n" +
22-
$"Operating System: {Environment.OSVersion.VersionString}\n" +
23-
$".Net CLR: {Environment.Version}\n" +
21+
//初始化系统信息
22+
Task.Run(() =>
23+
{
24+
var packagesInfo = new List<string>();
25+
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
26+
27+
foreach (var assembly in assemblies)
28+
{
29+
var name = assembly.GetName();
30+
packagesInfo.Add($"{name.Name}: {name.Version}");
31+
}
32+
33+
SystemInfo =
34+
$"LLCOM: {Services.Utils.Version}\n" +
35+
$"OS: {Environment.OSVersion.VersionString}\n" +
36+
$".Net CLR: {Environment.Version}\n" +
2437
#if debug
25-
$"Debug mode: true\n" +
38+
$"Debug mode: true\n" +
2639
#else
27-
$"Debug mode: false\n" +
40+
$"Debug mode: false\n" +
2841
#endif
29-
$"Location: {Environment.CurrentDirectory}\n" +
30-
$"AppData: TODO\n" +
31-
$"Environment: {Environment.GetEnvironmentVariable("PATH")}";
42+
$"Location: {Environment.CurrentDirectory}\n" +
43+
$"AppData: {Services.Utils.AppPath}\n" +
44+
$"Packages \n{string.Join("\n", packagesInfo)}\n" +
45+
$"Environment: {Environment.GetEnvironmentVariable("PATH")}";
46+
});
47+
}
48+
49+
50+
#region About
51+
[ObservableProperty] private string _systemInfo = "Loading...";
3252

3353
[RelayCommand]
3454
private async Task CopySystemInfo()
3555
{
56+
if(SystemInfo.Length < 20)//还没加载完
57+
return;
3658
await Services.Utils.CopyString(SystemInfo);
3759
}
3860

61+
[ObservableProperty]
62+
[NotifyPropertyChangedFor(nameof(HasNewVersion), nameof(NoNewVersion))]
63+
private bool _hasCheckedUpdate = false;
64+
65+
public bool HasNewVersion => HasCheckedUpdate && _updateUrl != null;
66+
public bool NoNewVersion => HasCheckedUpdate && _updateUrl == null;
67+
68+
private string? _updateUrl = null;
69+
70+
[RelayCommand]
71+
private async Task CheckUpdate()
72+
{
73+
if (HasCheckedUpdate && _updateUrl != null)
74+
{
75+
Services.Utils.OpenWebLink(_updateUrl);
76+
return;
77+
}
78+
79+
var versionNow = Services.Utils.Version;
80+
//获取https://api.github.com/repos/chenxuuu/llcom/releases/latest的json结果
81+
var client = new RestClient("https://api.github.com/repos/chenxuuu/llcom/releases/latest");
82+
var request = new RestRequest();
83+
var response = await client.ExecuteAsync(request);
84+
if (!response.IsSuccessful || response.Content is null)
85+
return;
86+
87+
var json = System.Text.Json.JsonDocument.Parse(response.Content);
88+
var version = json.RootElement.GetProperty("tag_name").GetString();
89+
if(version == null)
90+
return;
91+
92+
//判断在线版本是否新于本地版本,按点分割后比较
93+
var isBigger = true;
94+
if(version == versionNow)
95+
isBigger = false;
96+
else
97+
{
98+
var versionNowSplit = versionNow.Split('.');
99+
var versionSplit = version.Split('.');
100+
for (int i = 0; i < versionNowSplit.Length; i++)
101+
{
102+
if (int.Parse(versionNowSplit[i]) > int.Parse(versionSplit[i]))
103+
{
104+
isBigger = false;
105+
break;
106+
}
107+
}
108+
}
109+
110+
//更新信息
111+
if(isBigger)
112+
_updateUrl = json.RootElement.GetProperty("html_url").GetString();
113+
114+
HasCheckedUpdate = true;
115+
}
116+
#endregion
39117

40118
}

llcomNext/LLCOM/Views/MainWindow.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Icon="/Assets/Images/logo.ico"
44
MinHeight="300"
55
MinWidth="400"
6-
Title="LLCOM Next"
6+
Title="{Binding Title}"
77
Width="1200"
88
WindowStartupLocation="CenterScreen"
99
mc:Ignorable="d"

llcomNext/LLCOM/Views/Pages/SettingPageView.axaml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,17 @@
4545
Text="多功能调试工具" />
4646

4747
<Panel Margin="0,10,0,0">
48-
<Button Content="检查更新" />
48+
<Button Command="{Binding CheckUpdateCommand}" Name="CheckUpdateButton">
49+
<Panel>
50+
<TextBlock HorizontalAlignment="Center" IsVisible="{Binding !HasCheckedUpdate}">检查更新</TextBlock>
51+
<TextBlock HorizontalAlignment="Center" IsVisible="{Binding NoNewVersion}">已是最新版本</TextBlock>
52+
<TextBlock HorizontalAlignment="Center" IsVisible="{Binding HasNewVersion}">下载新版本</TextBlock>
53+
</Panel>
54+
</Button>
4955
<ProgressBar
5056
Height="30"
5157
IsIndeterminate="True"
58+
IsVisible="{Binding ElementName=CheckUpdateButton, Path=!IsEffectivelyEnabled}"
5259
Maximum="100"
5360
Minimum="0"
5461
Theme="{DynamicResource ProgressRing}"
@@ -71,17 +78,19 @@
7178
</StackPanel>
7279

7380

74-
<TextBox
75-
AcceptsReturn="True"
76-
FontSize="15"
77-
IsReadOnly="True"
78-
Margin="0,20,0,0"
79-
Text="{Binding SystemInfo}" />
8081
<Button
8182
Command="{Binding CopySystemInfoCommand}"
8283
Content="复制调试信息"
8384
HorizontalAlignment="Stretch"
84-
Margin="0,5,0,0" />
85+
Margin="0,20,0,0" />
86+
<TextBox
87+
AcceptsReturn="True"
88+
FontSize="15"
89+
Height="300"
90+
IsReadOnly="True"
91+
Margin="0,5,0,0"
92+
Text="{Binding SystemInfo}"
93+
VerticalContentAlignment="Top" />
8594
</StackPanel>
8695
</ScrollViewer>
8796
</TabItem>

0 commit comments

Comments
 (0)