fix transfer progress, add glamourer unlock by name, fix dtrbar, add to xlplugins main

This commit is contained in:
rootdarkarchon
2023-10-08 11:57:38 +02:00
parent 706aab5bb9
commit 864c76d258
8 changed files with 48 additions and 30 deletions

View File

@@ -30,7 +30,7 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
private readonly ICallGateSubscriber<GameObject?, string>? _glamourerGetAllCustomization;
private readonly ICallGateSubscriber<Character?, uint, object?> _glamourerRevert;
private readonly ICallGateSubscriber<string, uint, object?> _glamourerRevertByName;
private readonly ICallGateSubscriber<Character?, uint, bool> _glamourerUnlock;
private readonly ICallGateSubscriber<string, uint, bool> _glamourerUnlock;
private readonly ICallGateSubscriber<(int, int)> _heelsGetApiVersion;
private readonly ICallGateSubscriber<string> _heelsGetOffset;
private readonly ICallGateSubscriber<string, object?> _heelsOffsetUpdate;
@@ -113,7 +113,7 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
_glamourerApplyAll = pi.GetIpcSubscriber<string, GameObject?, uint, object>("Glamourer.ApplyAllToCharacterLock");
_glamourerRevert = pi.GetIpcSubscriber<Character?, uint, object?>("Glamourer.RevertCharacterLock");
_glamourerRevertByName = pi.GetIpcSubscriber<string, uint, object?>("Glamourer.RevertLock");
_glamourerUnlock = pi.GetIpcSubscriber<Character?, uint, bool>("Glamourer.Unlock");
_glamourerUnlock = pi.GetIpcSubscriber<string, uint, bool>("Glamourer.UnlockName");
_heelsGetApiVersion = pi.GetIpcSubscriber<(int, int)>("SimpleHeels.ApiVersion");
_heelsGetOffset = pi.GetIpcSubscriber<string>("SimpleHeels.GetLocalPlayer");
@@ -248,8 +248,6 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
{
logger.LogDebug("[{appid}] Calling on IPC: GlamourerApplyAll", applicationId);
_glamourerApplyAll!.InvokeAction(customization, chara, LockCode);
logger.LogDebug("[{appid}] Calling on IPC: PenumbraRedraw", applicationId);
_penumbraRedrawObject.Invoke(chara, RedrawType.Redraw);
}
catch (Exception)
{
@@ -272,11 +270,19 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
await _redrawSemaphore.WaitAsync(token).ConfigureAwait(false);
await PenumbraRedrawInternalAsync(logger, handler, applicationId, (chara) =>
{
logger.LogDebug("[{appid}] Calling On IPC: GlamourerRevert", applicationId);
_glamourerRevert.InvokeAction(chara, LockCode);
logger.LogDebug("[{appid}] Calling On IPC: PenumbraRedraw", applicationId);
_penumbraRedrawObject.Invoke(chara, RedrawType.AfterGPose);
_glamourerUnlock.InvokeFunc(chara, LockCode);
try
{
logger.LogDebug("[{appid}] Calling On IPC: GlamourerUnlockName", applicationId);
_glamourerUnlock.InvokeFunc(handler.Name, LockCode);
logger.LogDebug("[{appid}] Calling On IPC: GlamourerRevert", applicationId);
_glamourerRevert.InvokeAction(chara, LockCode);
logger.LogDebug("[{appid}] Calling On IPC: PenumbraRedraw", applicationId);
_penumbraRedrawObject.Invoke(chara, RedrawType.AfterGPose);
}
catch (Exception ex)
{
logger.LogWarning(ex, "[{appid}] Error during GlamourerRevert", applicationId);
}
}).ConfigureAwait(false);
}
@@ -293,6 +299,8 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
{
logger.LogDebug("[{appid}] Calling On IPC: GlamourerRevertByName", applicationId);
_glamourerRevertByName.InvokeAction(name, LockCode);
logger.LogDebug("[{appid}] Calling On IPC: GlamourerUnlockName", applicationId);
_glamourerUnlock.InvokeAction(name, LockCode);
}
catch (Exception ex)
{

View File

@@ -218,7 +218,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
Logger.LogDebug("[{applicationId}] Applying Customization Data for {handler}", applicationId, handler);
await _dalamudUtil.WaitWhileCharacterIsDrawing(Logger, handler, applicationId, 30000, token).ConfigureAwait(false);
token.ThrowIfCancellationRequested();
foreach (var change in changes.Value)
foreach (var change in changes.Value.OrderBy(p => (int)p))
{
Logger.LogDebug("[{applicationId}] Processing {change} for {handler}", applicationId, change, handler);
switch (change)
@@ -249,22 +249,20 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
case PlayerChanges.Glamourer:
if (charaData.GlamourerData.TryGetValue(changes.Key, out var glamourerData))
{
alreadyRedrawn = true;
await _ipcManager.GlamourerApplyAllAsync(Logger, handler, glamourerData, applicationId, token).ConfigureAwait(false);
}
break;
case PlayerChanges.ModFiles:
case PlayerChanges.ModManip:
if (!alreadyRedrawn)
{
alreadyRedrawn = true;
await _ipcManager.PenumbraRedrawAsync(Logger, handler, applicationId, token).ConfigureAwait(false);
}
break;
}
token.ThrowIfCancellationRequested();
}
if (changes.Value.Contains(PlayerChanges.ModFiles) || changes.Value.Contains(PlayerChanges.ModManip) || changes.Value.Contains(PlayerChanges.Glamourer))
await _ipcManager.PenumbraRedrawAsync(Logger, handler, applicationId, token).ConfigureAwait(false);
}
finally
{

View File

@@ -49,7 +49,6 @@ public sealed class Plugin : IDalamudPlugin
// add mare related singletons
collection.AddSingleton<MareMediator>();
collection.AddSingleton<FileCacheManager>();
collection.AddSingleton<DalamudContextMenu>();
collection.AddSingleton<ServerConfigurationManager>();
collection.AddSingleton<PairManager>();
collection.AddSingleton<ApiController>();

View File

@@ -33,6 +33,7 @@ public sealed class UiService : DisposableMediatorSubscriberBase
_dalamudPluginInterface.UiBuilder.DisableGposeUiHide = true;
_dalamudPluginInterface.UiBuilder.Draw += Draw;
_dalamudPluginInterface.UiBuilder.OpenConfigUi += ToggleUi;
_dalamudPluginInterface.UiBuilder.OpenMainUi += ToggleMainUi;
foreach (var window in windows)
{
@@ -59,6 +60,14 @@ public sealed class UiService : DisposableMediatorSubscriberBase
}
public void ToggleUi()
{
if (_mareConfigService.Current.HasValidSetup())
Mediator.Publish(new UiToggleMessage(typeof(SettingsUi)));
else
Mediator.Publish(new UiToggleMessage(typeof(IntroUi)));
}
public void ToggleMainUi()
{
if (_mareConfigService.Current.HasValidSetup())
Mediator.Publish(new UiToggleMessage(typeof(CompactUi)));

View File

@@ -18,7 +18,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
private readonly IDtrBar _dtrBar;
private readonly ConfigurationServiceBase<MareConfig> _configService;
private readonly MareMediator _mareMediator;
private Lazy<DtrBarEntry> _entry;
private readonly Lazy<DtrBarEntry> _entry;
private readonly PairManager _pairManager;
private Task? _runTask;
private string? _text;
@@ -40,6 +40,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
{
_logger.LogDebug("Disposing DtrEntry");
Clear();
_entry.Value.Dispose();
}
}
@@ -68,6 +69,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
private DtrBarEntry CreateEntry()
{
_logger.LogTrace("Creating new DtrBar entry");
var entry = _dtrBar.Get("Mare Synchronos");
entry.OnClick = () => _mareMediator.Publish(new UiToggleMessage(typeof(CompactUi)));
@@ -77,13 +79,10 @@ public sealed class DtrEntry : IDisposable, IHostedService
private void Clear()
{
if (!_entry.IsValueCreated) return;
_text = null;
_logger.LogInformation("Clearing entry");
_text = null;
_entry.Value.Shown = false;
_entry.Value.Text = null;
_entry.Value.Dispose();
_entry = new(CreateEntry);
}
private async Task RunAsync()
@@ -138,6 +137,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
text = "\uE044 \uE04C";
tooltip = "Mare Synchronos: Not Connected";
}
if (!string.Equals(text, _text, StringComparison.Ordinal))
{
_text = text;

View File

@@ -121,7 +121,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
Logger.LogDebug("Downloading {requestUrl} for request {id}", requestUrl, requestId);
try
{
response = await _orchestrator.SendRequestAsync(HttpMethod.Get, requestUrl, ct).ConfigureAwait(false);
response = await _orchestrator.SendRequestAsync(HttpMethod.Get, requestUrl, ct, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
}
catch (HttpRequestException ex)
@@ -142,7 +142,8 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
var buffer = new byte[bufferSize];
var bytesRead = 0;
while ((bytesRead = await (await response.Content.ReadAsStreamAsync(ct).ConfigureAwait(false)).ReadAsync(buffer, ct).ConfigureAwait(false)) > 0)
var stream = await response.Content.ReadAsStreamAsync(ct).ConfigureAwait(false);
while ((bytesRead = await stream.ReadAsync(buffer, ct).ConfigureAwait(false)) > 0)
{
ct.ThrowIfCancellationRequested();

View File

@@ -71,10 +71,11 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
_downloadReady.Remove(guid, out _);
}
public async Task<HttpResponseMessage> SendRequestAsync(HttpMethod method, Uri uri, CancellationToken? ct = null)
public async Task<HttpResponseMessage> SendRequestAsync(HttpMethod method, Uri uri,
CancellationToken? ct = null, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead)
{
using var requestMessage = new HttpRequestMessage(method, uri);
return await SendRequestInternalAsync(requestMessage, ct).ConfigureAwait(false);
return await SendRequestInternalAsync(requestMessage, ct, httpCompletionOption).ConfigureAwait(false);
}
public async Task<HttpResponseMessage> SendRequestAsync<T>(HttpMethod method, Uri uri, T content, CancellationToken ct) where T : class
@@ -108,7 +109,8 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
await _downloadSemaphore.WaitAsync(token).ConfigureAwait(false);
}
private async Task<HttpResponseMessage> SendRequestInternalAsync(HttpRequestMessage requestMessage, CancellationToken? ct = null)
private async Task<HttpResponseMessage> SendRequestInternalAsync(HttpRequestMessage requestMessage,
CancellationToken? ct = null, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead)
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _serverManager.GetToken());
@@ -125,8 +127,8 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
try
{
if (ct != null)
return await _httpClient.SendAsync(requestMessage, ct.Value).ConfigureAwait(false);
return await _httpClient.SendAsync(requestMessage).ConfigureAwait(false);
return await _httpClient.SendAsync(requestMessage, httpCompletionOption, ct.Value).ConfigureAwait(false);
return await _httpClient.SendAsync(requestMessage, httpCompletionOption).ConfigureAwait(false);
}
catch (Exception ex)
{

View File

@@ -409,12 +409,13 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
_initialized = false;
_healthCheckTokenSource?.Cancel();
Logger.LogInformation("Stopping existing connection");
await _hubFactory.DisposeHubAsync().ConfigureAwait(false);
Mediator.Publish(new DisconnectedMessage());
_mareHub = null;
_connectionDto = null;
}
await _hubFactory.DisposeHubAsync().ConfigureAwait(false);
ServerState = state;
}
}