Skip to content

Commit dc85de8

Browse files
committed
新增更新日志的展示
1 parent 42e23f1 commit dc85de8

File tree

13 files changed

+229
-91
lines changed

13 files changed

+229
-91
lines changed

src/ComputerLock/App.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ private void Init()
4444
appSettings.Initialize(hotkeyTools);
4545
return appSettings;
4646
});
47+
services.AddSingleton((_) => new VersionLogChecker(AppBase.Version, AppBase.VersionFilePath));
4748
services.AddSingleton(LogManager.GetLogger());
4849
services.AddSingleton<HotkeyHook>();
4950
services.AddSingleton<MouseHook>();
@@ -74,6 +75,7 @@ private void Init()
7475
config.SnackbarConfiguration.HideTransitionDuration = 400;
7576
});
7677
services.AddMudExtensions();
78+
services.AddMudMarkdownServices();
7779

7880
var sp = services.BuildServiceProvider();
7981
Resources.Add("services", sp);
Lines changed: 95 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,105 @@
11
<MudDrawer @bind-Open="@_isOpen"
2-
Class="pa-6"
3-
Anchor="Anchor.End"
4-
Elevation="1"
5-
Width="350px"
6-
Variant="@DrawerVariant.Temporary">
7-
<MudDrawerContainer>
2+
Class="pa-6"
3+
Anchor="Anchor.End"
4+
Elevation="1"
5+
Width="350px"
6+
Variant="@DrawerVariant.Temporary">
7+
<MudDrawerContainer>
88

9-
<MudSwitch Value="@(_isAutostart)"
10-
T="bool"
11-
ValueChanged="AutostartChange"
12-
Label="@(Lang["Autostart"])"
13-
Color="Color.Primary" />
9+
<MudSwitch Value="@(_isAutostart)"
10+
T="bool"
11+
ValueChanged="AutostartChange"
12+
Label="@(Lang["Autostart"])"
13+
Color="Color.Primary" />
1414

15-
<MudSwitch @bind-Value="@(AppSettings.IsHideWindowWhenLaunch)"
16-
@bind-Value:after="SaveSettings"
17-
Label="@(Lang["HideWindowWhenLaunch"])"
18-
Color="Color.Primary" />
19-
<MudSwitch @bind-Value="@(AppSettings.IsHideWindowWhenClose)"
20-
@bind-Value:after="SaveSettings"
21-
Label="@(Lang["HideWindowWhenClose"])"
22-
Color="Color.Primary" />
23-
<MudSwitch @bind-Value="@(AppSettings.IsAutoCheckUpdate)"
24-
@bind-Value:after="SaveSettings"
25-
Label="@(Lang["AutoCheckUpdate"])"
26-
Color="Color.Primary" />
15+
<MudSwitch @bind-Value="@(AppSettings.IsHideWindowWhenLaunch)"
16+
@bind-Value:after="SaveSettings"
17+
Label="@(Lang["HideWindowWhenLaunch"])"
18+
Color="Color.Primary" />
19+
<MudSwitch @bind-Value="@(AppSettings.IsHideWindowWhenClose)"
20+
@bind-Value:after="SaveSettings"
21+
Label="@(Lang["HideWindowWhenClose"])"
22+
Color="Color.Primary" />
23+
<MudSwitch @bind-Value="@(AppSettings.IsAutoCheckUpdate)"
24+
@bind-Value:after="SaveSettings"
25+
Label="@(Lang["AutoCheckUpdate"])"
26+
Color="Color.Primary" />
2727

28-
<MudSelect Class="mt-3"
29-
T="string"
30-
Label="语言 Lang"
31-
Value="@(AppSettings.Lang.ToString())"
32-
ValueChanged="LangValueChanged">
33-
<MudSelectItem Value="@("zh")">中文</MudSelectItem>
34-
<MudSelectItem Value="@("en")">en</MudSelectItem>
35-
</MudSelect>
28+
<MudSelect Class="mt-3"
29+
T="string"
30+
Label="语言 Lang"
31+
Value="@(AppSettings.Lang.ToString())"
32+
ValueChanged="LangValueChanged">
33+
<MudSelectItem Value="@("zh")">中文</MudSelectItem>
34+
<MudSelectItem Value="@("en")">en</MudSelectItem>
35+
</MudSelect>
3636

3737

38-
<div class="mt-4 d-flex align-center">
39-
<MudText Typo="Typo.subtitle2">@(Lang["LogFiles"])</MudText>
40-
@if (_logLoadingOk)
41-
{
42-
<MudChip T="string"
43-
Label="true"
44-
Disabled="true"
45-
Variant="Variant.Text"
46-
Size="Size.Small">
47-
@($"{_logFilesSize / 1024 / 1024:N2} MB")
48-
</MudChip>
49-
}
50-
</div>
51-
<div class="d-flex align-center">
52-
@if (!_logLoadingOk)
53-
{
54-
<MudProgressCircular Color="Color.Primary"
55-
Class="ml-2"
56-
Size="Size.Small"
57-
Indeterminate="true" />
58-
}
59-
else
60-
{
61-
<MudButton Variant="Variant.Text"
62-
Color="Color.Primary"
63-
Size="Size.Small"
64-
OnClick="OpenLogPath">@(Lang["OpenLogs"])</MudButton>
65-
<MudButton Variant="Variant.Text"
66-
Color="Color.Primary"
67-
Size="Size.Small"
68-
OnClick="ClearLogAsync">@(Lang["RemoveLogs"])</MudButton>
69-
}
70-
</div>
71-
<MudDivider />
38+
<div class="mt-4 d-flex align-center">
39+
<MudText Typo="Typo.subtitle2">@(Lang["LogFiles"])</MudText>
40+
@if (_logLoadingOk)
41+
{
42+
<MudChip T="string"
43+
Label="true"
44+
Disabled="true"
45+
Variant="Variant.Text"
46+
Size="Size.Small">
47+
@($"{_logFilesSize / 1024 / 1024:N2} MB")
48+
</MudChip>
49+
}
50+
</div>
51+
<div class="d-flex align-center">
52+
@if (!_logLoadingOk)
53+
{
54+
<MudProgressCircular Color="Color.Primary"
55+
Class="ml-2"
56+
Size="Size.Small"
57+
Indeterminate="true" />
58+
}
59+
else
60+
{
61+
<MudButton Variant="Variant.Text"
62+
Color="Color.Primary"
63+
Size="Size.Small"
64+
OnClick="OpenLogPath">@(Lang["OpenLogs"])</MudButton>
65+
<MudButton Variant="Variant.Text"
66+
Color="Color.Primary"
67+
Size="Size.Small"
68+
OnClick="ClearLogAsync">@(Lang["RemoveLogs"])</MudButton>
69+
}
70+
</div>
71+
<MudDivider />
7272

73-
<div class="mt-4 d-flex align-center">
74-
<MudText Typo="Typo.subtitle2">@(Lang["Version"])</MudText>
75-
<MudChip T="string"
76-
Label="true"
77-
Disabled="true"
78-
Variant="Variant.Text"
79-
Size="Size.Small">
80-
@(_version)
81-
</MudChip>
82-
</div>
83-
<MudButton Variant="Variant.Text"
84-
Color="Color.Primary"
85-
Size="Size.Small"
86-
OnClick="CheckUpdateAsync">@(Lang["CheckUpdate"])</MudButton>
73+
<div class="mt-4 d-flex align-center">
74+
<MudText Typo="Typo.subtitle2">@(Lang["Version"])</MudText>
75+
<MudChip T="string"
76+
Label="true"
77+
Disabled="true"
78+
Variant="Variant.Text"
79+
Size="Size.Small">
80+
@(_version)
81+
</MudChip>
8782

88-
<MudDivider />
83+
<MudLink Typo="Typo.body2"
84+
Color="Color.Default"
85+
Style="opacity:0.5;"
86+
Underline="Underline.None"
87+
OnClick="OpenVersionHistory">@(Lang["VersionHistory"])</MudLink>
88+
</div>
89+
<MudButton Variant="Variant.Text"
90+
Color="Color.Primary"
91+
Size="Size.Small"
92+
OnClick="CheckUpdateAsync">@(Lang["CheckUpdate"])</MudButton>
8993

90-
<div class="mt-4 d-flex align-center">
91-
<MudText Typo="Typo.subtitle2">@(Lang["Advanced"])</MudText>
92-
</div>
93-
<MudButton Class="mt-2"
94-
Variant="Variant.Text"
95-
Color="Color.Primary"
96-
Size="Size.Small"
97-
OnClick="ResetSettingsAsync">@(Lang["ResetSettings"])</MudButton>
98-
</MudDrawerContainer>
94+
<MudDivider />
95+
96+
<div class="mt-4 d-flex align-center">
97+
<MudText Typo="Typo.subtitle2">@(Lang["Advanced"])</MudText>
98+
</div>
99+
<MudButton Class="mt-2"
100+
Variant="Variant.Text"
101+
Color="Color.Primary"
102+
Size="Size.Small"
103+
OnClick="ResetSettingsAsync">@(Lang["ResetSettings"])</MudButton>
104+
</MudDrawerContainer>
99105
</MudDrawer>

src/ComputerLock/Components/Setting.razor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected override async Task OnInitializedAsync()
3434
{
3535
await base.OnInitializedAsync();
3636
_isAutostart = AutostartHook.IsAutostart();
37-
_version = $"v{AppBase.Version[..AppBase.Version.LastIndexOf('.')]}";
37+
_version = $"v{AppBase.VersionString[..AppBase.VersionString.LastIndexOf('.')]}";
3838
}
3939

4040
public async Task OpenAsync()
@@ -183,4 +183,9 @@ private async Task ResetSettingsAsync()
183183
AppSettingsProvider.RemoveSettings();
184184
Restart();
185185
}
186+
187+
private async Task OpenVersionHistory()
188+
{
189+
await DialogService.ShowAsync<VersionHistoryDialog>("");
190+
}
186191
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@using System.IO
2+
3+
<MudDialog>
4+
<TitleContent>
5+
@Lang["VersionHistory"]
6+
</TitleContent>
7+
<DialogContent>
8+
<MudMarkdown Value="@_value" />
9+
</DialogContent>
10+
<DialogActions>
11+
<MudButton OnClick="Close">@(Lang["Quit"])</MudButton>
12+
</DialogActions>
13+
</MudDialog>
14+
15+
@code
16+
{
17+
private string _value = null!;
18+
19+
[Inject]
20+
private IStringLocalizer<Lang> Lang { get; set; } = null!;
21+
22+
[CascadingParameter]
23+
private IMudDialogInstance MudDialog { get; set; } = null!;
24+
25+
private void Close() => MudDialog.Cancel();
26+
27+
protected override async Task OnInitializedAsync()
28+
{
29+
await base.OnInitializedAsync();
30+
const string markdownFileName = "VERSION_HISTORY.md";
31+
if (!File.Exists(markdownFileName))
32+
{
33+
_value = "什么也没找到\ud83d\ude01\ud83d\ude01";
34+
return;
35+
}
36+
_value = await File.ReadAllTextAsync(markdownFileName);
37+
}
38+
}

src/ComputerLock/ComputerLock.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Wpf" Version="8.0.100" />
2424
<PackageReference Include="ModernWpfUI" Version="0.9.6" />
2525
<PackageReference Include="MudBlazor" Version="8.2.0" />
26+
<PackageReference Include="MudBlazor.Markdown" Version="8.0.0" />
2627
</ItemGroup>
2728

2829
<ItemGroup>

src/ComputerLock/Configuration/AppBase.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics;
22
using System.IO;
3+
using System.Reflection;
34

45
namespace ComputerLock.Configuration;
56
internal class AppBase
@@ -20,5 +21,14 @@ internal class AppBase
2021
/// </summary>
2122
public static string ConfigPath { get; } = Path.Combine(DataPath, FriendlyName, "config.json");
2223

23-
public static string Version { get; } = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString();
24+
/// <summary>
25+
/// 版本文件路径
26+
/// </summary>
27+
public static string VersionFilePath { get; } = Path.Combine(DataPath, FriendlyName, "version");
28+
29+
/// <summary>
30+
/// 版本号
31+
/// </summary>
32+
public static Version Version { get; } = Assembly.GetExecutingAssembly().GetName().Version ?? throw new InvalidOperationException("App Version");
33+
public static string VersionString { get; } = Version.ToString();
2434
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.IO;
2+
3+
namespace ComputerLock.Platforms;
4+
5+
internal class VersionLogChecker(Version currentVersion, string versionFilePath)
6+
{
7+
// 检查是否需要展示更新日志
8+
public async Task<bool> CheckShowUpdateLogAsync()
9+
{
10+
var previousVersion = await GetPreviousVersionAsync();
11+
12+
if (currentVersion <= previousVersion)
13+
{
14+
return false;
15+
}
16+
17+
// 目前的逻辑是只自动显示一次更新信息,所以这里直接更新版本信息
18+
await SaveCurrentVersionAsync(currentVersion);
19+
return true;
20+
}
21+
22+
// 读取上次保存的版本号
23+
private async Task<Version> GetPreviousVersionAsync()
24+
{
25+
if (File.Exists(versionFilePath))
26+
{
27+
string versionText = await File.ReadAllTextAsync(versionFilePath);
28+
if (Version.TryParse(versionText, out var savedVersion))
29+
{
30+
return savedVersion;
31+
}
32+
}
33+
// 如果文件不存在或版本无效,则返回一个默认的低版本号
34+
return new Version("0.0.0.0");
35+
}
36+
37+
// 保存当前版本号到本地文件
38+
private async Task SaveCurrentVersionAsync(Version version)
39+
{
40+
string directory = Path.GetDirectoryName(versionFilePath) ?? throw new InvalidOperationException("versionFilePath");
41+
if (!Directory.Exists(directory))
42+
{
43+
Directory.CreateDirectory(directory);
44+
}
45+
await File.WriteAllTextAsync(versionFilePath, version.ToString());
46+
}
47+
}

src/ComputerLock/Resources/Lang.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ComputerLock/Resources/Lang.en.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,7 @@
366366
<data name="UseLockHotkey" xml:space="preserve">
367367
<value>Use Lock Hotkey</value>
368368
</data>
369+
<data name="VersionHistory" xml:space="preserve">
370+
<value>Version History</value>
371+
</data>
369372
</root>

src/ComputerLock/Resources/Lang.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,7 @@
346346
<data name="UseLockHotkey" xml:space="preserve">
347347
<value></value>
348348
</data>
349+
<data name="VersionHistory" xml:space="preserve">
350+
<value></value>
351+
</data>
349352
</root>

0 commit comments

Comments
 (0)