breakpoint
This commit is contained in:
63
BITKit/Scripts/Application/GodotBasedApplicationService.cs
Normal file
63
BITKit/Scripts/Application/GodotBasedApplicationService.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Net.Http;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Godot;
|
||||
using IDIS;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BITKit.Apps;
|
||||
|
||||
public partial class GodotBasedApplicationService:EntityComponent, IApplicationService
|
||||
{
|
||||
private static readonly System.Net.Http.HttpClient _httpClient = new();
|
||||
[Export] public string DownloadLatestUrl { get; set; }
|
||||
[Export] public string CheckLatestVersionUrl { get; set; }
|
||||
|
||||
public event Action<string> OnClientVersionCheck;
|
||||
public event Action<string> OnLatestVersionCheck;
|
||||
public event Action<string> OnDownloadLatest;
|
||||
public event Action<float> OnDownloadProgress;
|
||||
public event Action<string> OnDownloadComplete;
|
||||
public event Action OnDetectedLatestVersion;
|
||||
|
||||
private ILogger<IApplicationService> _logger;
|
||||
|
||||
public override void BuildService(IServiceCollection serviceCollection)
|
||||
{
|
||||
serviceCollection.AddSingleton<IApplicationService>(this);
|
||||
|
||||
}
|
||||
public override async void OnStart()
|
||||
{
|
||||
_logger = Entity.ServiceProvider.GetRequiredService<ILogger<IApplicationService>>();
|
||||
|
||||
var clientVersion = ProjectSettings.GetSetting("application/config/version").AsString();
|
||||
|
||||
_logger.LogInformation($"当前版本:{clientVersion}");
|
||||
|
||||
OnClientVersionCheck?.Invoke(clientVersion);
|
||||
|
||||
var response =await _httpClient.GetAsync(CheckLatestVersionUrl,Entity.CancellationToken);
|
||||
if (response.IsSuccessStatusCode is false)
|
||||
{
|
||||
throw new HttpRequestException(response.StatusCode.ToString());
|
||||
}
|
||||
var version =await response.Content.ReadAsStringAsync(Entity.CancellationToken);
|
||||
|
||||
OnLatestVersionCheck?.Invoke(version);
|
||||
|
||||
if (clientVersion != version)
|
||||
{
|
||||
OnDetectedLatestVersion?.Invoke();
|
||||
}
|
||||
|
||||
_logger.LogInformation($"最新版本:{version}");
|
||||
}
|
||||
|
||||
public UniTask<string> DownloadLatestVersionAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user