mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-09-06 05:36:53 +00:00
feat: Add auto-detect update feature.
This commit is contained in:
@@ -7,9 +7,9 @@ using ZonyLrcTools.Common.Updater.JsonModel;
|
||||
|
||||
namespace ZonyLrcTools.Common.Updater;
|
||||
|
||||
public class DefaultUpdater : ISingletonDependency
|
||||
public class DefaultUpdater : IUpdater, ISingletonDependency
|
||||
{
|
||||
public const string UpdateUrl = "https://api.zony.me/lrc-tools/update";
|
||||
public const string UpdateUrl = "https://api.myzony.com/lrc-tools/update";
|
||||
|
||||
private readonly IWarpHttpClient _warpHttpClient;
|
||||
private readonly ILogger<DefaultUpdater> _logger;
|
||||
@@ -23,7 +23,7 @@ public class DefaultUpdater : ISingletonDependency
|
||||
|
||||
public async Task CheckUpdateAsync()
|
||||
{
|
||||
var response = await _warpHttpClient.GetAsync<NewVersionResponse>(UpdateUrl);
|
||||
var response = await _warpHttpClient.GetAsync<NewVersionResponse?>(UpdateUrl);
|
||||
if (response == null)
|
||||
{
|
||||
return;
|
||||
@@ -35,13 +35,13 @@ public class DefaultUpdater : ISingletonDependency
|
||||
return;
|
||||
}
|
||||
|
||||
var importantItem = response.Items.FirstOrDefault(x => x.ItemType == NewVersionItemType.Important);
|
||||
var importantItem = response.Items?.FirstOrDefault(x => x.ItemType == NewVersionItemType.Important);
|
||||
if (importantItem != null)
|
||||
{
|
||||
_logger.LogWarning($"发现了新版本,请点击下面的链接进行更新:{importantItem.Url}");
|
||||
_logger.LogWarning($"最新版本号:{response.NewVersion},当前版本号: ${currentVersion}");
|
||||
_logger.LogWarning($"更新内容:{response.NewVersionDescription}");
|
||||
|
||||
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
Process.Start("explorer.exe", importantItem.Url);
|
||||
|
6
src/ZonyLrcTools.Common/Updater/IUpdater.cs
Normal file
6
src/ZonyLrcTools.Common/Updater/IUpdater.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace ZonyLrcTools.Common.Updater;
|
||||
|
||||
public interface IUpdater
|
||||
{
|
||||
Task CheckUpdateAsync();
|
||||
}
|
@@ -2,7 +2,7 @@ namespace ZonyLrcTools.Common.Updater.JsonModel;
|
||||
|
||||
public class NewVersionItem
|
||||
{
|
||||
public string Url { get; set; }
|
||||
public string? Url { get; set; }
|
||||
|
||||
public NewVersionItemType ItemType { get; set; }
|
||||
}
|
@@ -2,6 +2,6 @@ namespace ZonyLrcTools.Common.Updater.JsonModel;
|
||||
|
||||
public enum NewVersionItemType
|
||||
{
|
||||
Important,
|
||||
Important = 1,
|
||||
NormalBinaryFile
|
||||
}
|
@@ -2,11 +2,11 @@ namespace ZonyLrcTools.Common.Updater.JsonModel;
|
||||
|
||||
public class NewVersionResponse
|
||||
{
|
||||
public Version NewVersion { get; set; }
|
||||
public Version? NewVersion { get; set; }
|
||||
|
||||
public string NewVersionDescription { get; set; }
|
||||
public string? NewVersionDescription { get; set; }
|
||||
|
||||
public List<NewVersionItem> Items { get; set; }
|
||||
public List<NewVersionItem>? Items { get; set; }
|
||||
|
||||
public DateTime UpdateTime { get; set; }
|
||||
public DateTime? UpdateTime { get; set; }
|
||||
}
|
@@ -4,6 +4,7 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>4.0.0.49</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user