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();
|
||||
}
|
||||
}
|
@@ -3,8 +3,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using BITKit.Core.Entites;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BITKit;
|
||||
/// <summary>
|
||||
@@ -29,11 +31,28 @@ public partial class Entity : Node,IEntity
|
||||
/// IEntity.Id实现
|
||||
/// </summary>
|
||||
public ulong Id { get; private set; }
|
||||
|
||||
public CancellationToken CancellationToken => _cancellationTokenSource.Token;
|
||||
private CancellationTokenSource _cancellationTokenSource;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 服务提供者
|
||||
/// </summary>
|
||||
public IServiceProvider ServiceProvider { get; private set; }
|
||||
private IServiceCollection _serviceCollection;
|
||||
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
_cancellationTokenSource.Cancel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载所有EntityComponent的内部实现
|
||||
/// </summary>
|
||||
@@ -46,7 +65,6 @@ public partial class Entity : Node,IEntity
|
||||
_serviceCollection = new ServiceCollection();
|
||||
_serviceCollection.AddLogging();
|
||||
|
||||
|
||||
foreach (var x in MathNode.GetAllNode(this))
|
||||
{
|
||||
GetInstanceId();
|
||||
|
@@ -14,4 +14,5 @@ public partial class EntityComponent : Node,IEntityComponent
|
||||
public virtual void BuildService(IServiceCollection serviceCollection){}
|
||||
public virtual void OnStart(){}
|
||||
public virtual void OnAwake(){}
|
||||
|
||||
}
|
||||
|
41
BITKit/Scripts/UX/UXApplicationService.cs
Normal file
41
BITKit/Scripts/UX/UXApplicationService.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using BITKit.Apps;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace BITKit;
|
||||
|
||||
public partial class UXApplicationService : EntityComponent
|
||||
|
||||
{
|
||||
[Export] private Label currentVersionLabel;
|
||||
[Export] private Label latestVersionLabel;
|
||||
[Export] private Button downloadLatestButton;
|
||||
|
||||
private IApplicationService _service;
|
||||
public override void OnAwake()
|
||||
{
|
||||
_service = Entity.ServiceProvider.GetRequiredService<IApplicationService>();
|
||||
|
||||
downloadLatestButton.Hide();
|
||||
|
||||
downloadLatestButton.Pressed += () =>
|
||||
{
|
||||
OS.ShellOpen(_service.DownloadLatestUrl);
|
||||
};
|
||||
|
||||
_service.OnClientVersionCheck += x =>
|
||||
{
|
||||
currentVersionLabel.Text = x;
|
||||
};
|
||||
_service.OnLatestVersionCheck += x =>
|
||||
{
|
||||
latestVersionLabel.Text = x;
|
||||
};
|
||||
_service.OnDetectedLatestVersion += () =>
|
||||
{
|
||||
downloadLatestButton.Show();
|
||||
};
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user