Skip to content

Commit b5bca46

Browse files
committed
*优化代码结构和可读性
1 parent c4a6d8d commit b5bca46

9 files changed

Lines changed: 170 additions & 269 deletions

File tree

Core.Window/ApplicationService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Core.Services.DeviceCommunication;
55
using Core.Services.Interfaces;
66
using Core.Services.MQTT;
7+
using Core.Services.Plugin;
78
using Core.Utils;
89
using Microsoft.Extensions.DependencyInjection;
910
using Microsoft.Win32;
@@ -146,10 +147,9 @@ public async Task<bool> CheckUpdate(bool toastIfNoUpdate) {
146147
try {
147148
var toastService = ServiceManager.Services.GetService<IToastService>()!;
148149
var tempPath = Path.Combine(Path.GetTempPath(), $"Kitopia_{latestVersion}_Installer.exe");
149-
150-
using var client = new HttpClient();
150+
151151
using var response =
152-
await client.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead);
152+
await PluginNetworkService.HttpClient.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead);
153153
response.EnsureSuccessStatusCode();
154154

155155
var totalBytes = response.Content.Headers.ContentLength ?? -1L;
@@ -193,7 +193,7 @@ public async Task<bool> CheckUpdate(bool toastIfNoUpdate) {
193193
progressToast.Fail($"下载出错: {ex.Message}", "更新失败");
194194
}
195195
else {
196-
ServiceManager.Services.GetService<IToastService>()!
196+
_ =ServiceManager.Services.GetService<IToastService>()!
197197
.Show("更新失败", $"下载出错: {ex.Message}", NotificationType.Error);
198198
}
199199
}

Core.Window/ClipboardWindow.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ public IReadOnlyList<string> GetFiles()
151151
if (Clipboard.ContainsFileDropList())
152152
{
153153
var list = Clipboard.GetFileDropList();
154-
foreach (string path in list)
154+
foreach (string? path in list)
155155
{
156+
if (string.IsNullOrEmpty(path)) {
157+
continue;
158+
}
156159
files.Add(path);
157160
}
158161
}

Core.Window/Core.Window.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@
5050
<PackageReference Include="Vanara.PInvoke.SHCore" Version="5.0.0" />
5151
<PackageReference Include="Vanara.Windows.Shell" Version="5.0.0" />
5252
</ItemGroup>
53-
<ItemGroup>
54-
<Folder Include="ScreenCapture\WGCTool\"/>
55-
</ItemGroup>
5653
<ItemGroup>
5754
<Compile Update="TopMostBorderWindow.axaml.cs">
5855
<DependentUpon>TopMostBorderWindow.axaml</DependentUpon>

Core.Window/GitHubUpdateService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class GitHubUpdateService
2525
if (!response.IsSuccessStatusCode)
2626
{
2727
Logger.Warning($"Failed to check for updates. Status code: {response.StatusCode}");
28-
ServiceManager.Services.GetService<IToastService>()!.Show("更新", $"无法检查更新,请检查网络连接。\nCode: {response.StatusCode}", NotificationType.Error);
28+
_ =ServiceManager.Services.GetService<IToastService>()!.Show("更新", $"无法检查更新,请检查网络连接。\nCode: {response.StatusCode}", NotificationType.Error);
2929
return (false, null, null, null);
3030
}
3131

@@ -35,14 +35,14 @@ public class GitHubUpdateService
3535

3636
if (release == null)
3737
{
38-
ServiceManager.Services .GetService<IToastService>()!.Show("更新", "无法检查更新,未找到版本信息。", NotificationType.Error);
38+
_ =ServiceManager.Services .GetService<IToastService>()!.Show("更新", "无法检查更新,未找到版本信息。", NotificationType.Error);
3939
return (false, null, null, null);
4040
}
4141

4242
var tagName = release["tag_name"]?.ToString();
4343
if (string.IsNullOrEmpty(tagName))
4444
{
45-
ServiceManager.Services.GetService<IToastService>()!.Show("更新", "无法检查更新,未找到版本信息。", NotificationType.Error);
45+
_ =ServiceManager.Services.GetService<IToastService>()!.Show("更新", "无法检查更新,未找到版本信息。", NotificationType.Error);
4646
return (false, null, null, null);
4747
}
4848

@@ -52,7 +52,7 @@ public class GitHubUpdateService
5252
if (!Version.TryParse(ServiceManager.Version , out var currentVersion))
5353
{
5454
Logger.Warning($"Failed to parse current version: {ServiceManager.Version }");
55-
ServiceManager.Services.GetService<IToastService>()!.Show("更新", "无法检查更新,当前版本信息格式错误。", NotificationType.Error);
55+
_ =ServiceManager.Services.GetService<IToastService>()!.Show("更新", "无法检查更新,当前版本信息格式错误。", NotificationType.Error);
5656
return (false, null, null, null);
5757
}
5858

@@ -69,13 +69,13 @@ public class GitHubUpdateService
6969
else
7070
{
7171
Logger.Warning($"Failed to parse latest version: {cleanTagName}");
72-
ServiceManager.Services.GetService<IToastService>()!.Show("更新", "无法检查更新,版本信息格式错误。", NotificationType.Error);
72+
_ =ServiceManager.Services.GetService<IToastService>()!.Show("更新", "无法检查更新,版本信息格式错误。", NotificationType.Error);
7373
}
7474
return (false, null, null, null);
7575
}
7676
catch (Exception ex)
7777
{
78-
ServiceManager.Services.GetService<IToastService>()!.Show("更新", $"检查更新时出错: {ex.Message}", NotificationType.Error);
78+
_ =ServiceManager.Services.GetService<IToastService>()!.Show("更新", $"检查更新时出错: {ex.Message}", NotificationType.Error);
7979
Logger.Error(ex, "Error checking for updates");
8080
return (false, null, null, null);
8181
}

Core.Window/ScreenCapture/CaptureTool.cs

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

0 commit comments

Comments
 (0)