mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-31 21:03:43 +01:00
feat: Dalamud RPC service
A draft for a simple RPC service for Dalamud. Enables use of Dalamud URIs, to be added later.
This commit is contained in:
parent
62b9c1f2a1
commit
78ed4a2b01
12 changed files with 911 additions and 1 deletions
53
Dalamud/Networking/Pipes/Api/PluginLinkHandler.cs
Normal file
53
Dalamud/Networking/Pipes/Api/PluginLinkHandler.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using System.Linq;
|
||||
|
||||
using Dalamud.IoC;
|
||||
using Dalamud.IoC.Internal;
|
||||
using Dalamud.Networking.Pipes.Internal;
|
||||
using Dalamud.Plugin.Internal.Types;
|
||||
using Dalamud.Plugin.Services;
|
||||
|
||||
namespace Dalamud.Networking.Pipes.Api;
|
||||
|
||||
/// <inheritdoc cref="IPluginLinkHandler" />
|
||||
[PluginInterface]
|
||||
[ServiceManager.ScopedService]
|
||||
[ResolveVia<IPluginLinkHandler>]
|
||||
public class PluginLinkHandler : IInternalDisposableService, IPluginLinkHandler
|
||||
{
|
||||
private readonly LinkHandlerService linkHandler;
|
||||
private readonly LocalPlugin localPlugin;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginLinkHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="localPlugin">The plugin to bind this service to.</param>
|
||||
/// <param name="linkHandler">The central link handler.</param>
|
||||
internal PluginLinkHandler(LocalPlugin localPlugin, LinkHandlerService linkHandler)
|
||||
{
|
||||
this.linkHandler = linkHandler;
|
||||
this.localPlugin = localPlugin;
|
||||
|
||||
this.linkHandler.Register("plugin", this.HandleUri);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public event IPluginLinkHandler.PluginUriReceived? OnUriReceived;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void DisposeService()
|
||||
{
|
||||
this.OnUriReceived = null;
|
||||
this.linkHandler.Unregister("plugin", this.HandleUri);
|
||||
}
|
||||
|
||||
private void HandleUri(DalamudUri uri)
|
||||
{
|
||||
var target = uri.Path.Split("/").FirstOrDefault();
|
||||
if (target == null || !string.Equals(target, this.localPlugin.InternalName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.OnUriReceived?.Invoke(uri);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue