mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
feat: add debug link handler as demo
This commit is contained in:
parent
01d8fc0c7e
commit
0d8f577576
2 changed files with 68 additions and 2 deletions
67
Dalamud/Networking/Rpc/Service/Links/DebugLinkHandler.cs
Normal file
67
Dalamud/Networking/Rpc/Service/Links/DebugLinkHandler.cs
Normal 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
|
||||||
|
|
@ -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]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue