diff --git a/src/Lumina.Domain.SharedKernel/Common/Enums/Plugins/PluginSettingType.cs b/src/Lumina.Domain.SharedKernel/Common/Enums/Plugins/PluginSettingType.cs new file mode 100644 index 00000000..364a0f8c --- /dev/null +++ b/src/Lumina.Domain.SharedKernel/Common/Enums/Plugins/PluginSettingType.cs @@ -0,0 +1,27 @@ +namespace Lumina.Domain.SharedKernel.Common.Enums.Plugins; + +/// +/// Enumeration for the types of a plugin setting. +/// +public enum PluginSettingType +{ + /// + /// A free-form single line text value. + /// + Text, + + /// + /// A numeric value. + /// + Number, + + /// + /// A boolean (true/false) value. + /// + Boolean, + + /// + /// A value selected from a list of allowed values. + /// + Select +} diff --git a/src/Lumina.Plugins.Contracts/Common/Models/DTO/Settings/PluginSettingDescriptorDto.cs b/src/Lumina.Plugins.Contracts/Common/Models/DTO/Settings/PluginSettingDescriptorDto.cs new file mode 100644 index 00000000..a3671b21 --- /dev/null +++ b/src/Lumina.Plugins.Contracts/Common/Models/DTO/Settings/PluginSettingDescriptorDto.cs @@ -0,0 +1,24 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.SharedKernel.Common.Enums.Plugins; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Plugins.Contracts.Common.Models.DTO.Settings; + +/// +/// Data transfer object describing a single setting of a plugin, used by the host to render the plugin settings page. +/// +/// The unique key of the setting, used to persist and retrieve its value. +/// The display label of the setting. +/// The type of the setting. +/// The optional default value of the setting, serialized as a string. +/// The list of allowed values, when the setting is a selection. +[DebuggerDisplay("Key: {Key}")] +public sealed record PluginSettingDescriptorDto( + string Key, + string Label, + PluginSettingType Type, + string? DefaultValue = null, + IReadOnlyList? AllowedValues = null +); diff --git a/src/Lumina.Plugins.Contracts/Core/Metadata/IRemoteMetadataProvider.cs b/src/Lumina.Plugins.Contracts/Core/Metadata/IRemoteMetadataProvider.cs new file mode 100644 index 00000000..c0d52ba1 --- /dev/null +++ b/src/Lumina.Plugins.Contracts/Core/Metadata/IRemoteMetadataProvider.cs @@ -0,0 +1,46 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Contracts.DTO.Common; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Plugins.Contracts.Core.Metadata; + +/// +/// Contract for a plugin that provides metadata for media items from a remote source. +/// +public interface IRemoteMetadataProvider +{ + /// + /// Gets the display name of the metadata provider. + /// + string Name { get; } + + /// + /// Gets the media library type this metadata provider supports. + /// + LibraryType SupportedLibraryType { get; } + + /// + /// Gets a value indicating whether this metadata provider requires access to the web to retrieve metadata. + /// + bool RequiresWebAccess { get; } + + /// + /// Searches for the metadata of the media item described by . + /// + /// The lookup describing the media item to search for. + /// Cancellation token that can be used to stop the execution. + /// The collection of metadata candidates found for the media item. + Task> GetSearchResultsAsync(MetadataLookupDto lookup, CancellationToken cancellationToken); + + /// + /// Gets the metadata of the media item described by . + /// + /// The lookup describing the media item to get the metadata for. + /// Cancellation token that can be used to stop the execution. + /// The metadata of the media item, or when no metadata was found. + Task GetMetadataAsync(MetadataLookupDto lookup, CancellationToken cancellationToken); +} diff --git a/src/Lumina.Plugins.Contracts/Core/Metadata/IRemoteMetadataProviderGeneric.cs b/src/Lumina.Plugins.Contracts/Core/Metadata/IRemoteMetadataProviderGeneric.cs new file mode 100644 index 00000000..85c292cb --- /dev/null +++ b/src/Lumina.Plugins.Contracts/Core/Metadata/IRemoteMetadataProviderGeneric.cs @@ -0,0 +1,46 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Contracts.DTO.Common; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Plugins.Contracts.Core.Metadata; + +/// +/// Contract for a plugin that provides metadata for media items from a remote source, typed to the media item lookup and metadata types. +/// +/// The type of the lookup describing the media item. +/// The type of the metadata of the media item. +public interface IRemoteMetadataProvider : IRemoteMetadataProvider + where TLookup : MetadataLookupDto + where TMetadata : MetadataDto +{ + /// + /// Searches for the metadata of the media item described by . + /// + /// The lookup describing the media item to search for. + /// Cancellation token that can be used to stop the execution. + /// The collection of metadata candidates found for the media item. + Task> GetSearchResultsAsync(TLookup lookup, CancellationToken cancellationToken); + + /// + /// Gets the metadata of the media item described by . + /// + /// The lookup describing the media item to get the metadata for. + /// Cancellation token that can be used to stop the execution. + /// The metadata of the media item, or when no metadata was found. + Task GetMetadataAsync(TLookup lookup, CancellationToken cancellationToken); + + /// + async Task> IRemoteMetadataProvider.GetSearchResultsAsync(MetadataLookupDto lookup, CancellationToken cancellationToken) + { + return await GetSearchResultsAsync((TLookup)lookup, cancellationToken).ConfigureAwait(false); + } + + /// + async Task IRemoteMetadataProvider.GetMetadataAsync(MetadataLookupDto lookup, CancellationToken cancellationToken) + { + return await GetMetadataAsync((TLookup)lookup, cancellationToken).ConfigureAwait(false); + } +} diff --git a/src/Lumina.Plugins.Contracts/Core/Plugins/IPlugin.cs b/src/Lumina.Plugins.Contracts/Core/Plugins/IPlugin.cs new file mode 100644 index 00000000..0947c6fa --- /dev/null +++ b/src/Lumina.Plugins.Contracts/Core/Plugins/IPlugin.cs @@ -0,0 +1,44 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Plugins.Contracts.Common.Models.DTO.Settings; +using System; +using System.Collections.Generic; +#endregion + +namespace Lumina.Plugins.Contracts.Core.Plugins; + +/// +/// Contract for a Lumina plugin. +/// +public interface IPlugin +{ + /// + /// Gets the stable unique identifier of the plugin, used to persist its state. + /// + Guid Id { get; } + + /// + /// Gets the display name of the plugin. + /// + string Name { get; } + + /// + /// Gets the author of the plugin. + /// + string Author { get; } + + /// + /// Gets the version of the plugin. + /// + Version Version { get; } + + /// + /// Gets the description of the plugin. + /// + string Description { get; } + + /// + /// Gets the settings schema of the plugin, used by the host to render the plugin settings page. + /// + /// The collection of setting descriptors declared by the plugin. + IReadOnlyList GetSettingsSchema(); +} diff --git a/src/Lumina.Plugins.Contracts/Core/Plugins/IPluginServiceRegistrator.cs b/src/Lumina.Plugins.Contracts/Core/Plugins/IPluginServiceRegistrator.cs new file mode 100644 index 00000000..9636562e --- /dev/null +++ b/src/Lumina.Plugins.Contracts/Core/Plugins/IPluginServiceRegistrator.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using Microsoft.Extensions.DependencyInjection; +#endregion + +namespace Lumina.Plugins.Contracts.Core.Plugins; + +/// +/// Contract for registering the services of a plugin into the host dependency injection container. +/// +public interface IPluginServiceRegistrator +{ + /// + /// Registers the services of the plugin into the host dependency injection container. + /// + /// The service collection to which the plugin services are added. + void RegisterServices(IServiceCollection services); +} diff --git a/src/Lumina.Plugins.Contracts/Core/Plugins/IPluginSettingsStore.cs b/src/Lumina.Plugins.Contracts/Core/Plugins/IPluginSettingsStore.cs new file mode 100644 index 00000000..e3b6dac2 --- /dev/null +++ b/src/Lumina.Plugins.Contracts/Core/Plugins/IPluginSettingsStore.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Plugins.Contracts.Core.Plugins; + +/// +/// Contract for reading the settings persisted by the host for a plugin. +/// +public interface IPluginSettingsStore +{ + /// + /// Gets the settings persisted by the host for the plugin identified by . + /// + /// The unique identifier of the plugin whose settings are read. + /// Cancellation token that can be used to cancel the operation. + /// The persisted settings keyed by setting key, or when no settings were persisted for the plugin. + Task?> GetSettingsAsync(Guid pluginId, CancellationToken cancellationToken); +} diff --git a/src/Lumina.Plugins.Contracts/Lumina.Plugins.Contracts.csproj b/src/Lumina.Plugins.Contracts/Lumina.Plugins.Contracts.csproj new file mode 100644 index 00000000..c223d0c2 --- /dev/null +++ b/src/Lumina.Plugins.Contracts/Lumina.Plugins.Contracts.csproj @@ -0,0 +1,23 @@ + + + net10.0 + disable + enable + $(SolutionDir)..\bin\api\ + false + true + $(WarningsNotAsErrors);NU1901;NU1902;NU1903;NU1904 + + + + + + + + + + + + + +