Run PluginWatcher in lobby and fix accidental Mare API hijacking
This commit is contained in:
@@ -27,6 +27,7 @@ public class IpcProvider : IHostedService, IMediatorSubscriber
|
||||
|
||||
private bool _marePluginEnabled = false;
|
||||
private bool _impersonating = false;
|
||||
private readonly CancellationTokenSource _registerDelayCts = new();
|
||||
|
||||
public bool MarePluginEnabled => _marePluginEnabled;
|
||||
public bool ImpersonationActive => _impersonating;
|
||||
@@ -95,13 +96,32 @@ public class IpcProvider : IHostedService, IMediatorSubscriber
|
||||
{
|
||||
if (_mareConfig.Current.MareAPI)
|
||||
{
|
||||
var cancelToken = _registerDelayCts.Token;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
// Wait before registering to reduce the chance of a race condition
|
||||
await Task.Delay(500);
|
||||
|
||||
if (cancelToken.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
if (_marePluginEnabled)
|
||||
{
|
||||
_logger.LogDebug("Not registering MareSynchronos API: Mare plugin is loaded");
|
||||
return;
|
||||
}
|
||||
|
||||
_loadFileProviderMare?.RegisterFunc(LoadMcdf);
|
||||
_loadFileAsyncProviderMare?.RegisterFunc(LoadMcdfAsync);
|
||||
_handledGameAddressesMare?.RegisterFunc(GetHandledAddresses);
|
||||
_impersonating = true;
|
||||
_logger.LogDebug("Registered MareSynchronos API");
|
||||
}, cancelToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
_registerDelayCts.Cancel();
|
||||
if (_impersonating)
|
||||
{
|
||||
_loadFileProviderMare?.UnregisterFunc();
|
||||
_loadFileAsyncProviderMare?.UnregisterFunc();
|
||||
@@ -111,6 +131,7 @@ public class IpcProvider : IHostedService, IMediatorSubscriber
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -119,6 +140,7 @@ public class IpcProvider : IHostedService, IMediatorSubscriber
|
||||
_loadFileAsyncProvider?.UnregisterFunc();
|
||||
_handledGameAddresses?.UnregisterFunc();
|
||||
|
||||
_registerDelayCts.Cancel();
|
||||
if (_impersonating)
|
||||
{
|
||||
_loadFileProviderMare?.UnregisterFunc();
|
||||
|
||||
@@ -153,7 +153,6 @@ public class MarePlugin : MediatorSubscriberBase, IHostedService
|
||||
_runtimeServiceScope.ServiceProvider.GetRequiredService<NotificationService>();
|
||||
_runtimeServiceScope.ServiceProvider.GetRequiredService<ChatService>();
|
||||
_runtimeServiceScope.ServiceProvider.GetRequiredService<GuiHookService>();
|
||||
_runtimeServiceScope.ServiceProvider.GetRequiredService<PluginWatcherService>();
|
||||
|
||||
#if !DEBUG
|
||||
if (_mareConfigService.Current.LogLevel != LogLevel.Information)
|
||||
|
||||
@@ -197,6 +197,7 @@ public sealed class Plugin : IDalamudPlugin
|
||||
collection.AddScoped<ChatService>();
|
||||
collection.AddScoped<GuiHookService>();
|
||||
|
||||
collection.AddHostedService(p => p.GetRequiredService<PluginWatcherService>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<ConfigurationSaveService>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<MareMediator>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<NotificationService>());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Dalamud.Plugin;
|
||||
using MareSynchronos.Services.Mediator;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using CapturedPluginState = (string InternalName, System.Version Version, bool IsLoaded);
|
||||
|
||||
@@ -31,7 +32,7 @@ SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
public class PluginWatcherService : MediatorSubscriberBase
|
||||
public class PluginWatcherService : MediatorSubscriberBase, IHostedService
|
||||
{
|
||||
private readonly IDalamudPluginInterface _pluginInterface;
|
||||
|
||||
@@ -88,6 +89,17 @@ public class PluginWatcherService : MediatorSubscriberBase
|
||||
Update(publish: false);
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
Mediator.UnsubscribeAll(this);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public static PluginChangeMessage? GetInitialPluginState(IDalamudPluginInterface pi, string internalName)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user