3283e51381
Move font handle creation from BuildFonts() into the FontManager ctor inside a single atlas.SuppressAutoRebuild() block. Axis, AxisItalic and FontAwesome become init-only IFontHandle properties; RegularFont and ItalicFont stay mutable so the live font-settings rebuild path keeps working without a plugin reload. - BuildFonts() renamed to RebuildDelegateFonts(), scope reduced to the delegate fonts only - BuildFontsAsync() removed; Task.Run had no purpose with ctor-init - FontManagerInitHostedService deleted; PluginHostFactory drops the matching AddHostedService registration - PluginHostFactory FontManager registration takes IDalamudPluginInterface via factory lambda - Settings save path now calls RebuildDelegateFonts() instead of BuildFonts() - Plugin.Draw push site gets a null-forgiving for the nullable RegularFont with a one-line WHY
88 lines
3.2 KiB
C#
88 lines
3.2 KiB
C#
using Dalamud.Plugin;
|
|
using HellionChat.Ipc;
|
|
using HellionChat.Themes;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
namespace HellionChat.Infrastructure.Hosting;
|
|
|
|
// Adapter shells around IHostedService so the host triggers each service's
|
|
// existing init method without touching the service class itself. Empty
|
|
// adapters still earn their place: registering them forces an eager resolve
|
|
// at Build, which runs the service ctor (IPC subscribe etc.) right then
|
|
// instead of lazily on first GetRequiredService.
|
|
|
|
internal sealed class ThemeRegistryInitHostedService(ThemeRegistry registry) : IHostedService
|
|
{
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
// Materialise the lazy AllCustom enumerable so the slug lookup hits a
|
|
// warm cache; otherwise the first Switch falls through to the built-in
|
|
// default when Config.Theme points at a custom slug.
|
|
foreach (var _ in registry.AllCustom()) { }
|
|
registry.Switch(Plugin.Config.Theme);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
}
|
|
|
|
// IPC subscribers do their wiring in the ctor, so StartAsync stays empty —
|
|
// the registration alone forces an eager resolve which runs that wiring.
|
|
|
|
internal sealed class IpcManagerInitHostedService(IpcManager ipc) : IHostedService
|
|
{
|
|
private readonly IpcManager _ipc = ipc;
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
}
|
|
|
|
internal sealed class TypingIpcInitHostedService(TypingIpc typingIpc) : IHostedService
|
|
{
|
|
private readonly TypingIpc _typingIpc = typingIpc;
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
}
|
|
|
|
internal sealed class ExtraChatInitHostedService(ExtraChat extraChat) : IHostedService
|
|
{
|
|
private readonly ExtraChat _extraChat = extraChat;
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
}
|
|
|
|
internal sealed class MessageManagerInitHostedService(
|
|
IDalamudPluginInterface pluginInterface,
|
|
MessageManager manager
|
|
) : IHostedService
|
|
{
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
// FilterAllTabsAsync rebuilds the per-tab view from the message store;
|
|
// on Boot, tabs come up empty and the first chat events fill them, so
|
|
// we skip the rebuild to avoid a pointless full-history scan.
|
|
if (pluginInterface.Reason is not PluginLoadReason.Boot)
|
|
manager.FilterAllTabsAsync();
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
}
|
|
|
|
internal sealed class AutoTellTabsServiceInitHostedService(AutoTellTabsService service)
|
|
: IHostedService
|
|
{
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
service.Initialize();
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
}
|