2022-12-21 19:23:48 +00:00
|
|
|
|
using Dalamud.Logging;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
using Grpc.Net.Client;
|
2022-11-24 22:28:31 +00:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
2022-11-24 22:28:31 +00:00
|
|
|
|
namespace Pal.Client.Net
|
2022-10-23 02:38:58 +00:00
|
|
|
|
{
|
2022-12-21 19:23:48 +00:00
|
|
|
|
internal partial class RemoteApi : IDisposable
|
2022-10-23 02:38:58 +00:00
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
2022-12-21 19:23:48 +00:00
|
|
|
|
public static string RemoteUrl { get; } = "http://localhost:5145";
|
2022-10-23 02:38:58 +00:00
|
|
|
|
#else
|
2022-12-21 19:23:48 +00:00
|
|
|
|
public static string RemoteUrl { get; } = "https://pal.μ.tv";
|
2022-10-23 02:38:58 +00:00
|
|
|
|
#endif
|
2022-10-30 19:39:12 +00:00
|
|
|
|
private readonly string UserAgent = $"{typeof(RemoteApi).Assembly.GetName().Name?.Replace(" ", "")}/{typeof(RemoteApi).Assembly.GetName().Version?.ToString(2)}";
|
|
|
|
|
|
2022-11-24 22:28:31 +00:00
|
|
|
|
private readonly ILoggerFactory _grpcToPluginLogLoggerFactory = LoggerFactory.Create(builder => builder.AddProvider(new GrpcLoggerProvider()).AddFilter("Grpc", LogLevel.Trace));
|
|
|
|
|
|
2022-10-30 10:02:49 +00:00
|
|
|
|
private GrpcChannel? _channel;
|
2022-12-11 14:22:41 +00:00
|
|
|
|
private LoginInfo _loginInfo = new LoginInfo(null);
|
2022-11-02 20:28:33 +00:00
|
|
|
|
private bool _warnedAboutUpgrade = false;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2022-12-11 14:22:41 +00:00
|
|
|
|
public Configuration.AccountInfo? Account
|
2022-10-31 16:34:47 +00:00
|
|
|
|
{
|
2022-12-21 19:23:48 +00:00
|
|
|
|
get => Service.Configuration.Accounts.TryGetValue(RemoteUrl, out Configuration.AccountInfo? accountInfo) ? accountInfo : null;
|
2022-10-31 16:34:47 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != null)
|
2022-12-21 19:23:48 +00:00
|
|
|
|
Service.Configuration.Accounts[RemoteUrl] = value;
|
2022-10-31 16:34:47 +00:00
|
|
|
|
else
|
2022-12-21 19:23:48 +00:00
|
|
|
|
Service.Configuration.Accounts.Remove(RemoteUrl);
|
2022-10-31 16:34:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-11 14:22:41 +00:00
|
|
|
|
public Guid? AccountId => Account?.Id;
|
|
|
|
|
|
2022-11-24 06:24:45 +00:00
|
|
|
|
private string PartialAccountId =>
|
2022-12-11 14:22:41 +00:00
|
|
|
|
Account?.Id?.ToString()?.PadRight(14).Substring(0, 13) ?? "[no account id]";
|
2022-11-24 06:24:45 +00:00
|
|
|
|
|
2022-10-23 02:38:58 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2022-11-24 06:24:45 +00:00
|
|
|
|
PluginLog.Debug("Disposing gRPC channel");
|
2022-10-23 02:38:58 +00:00
|
|
|
|
_channel?.Dispose();
|
|
|
|
|
_channel = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|