api10 todo: refactor InstalledPluginState into an interface, add functions to open UI

This commit is contained in:
goat 2024-06-29 00:18:33 +02:00
parent c6243cd3de
commit 2565f2c3c6
3 changed files with 92 additions and 10 deletions

View file

@ -202,7 +202,8 @@ public sealed class DalamudPluginInterface : IDalamudPluginInterface, IDisposabl
/// <summary>
/// Gets a list of installed plugins along with their current state.
/// </summary>
public IEnumerable<InstalledPluginState> InstalledPlugins => Service<PluginManager>.Get().InstalledPlugins.Select(p => new InstalledPluginState(p.Name, p.Manifest.InternalName, p.IsLoaded, p.EffectiveVersion));
public IEnumerable<IExposedPlugin> InstalledPlugins =>
Service<PluginManager>.Get().InstalledPlugins.Select(p => new ExposedPlugin(p));
/// <summary>
/// Gets the <see cref="UiBuilder"/> internal implementation.

View file

@ -155,7 +155,7 @@ public interface IDalamudPluginInterface
/// <summary>
/// Gets a list of installed plugins along with their current state.
/// </summary>
IEnumerable<InstalledPluginState> InstalledPlugins { get; }
IEnumerable<IExposedPlugin> InstalledPlugins { get; }
/// <summary>
/// Opens the <see cref="PluginInstallerWindow"/> with the plugin name set as search target.

View file

@ -1,13 +1,94 @@
using Dalamud.Utility;
using Dalamud.Plugin.Internal.Types;
namespace Dalamud.Plugin;
/// <summary>
/// State of an installed plugin.
/// Interface representing an installed plugin, to be exposed to other plugins.
/// </summary>
/// <param name="Name">The name of the plugin.</param>
/// <param name="InternalName">The internal name of the plugin.</param>
/// <param name="IsLoaded">Whether or not the plugin is loaded.</param>
/// <param name="Version">The version of the plugin.</param>
[Api10ToDo("Refactor into an interface, add wrappers for OpenMainUI and OpenConfigUI")]
public record InstalledPluginState(string Name, string InternalName, bool IsLoaded, Version Version);
public interface IExposedPlugin
{
/// <summary>
/// Gets the name of the plugin.
/// </summary>
string Name { get; }
/// <summary>
/// Gets the internal name of the plugin.
/// </summary>
string InternalName { get; }
/// <summary>
/// Gets a value indicating whether the plugin is loaded.
/// </summary>
bool IsLoaded { get; }
/// <summary>
/// Gets the version of the plugin.
/// </summary>
Version Version { get; }
/// <summary>
/// Gets a value indicating whether the plugin has a main UI.
/// </summary>
public bool HasMainUi { get; }
/// <summary>
/// Gets a value indicating whether the plugin has a config UI.
/// </summary>
public bool HasConfigUi { get; }
/// <summary>
/// Opens the main UI of the plugin.
/// Throws <see cref="InvalidOperationException"/> if <see cref="HasMainUi"/> is false.
/// </summary>
public void OpenMainUi();
/// <summary>
/// Opens the config UI of the plugin.
/// Throws <see cref="InvalidOperationException"/> if <see cref="HasConfigUi"/> is false.
/// </summary>
public void OpenConfigUi();
}
/// <summary>
/// Internal representation of an installed plugin, to be exposed to other plugins.
/// </summary>
/// <param name="plugin">The plugin.</param>
internal sealed class ExposedPlugin(LocalPlugin plugin) : IExposedPlugin
{
/// <inheritdoc/>
public string Name => plugin.Name;
/// <inheritdoc/>
public string InternalName => plugin.InternalName;
/// <inheritdoc/>
public bool IsLoaded => plugin.IsLoaded;
/// <inheritdoc/>
public Version Version => plugin.EffectiveVersion;
/// <inheritdoc/>
public bool HasMainUi => plugin.DalamudInterface?.LocalUiBuilder.HasMainUi ?? false;
/// <inheritdoc/>
public bool HasConfigUi => plugin.DalamudInterface?.LocalUiBuilder.HasMainUi ?? false;
/// <inheritdoc/>
public void OpenMainUi()
{
if (plugin.DalamudInterface?.LocalUiBuilder.HasMainUi == true)
plugin.DalamudInterface.LocalUiBuilder.OpenMain();
else
throw new InvalidOperationException("Plugin does not have a main UI.");
}
/// <inheritdoc/>
public void OpenConfigUi()
{
if (plugin.DalamudInterface?.LocalUiBuilder.HasConfigUi == true)
plugin.DalamudInterface.LocalUiBuilder.OpenConfig();
else
throw new InvalidOperationException("Plugin does not have a config UI.");
}
}