diff --git a/HellionChat/Infrastructure/Hosting/InitHostedServices.cs b/HellionChat/Infrastructure/Hosting/InitHostedServices.cs index 9ffb54f..a957127 100644 --- a/HellionChat/Infrastructure/Hosting/InitHostedServices.cs +++ b/HellionChat/Infrastructure/Hosting/InitHostedServices.cs @@ -1,7 +1,9 @@ +using Dalamud.Game.Addon.Lifecycle; using Dalamud.Plugin; using HellionChat.Integrations; using HellionChat.Ipc; using HellionChat.Themes; +using HellionChat.Ui.Components; using Microsoft.Extensions.Hosting; namespace HellionChat.Infrastructure.Hosting; @@ -101,3 +103,41 @@ internal sealed class FailedTellNotifierInitHostedService(FailedTellNotifier not public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; } + +internal sealed class PayloadHandlerInitHostedService( + PayloadHandler payloadHandler, + MessageList messageList +) : IHostedService +{ + public async Task StartAsync(CancellationToken cancellationToken) + { + // §6.2 cycle-resolution: both singletons exist by the time HostedServices + // run, so this is the first safe point to wire the setter. + messageList.AttachPayloadHandler(payloadHandler); + + // IAddonLifecycle thread-affinity is not explicitly documented; wrap is + // defensive insurance — mirrors the window-registration RunOnFrameworkThread + // pattern established in PluginLifecycle.cs. + await Plugin.Framework.RunOnFrameworkThread(() => + { + Plugin.AddonLifecycle.RegisterListener( + AddonEvent.PostUpdate, + "ItemDetail", + payloadHandler.MoveTooltip + ); + Plugin.AddonLifecycle.RegisterListener( + AddonEvent.PostUpdate, + "ActionDetail", + payloadHandler.MoveTooltip + ); + }); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + await Plugin.Framework.RunOnFrameworkThread(() => + { + Plugin.AddonLifecycle.UnregisterListener(payloadHandler.MoveTooltip); + }); + } +} diff --git a/HellionChat/PluginHostFactory.cs b/HellionChat/PluginHostFactory.cs index f74f191..c74bc5d 100644 --- a/HellionChat/PluginHostFactory.cs +++ b/HellionChat/PluginHostFactory.cs @@ -312,6 +312,10 @@ internal static class PluginHostFactory sp.GetRequiredService() ) ); + services.AddHostedService(sp => new Infrastructure.Hosting.PayloadHandlerInitHostedService( + sp.GetRequiredService(), + sp.GetRequiredService() + )); } }