PalacePal/Pal.Client/Net/RemoteApi.cs

50 lines
1.7 KiB
C#
Raw Normal View History

2022-12-21 19:23:48 +00:00
using Dalamud.Logging;
using Grpc.Net.Client;
2022-11-24 22:28:31 +00:00
using Microsoft.Extensions.Logging;
using System;
2023-02-11 20:10:45 +00:00
using Pal.Client.Extensions;
2022-11-24 22:28:31 +00:00
namespace Pal.Client.Net
{
2022-12-21 19:23:48 +00:00
internal partial class RemoteApi : IDisposable
{
#if DEBUG
2022-12-21 19:23:48 +00:00
public static string RemoteUrl { get; } = "http://localhost:5145";
#else
2022-12-21 19:23:48 +00:00
public static string RemoteUrl { get; } = "https://pal.μ.tv";
#endif
2023-02-10 19:48:14 +00:00
private readonly string _userAgent = $"{typeof(RemoteApi).Assembly.GetName().Name?.Replace(" ", "")}/{typeof(RemoteApi).Assembly.GetName().Version?.ToString(2)}";
2022-10-30 19:39:12 +00:00
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;
2023-02-10 19:48:14 +00:00
private LoginInfo _loginInfo = new(null);
2023-02-11 20:10:45 +00:00
private bool _warnedAboutUpgrade;
2022-12-11 14:22:41 +00:00
public Configuration.AccountInfo? Account
{
2022-12-21 19:23:48 +00:00
get => Service.Configuration.Accounts.TryGetValue(RemoteUrl, out Configuration.AccountInfo? accountInfo) ? accountInfo : null;
set
{
if (value != null)
2022-12-21 19:23:48 +00:00
Service.Configuration.Accounts[RemoteUrl] = value;
else
2022-12-21 19:23:48 +00:00
Service.Configuration.Accounts.Remove(RemoteUrl);
}
}
2022-12-11 14:22:41 +00:00
public Guid? AccountId => Account?.Id;
2023-02-11 20:10:45 +00:00
public string? PartialAccountId => Account?.Id?.ToPartialId();
2023-02-06 21:00:38 +00:00
private string FormattedPartialAccountId => PartialAccountId ?? "[no account id]";
public void Dispose()
{
PluginLog.Debug("Disposing gRPC channel");
_channel?.Dispose();
_channel = null;
}
}
}