fix(plugin): register UiBuilder.OpenConfigUi / OpenMainUi stubs
Dalamud's plugin validator flagged two issues on v0.1.0: - "The plugin does not register a config UI callback." - "The plugin does not register a main UI callback." v0.1.0 ships the RecipeData layer only - the actual SettingsWindow and MainWindow arrive with module 08 (UI). To pass validation and to give users a useful response when they click "Open Settings" or "Open Main" in the plugin installer, both callbacks now fire toast notifications via INotificationManager that point at the roadmap. The handlers wire up in the constructor right after the host build and unwire in DisposeAsync. INotificationManager joins the Block A Dalamud services in PluginHostDependencies + PluginHostFactory so the DI container also exposes it for later modules.
This commit is contained in:
+50
-6
@@ -1,15 +1,19 @@
|
|||||||
// Anvil plugin entry. Implements IAsyncDalamudPlugin so Dalamud awaits
|
// Anvil plugin entry. Implements IAsyncDalamudPlugin so Dalamud awaits
|
||||||
// LoadAsync before considering the plugin loaded. The constructor wires
|
// LoadAsync before considering the plugin loaded. The constructor wires
|
||||||
// the generic-host DI container synchronously - Dalamud's IoC fills the
|
// the generic-host DI container synchronously - Dalamud's IoC fills the
|
||||||
// five Dalamud services as ctor args (Lightless pattern), the bundle is
|
// services as ctor args (Lightless pattern), the bundle is handed to
|
||||||
// handed to PluginHostFactory, and PluginLifecycle takes it from there.
|
// PluginHostFactory, and PluginLifecycle takes it from there.
|
||||||
//
|
//
|
||||||
// v0.1.0 is intentionally thin. Module 02+ extends PluginHostFactory's
|
// v0.1.0 ships the RecipeData layer only. The OpenConfigUi / OpenMainUi
|
||||||
// services collection; this file does not need to change.
|
// callbacks fire toast notifications so Dalamud's plugin validator stops
|
||||||
|
// complaining about missing UI callbacks while module 08 (the actual
|
||||||
|
// windows) is still under construction. The callbacks will be replaced
|
||||||
|
// once the SettingsWindow + MainWindow land.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Dalamud.Interface.ImGuiNotification;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@@ -18,6 +22,8 @@ namespace Anvil;
|
|||||||
|
|
||||||
public sealed class Plugin : IAsyncDalamudPlugin
|
public sealed class Plugin : IAsyncDalamudPlugin
|
||||||
{
|
{
|
||||||
|
private readonly IDalamudPluginInterface _pluginInterface;
|
||||||
|
private readonly INotificationManager _notification;
|
||||||
private readonly PluginLifecycle _lifecycle;
|
private readonly PluginLifecycle _lifecycle;
|
||||||
|
|
||||||
public Plugin(
|
public Plugin(
|
||||||
@@ -25,20 +31,30 @@ public sealed class Plugin : IAsyncDalamudPlugin
|
|||||||
IPluginLog pluginLog,
|
IPluginLog pluginLog,
|
||||||
IDataManager dataManager,
|
IDataManager dataManager,
|
||||||
IFramework framework,
|
IFramework framework,
|
||||||
ISelfTestRegistry selfTestRegistry
|
ISelfTestRegistry selfTestRegistry,
|
||||||
|
INotificationManager notification
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
_pluginInterface = pluginInterface;
|
||||||
|
_notification = notification;
|
||||||
|
|
||||||
var dependencies = new PluginHostDependencies(
|
var dependencies = new PluginHostDependencies(
|
||||||
pluginInterface,
|
pluginInterface,
|
||||||
pluginLog,
|
pluginLog,
|
||||||
dataManager,
|
dataManager,
|
||||||
framework,
|
framework,
|
||||||
selfTestRegistry
|
selfTestRegistry,
|
||||||
|
notification
|
||||||
);
|
);
|
||||||
|
|
||||||
var host = PluginHostFactory.Build(this, dependencies);
|
var host = PluginHostFactory.Build(this, dependencies);
|
||||||
_lifecycle = host.Services.GetRequiredService<PluginLifecycle>();
|
_lifecycle = host.Services.GetRequiredService<PluginLifecycle>();
|
||||||
_lifecycle.Host = host;
|
_lifecycle.Host = host;
|
||||||
|
|
||||||
|
// Stub UI callbacks. The validator accepts any subscription;
|
||||||
|
// the toasts are user-facing placeholders until module 08 lands.
|
||||||
|
_pluginInterface.UiBuilder.OpenConfigUi += OpenConfigUiStub;
|
||||||
|
_pluginInterface.UiBuilder.OpenMainUi += OpenMainUiStub;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task LoadAsync(CancellationToken cancellationToken) =>
|
public Task LoadAsync(CancellationToken cancellationToken) =>
|
||||||
@@ -46,6 +62,34 @@ public sealed class Plugin : IAsyncDalamudPlugin
|
|||||||
|
|
||||||
public async ValueTask DisposeAsync()
|
public async ValueTask DisposeAsync()
|
||||||
{
|
{
|
||||||
|
_pluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUiStub;
|
||||||
|
_pluginInterface.UiBuilder.OpenMainUi -= OpenMainUiStub;
|
||||||
await _lifecycle.DisposeAsync().ConfigureAwait(false);
|
await _lifecycle.DisposeAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OpenConfigUiStub()
|
||||||
|
{
|
||||||
|
_notification.AddNotification(
|
||||||
|
new Notification
|
||||||
|
{
|
||||||
|
Title = "Anvil",
|
||||||
|
Content =
|
||||||
|
"Settings window arrives with module 08 (UI). Track the roadmap on the Hellion Forge Gitea repo.",
|
||||||
|
Type = NotificationType.Info,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OpenMainUiStub()
|
||||||
|
{
|
||||||
|
_notification.AddNotification(
|
||||||
|
new Notification
|
||||||
|
{
|
||||||
|
Title = "Anvil",
|
||||||
|
Content =
|
||||||
|
"Main window arrives with module 08 (UI). v0.1.0 ships the RecipeData layer only.",
|
||||||
|
Type = NotificationType.Info,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,6 @@ internal sealed record PluginHostDependencies(
|
|||||||
IPluginLog PluginLog,
|
IPluginLog PluginLog,
|
||||||
IDataManager DataManager,
|
IDataManager DataManager,
|
||||||
IFramework Framework,
|
IFramework Framework,
|
||||||
ISelfTestRegistry SelfTestRegistry
|
ISelfTestRegistry SelfTestRegistry,
|
||||||
|
INotificationManager Notification
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ internal static class PluginHostFactory
|
|||||||
services.AddSingleton(dependencies.DataManager);
|
services.AddSingleton(dependencies.DataManager);
|
||||||
services.AddSingleton(dependencies.Framework);
|
services.AddSingleton(dependencies.Framework);
|
||||||
services.AddSingleton(dependencies.SelfTestRegistry);
|
services.AddSingleton(dependencies.SelfTestRegistry);
|
||||||
|
services.AddSingleton(dependencies.Notification);
|
||||||
|
|
||||||
// Self-reference. Lets services that genuinely need the plugin
|
// Self-reference. Lets services that genuinely need the plugin
|
||||||
// back-ref (later modules; v0.1.0 has none) reach it without a
|
// back-ref (later modules; v0.1.0 has none) reach it without a
|
||||||
|
|||||||
Reference in New Issue
Block a user