feat: add debug link handler as demo

This commit is contained in:
Kaz Wolfe 2025-11-18 16:28:03 -08:00
parent 01d8fc0c7e
commit 0d8f577576
No known key found for this signature in database
GPG key ID: 258813F53A16EBB4
2 changed files with 68 additions and 2 deletions

View file

@ -0,0 +1,67 @@
using Dalamud.Game.Gui.Toast;
using Dalamud.Interface.ImGuiNotification;
using Dalamud.Interface.ImGuiNotification.Internal;
using Dalamud.Networking.Rpc.Model;
namespace Dalamud.Networking.Rpc.Service.Links;
#if DEBUG
/// <summary>
/// A debug controller for link handling.
/// </summary>
[ServiceManager.EarlyLoadedService]
internal sealed class DebugLinkHandler : IInternalDisposableService
{
private readonly LinkHandlerService linkHandlerService;
/// <summary>
/// Initializes a new instance of the <see cref="DebugLinkHandler"/> class.
/// </summary>
/// <param name="linkHandler">Injected LinkHandler.</param>
[ServiceManager.ServiceConstructor]
public DebugLinkHandler(LinkHandlerService linkHandler)
{
this.linkHandlerService = linkHandler;
this.linkHandlerService.Register("debug", this.HandleLink);
}
/// <inheritdoc/>
public void DisposeService()
{
this.linkHandlerService.Unregister("debug", this.HandleLink);
}
private void HandleLink(DalamudUri uri)
{
var action = uri.Path.Split("/").GetValue(1)?.ToString();
switch (action)
{
case "toast":
this.ShowToast(uri);
break;
case "notification":
this.ShowNotification(uri);
break;
}
}
private void ShowToast(DalamudUri uri)
{
var message = uri.QueryParams.Get("message") ?? "Hello, world!";
Service<ToastGui>.Get().ShowNormal(message);
}
private void ShowNotification(DalamudUri uri)
{
Service<NotificationManager>.Get().AddNotification(
new Notification
{
Title = uri.QueryParams.Get("title"),
Content = uri.QueryParams.Get("content") ?? "Hello, world!",
});
}
}
#endif

View file

@ -4,13 +4,12 @@ using Dalamud.Console;
using Dalamud.IoC; using Dalamud.IoC;
using Dalamud.IoC.Internal; using Dalamud.IoC.Internal;
using Dalamud.Networking.Rpc.Model; using Dalamud.Networking.Rpc.Model;
using Dalamud.Networking.Rpc.Service;
using Dalamud.Plugin.Internal.Types; using Dalamud.Plugin.Internal.Types;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
#pragma warning disable DAL_RPC #pragma warning disable DAL_RPC
namespace Dalamud.Networking.Rpc.Api; namespace Dalamud.Networking.Rpc.Service.Links;
/// <inheritdoc cref="IPluginLinkHandler" /> /// <inheritdoc cref="IPluginLinkHandler" />
[PluginInterface] [PluginInterface]