[Api13] Update ChatLinkHandler functions (#2322)

* Update ChatLinkHandler functions

- Move functions to IChatGui
- Switch CommandId to type Guid and generate them automatically

* Remove unused field
This commit is contained in:
Haselnussbomber 2025-08-04 03:07:21 +02:00 committed by GitHub
parent ecbb4053ce
commit 63e7cb25b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 74 additions and 77 deletions

View file

@ -13,8 +13,6 @@ using Dalamud.Data;
using Dalamud.Game.Gui;
using Dalamud.Game.Text;
using Dalamud.Game.Text.Sanitizer;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Internal.Windows.PluginInstaller;
@ -427,39 +425,6 @@ internal sealed class DalamudPluginInterface : IDalamudPluginInterface, IDisposa
#endregion
#region Chat Links
// TODO API9: Move to chatgui, don't allow passing own commandId
/// <summary>
/// Register a chat link handler.
/// </summary>
/// <param name="commandId">The ID of the command.</param>
/// <param name="commandAction">The action to be executed.</param>
/// <returns>Returns an SeString payload for the link.</returns>
public DalamudLinkPayload AddChatLinkHandler(uint commandId, Action<uint, SeString> commandAction)
{
return Service<ChatGui>.Get().AddChatLinkHandler(this.plugin.InternalName, commandId, commandAction);
}
/// <summary>
/// Remove a chat link handler.
/// </summary>
/// <param name="commandId">The ID of the command.</param>
public void RemoveChatLinkHandler(uint commandId)
{
Service<ChatGui>.Get().RemoveChatLinkHandler(this.plugin.InternalName, commandId);
}
/// <summary>
/// Removes all chat link handlers registered by the plugin.
/// </summary>
public void RemoveChatLinkHandler()
{
Service<ChatGui>.Get().RemoveChatLinkHandler(this.plugin.InternalName);
}
#endregion
#region Dependency Injection
/// <inheritdoc/>

View file

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading.Tasks;
@ -281,25 +281,6 @@ public interface IDalamudPluginInterface
/// <returns>directory with path of AppData/XIVLauncher/pluginConfig/PluginInternalName/loc.</returns>
string GetPluginLocDirectory();
/// <summary>
/// Register a chat link handler.
/// </summary>
/// <param name="commandId">The ID of the command.</param>
/// <param name="commandAction">The action to be executed.</param>
/// <returns>Returns an SeString payload for the link.</returns>
DalamudLinkPayload AddChatLinkHandler(uint commandId, Action<uint, SeString> commandAction);
/// <summary>
/// Remove a chat link handler.
/// </summary>
/// <param name="commandId">The ID of the command.</param>
void RemoveChatLinkHandler(uint commandId);
/// <summary>
/// Removes all chat link handlers registered by the plugin.
/// </summary>
void RemoveChatLinkHandler();
/// <summary>
/// Create a new object of the provided type using its default constructor, then inject objects and properties.
/// </summary>

View file

@ -102,8 +102,6 @@ internal class AutoUpdateManager : IServiceType
this.openInstallerWindowLinkTask =
Service<ChatGui>.GetAsync().ContinueWith(
chatGuiTask => chatGuiTask.Result.AddChatLinkHandler(
"Dalamud",
1001,
(_, _) =>
{
Service<DalamudInterface>.GetNullable()?.OpenPluginInstallerTo(PluginInstallerOpenKind.InstalledPlugins);

View file

@ -125,8 +125,6 @@ internal class PluginManager : IInternalDisposableService
this.openInstallerWindowPluginChangelogsLink =
Service<ChatGui>.GetAsync().ContinueWith(
chatGuiTask => chatGuiTask.Result.AddChatLinkHandler(
"Dalamud",
1003,
(_, _) =>
{
Service<DalamudInterface>.GetNullable()?.OpenPluginInstallerTo(

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using Dalamud.Game.Gui;
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
namespace Dalamud.Plugin.Services;
@ -82,7 +83,25 @@ public interface IChatGui
/// <summary>
/// Gets the dictionary of Dalamud Link Handlers.
/// </summary>
public IReadOnlyDictionary<(string PluginName, uint CommandId), Action<uint, SeString>> RegisteredLinkHandlers { get; }
public IReadOnlyDictionary<(string PluginName, Guid CommandId), Action<Guid, SeString>> RegisteredLinkHandlers { get; }
/// <summary>
/// Register a chat link handler.
/// </summary>
/// <param name="commandAction">The action to be executed.</param>
/// <returns>Returns an SeString payload for the link.</returns>
public DalamudLinkPayload AddChatLinkHandler(Action<Guid, SeString> commandAction);
/// <summary>
/// Remove a chat link handler.
/// </summary>
/// <param name="commandId">The ID of the command.</param>
public void RemoveChatLinkHandler(Guid commandId);
/// <summary>
/// Removes all chat link handlers registered by the plugin.
/// </summary>
public void RemoveChatLinkHandler();
/// <summary>
/// Queue a chat message. Dalamud will send queued messages on the next framework event.