Core - Added API for retrieving current suspended device providers

Core - Added events for plugin removal, entry installlation/uninstallation
Workshop - Remove the related workshop entry when manually removing a plugin or profile
Workshop - Prevent installing profiles with missing plugins and show a dialog with which plugins are missing
This commit is contained in:
Robert committed 2024-06-30 09:42:41 +02:00
1 parent 86f78940b1
commit 648b7765ef
20 files changed
+440 -106

No files matched your search

@@ -38,12 +38,14 @@ internal class DeviceService : IDeviceService
_renderService = renderService;
_getLayoutProviders = getLayoutProviders;
SuspendedDeviceProviders = new ReadOnlyCollection<DeviceProvider>(_suspendedDeviceProviders);
EnabledDevices = new ReadOnlyCollection<ArtemisDevice>(_enabledDevices);
Devices = new ReadOnlyCollection<ArtemisDevice>(_devices);
RenderScale.RenderScaleMultiplierChanged += RenderScaleOnRenderScaleMultiplierChanged;
}
public IReadOnlyCollection<DeviceProvider> SuspendedDeviceProviders { get; }
public IReadOnlyCollection<ArtemisDevice> EnabledDevices { get; }
public IReadOnlyCollection<ArtemisDevice> Devices { get; }
@@ -10,6 +10,11 @@ namespace Artemis.Core.Services;
/// </summary>
public interface IDeviceService : IArtemisService
{
/// <summary>
/// Gets a read-only collection containing all enabled but suspended device providers
/// </summary>
IReadOnlyCollection<DeviceProvider> SuspendedDeviceProviders { get; }
/// <summary>
/// Gets a read-only collection containing all enabled devices
/// </summary>
@@ -42,7 +47,7 @@ public interface IDeviceService : IArtemisService
/// Applies auto-arranging logic to the surface
/// </summary>
void AutoArrangeDevices();
/// <summary>
/// Apples the best available to the provided <see cref="ArtemisDevice" />
/// </summary>
@@ -111,7 +116,7 @@ public interface IDeviceService : IArtemisService
/// Occurs when a device provider was removed.
/// </summary>
event EventHandler<DeviceProviderEventArgs> DeviceProviderRemoved;
/// <summary>
/// Occurs when the surface has had modifications to its LED collection
/// </summary>
@@ -186,6 +186,11 @@ public interface IPluginManagementService : IArtemisService, IDisposable
/// </summary>
event EventHandler<PluginEventArgs> PluginDisabled;
/// <summary>
/// Occurs when a plugin is removed
/// </summary>
event EventHandler<PluginEventArgs> PluginRemoved;
/// <summary>
/// Occurs when a plugin feature is being enabled
/// </summary>
@@ -686,6 +686,8 @@ internal class PluginManagementService : IPluginManagementService
if (removeSettings)
RemovePluginSettings(plugin);
OnPluginRemoved(new PluginEventArgs(plugin));
}
public void RemovePluginSettings(Plugin plugin)
@@ -850,6 +852,7 @@ internal class PluginManagementService : IPluginManagementService
public event EventHandler<PluginEventArgs>? PluginEnabling;
public event EventHandler<PluginEventArgs>? PluginEnabled;
public event EventHandler<PluginEventArgs>? PluginDisabled;
public event EventHandler<PluginEventArgs>? PluginRemoved;
public event EventHandler<PluginFeatureEventArgs>? PluginFeatureEnabling;
public event EventHandler<PluginFeatureEventArgs>? PluginFeatureEnabled;
@@ -890,6 +893,11 @@ internal class PluginManagementService : IPluginManagementService
{
PluginDisabled?.Invoke(this, e);
}
protected virtual void OnPluginRemoved(PluginEventArgs e)
{
PluginRemoved?.Invoke(this, e);
}
protected virtual void OnPluginFeatureEnabling(PluginFeatureEventArgs e)
{
@@ -30,7 +30,7 @@ public interface IProfileService : IArtemisService
/// Gets or sets a value indicating whether the currently focused profile should receive updates.
/// </summary>
bool UpdateFocusProfile { get; set; }
/// <summary>
/// Gets or sets whether profiles are rendered each frame by calling their Render method
/// </summary>
@@ -54,7 +54,7 @@ public interface IProfileService : IArtemisService
/// </summary>
/// <param name="profileConfiguration">The profile configuration of the profile to activate.</param>
void DeactivateProfile(ProfileConfiguration profileConfiguration);
/// <summary>
/// Saves the provided <see cref="ProfileCategory" /> and it's <see cref="ProfileConfiguration" />s but not the
/// <see cref="Profile" />s themselves.
@@ -117,8 +117,9 @@ public interface IProfileService : IArtemisService
/// <param name="nameAffix">Text to add after the name of the profile (separated by a dash).</param>
/// <param name="target">The profile before which to import the profile into the category.</param>
/// <returns>The resulting profile configuration.</returns>
Task<ProfileConfiguration> ImportProfile(Stream archiveStream, ProfileCategory category, bool makeUnique, bool markAsFreshImport, string? nameAffix = "imported", ProfileConfiguration? target = null);
Task<ProfileConfiguration> ImportProfile(Stream archiveStream, ProfileCategory category, bool makeUnique, bool markAsFreshImport, string? nameAffix = "imported",
ProfileConfiguration? target = null);
/// <summary>
/// Imports the provided ZIP archive stream into the provided profile configuration
/// </summary>
@@ -163,5 +164,14 @@ public interface IProfileService : IArtemisService
/// Occurs whenever a profile category is removed.
/// </summary>
public event EventHandler<ProfileCategoryEventArgs>? ProfileCategoryRemoved;
/// <summary>
/// Occurs whenever a profile is added.
/// </summary>
public event EventHandler<ProfileConfigurationEventArgs>? ProfileRemoved;
/// <summary>
/// Occurs whenever a profile is removed.
/// </summary>
public event EventHandler<ProfileConfigurationEventArgs>? ProfileAdded;
}
@@ -26,7 +26,6 @@ internal class ProfileService : IProfileService
private readonly IPluginManagementService _pluginManagementService;
private readonly IDeviceService _deviceService;
private readonly List<ArtemisKeyboardKeyEventArgs> _pendingKeyboardEvents = new();
private readonly List<IProfileMigration> _profileMigrators;
private readonly List<Exception> _renderExceptions = new();
private readonly List<Exception> _updateExceptions = new();
@@ -38,15 +37,13 @@ internal class ProfileService : IProfileService
IProfileRepository profileRepository,
IPluginManagementService pluginManagementService,
IInputService inputService,
IDeviceService deviceService,
List<IProfileMigration> profileMigrators)
IDeviceService deviceService)
{
_logger = logger;
_profileCategoryRepository = profileCategoryRepository;
_profileRepository = profileRepository;
_pluginManagementService = pluginManagementService;
_deviceService = deviceService;
_profileMigrators = profileMigrators;
ProfileCategories = new ReadOnlyCollection<ProfileCategory>(_profileCategoryRepository.GetAll().Select(c => new ProfileCategory(c)).OrderBy(c => c.Order).ToList());
@@ -264,6 +261,8 @@ internal class ProfileService : IProfileService
category.AddProfileConfiguration(configuration, category.ProfileConfigurations.FirstOrDefault());
SaveProfileCategory(category);
OnProfileAdded(new ProfileConfigurationEventArgs(configuration));
return configuration;
}
@@ -279,6 +278,8 @@ internal class ProfileService : IProfileService
_profileRepository.Remove(profileConfiguration.Entity);
_profileCategoryRepository.Save(category.Entity);
OnProfileRemoved(new ProfileConfigurationEventArgs(profileConfiguration));
}
/// <inheritdoc />
@@ -436,8 +437,9 @@ internal class ProfileService : IProfileService
/// <inheritdoc />
public async Task<ProfileConfiguration> OverwriteProfile(MemoryStream archiveStream, ProfileConfiguration profileConfiguration)
{
ProfileConfiguration imported = await ImportProfile(archiveStream, profileConfiguration.Category, true, true, null, profileConfiguration);
ProfileConfiguration imported = await ImportProfile(archiveStream, profileConfiguration.Category, true, false, null, profileConfiguration);
imported.Name = profileConfiguration.Name;
RemoveProfileConfiguration(profileConfiguration);
SaveProfileCategory(imported.Category);
@@ -588,6 +590,8 @@ internal class ProfileService : IProfileService
public event EventHandler<ProfileConfigurationEventArgs>? ProfileDeactivated;
public event EventHandler<ProfileCategoryEventArgs>? ProfileCategoryAdded;
public event EventHandler<ProfileCategoryEventArgs>? ProfileCategoryRemoved;
public event EventHandler<ProfileConfigurationEventArgs>? ProfileRemoved;
public event EventHandler<ProfileConfigurationEventArgs>? ProfileAdded;
protected virtual void OnProfileActivated(ProfileConfigurationEventArgs e)
{
@@ -610,4 +614,14 @@ internal class ProfileService : IProfileService
}
#endregion
protected virtual void OnProfileRemoved(ProfileConfigurationEventArgs e)
{
ProfileRemoved?.Invoke(this, e);
}
protected virtual void OnProfileAdded(ProfileConfigurationEventArgs e)
{
ProfileAdded?.Invoke(this, e);
}
}