Use a proxy function for OnFrameworkUpdate

This commit is contained in:
Loporrit
2023-12-11 23:47:19 +00:00
parent de9532041e
commit 247008e13d
2 changed files with 16 additions and 2 deletions

View File

@@ -34,10 +34,21 @@ public sealed class Plugin : IDalamudPlugin
private readonly CancellationTokenSource _pluginCts = new(); private readonly CancellationTokenSource _pluginCts = new();
private readonly Task _hostBuilderRunTask; private readonly Task _hostBuilderRunTask;
public static Plugin Self;
public Action<IFramework> _realOnFrameworkUpdate = null;
// Proxy function in the LoporritSync namespace to avoid confusion in /xlstats
public void OnFrameworkUpdate(IFramework framework)
{
if (_realOnFrameworkUpdate != null)
_realOnFrameworkUpdate(framework);
}
public Plugin(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IDataManager gameData, public Plugin(DalamudPluginInterface pluginInterface, ICommandManager commandManager, IDataManager gameData,
IFramework framework, IObjectTable objectTable, IClientState clientState, ICondition condition, IChatGui chatGui, IFramework framework, IObjectTable objectTable, IClientState clientState, ICondition condition, IChatGui chatGui,
IGameGui gameGui, IDtrBar dtrBar, IPluginLog pluginLog, ITargetManager targetManager) IGameGui gameGui, IDtrBar dtrBar, IPluginLog pluginLog, ITargetManager targetManager)
{ {
Plugin.Self = this;
_hostBuilderRunTask = new HostBuilder() _hostBuilderRunTask = new HostBuilder()
.UseContentRoot(pluginInterface.ConfigDirectory.FullName) .UseContentRoot(pluginInterface.ConfigDirectory.FullName)
.ConfigureLogging(lb => .ConfigureLogging(lb =>

View File

@@ -291,7 +291,10 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
public Task StartAsync(CancellationToken cancellationToken) public Task StartAsync(CancellationToken cancellationToken)
{ {
_framework.Update += FrameworkOnUpdate; #pragma warning disable S2696 // Instance members should not write to "static" fields
LoporritSync.Plugin.Self._realOnFrameworkUpdate = this.FrameworkOnUpdate;
#pragma warning restore S2696
_framework.Update += LoporritSync.Plugin.Self.OnFrameworkUpdate;
if (IsLoggedIn) if (IsLoggedIn)
{ {
_classJobId = _clientState.LocalPlayer!.ClassJob.Id; _classJobId = _clientState.LocalPlayer!.ClassJob.Id;
@@ -305,7 +308,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
_logger.LogTrace("Stopping {type}", GetType()); _logger.LogTrace("Stopping {type}", GetType());
Mediator.UnsubscribeAll(this); Mediator.UnsubscribeAll(this);
_framework.Update -= FrameworkOnUpdate; _framework.Update -= LoporritSync.Plugin.Self.OnFrameworkUpdate;
return Task.CompletedTask; return Task.CompletedTask;
} }