Added switch to enable or disable a plugin

This commit is contained in:
Thorsten Sommer 2025-03-27 21:07:39 +01:00
parent d77a5ab8e3
commit 6cb4cad01f
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
3 changed files with 22 additions and 2 deletions

View File

@ -63,7 +63,10 @@
</MudStack> </MudStack>
</MudTd> </MudTd>
<MudTd> <MudTd>
Actions... @if (!context.IsInternal)
{
<MudSwitch T="bool" Value="@this.SettingsManager.IsPluginEnabled(context)" ValueChanged="@(_ => this.PluginActivationStateChanged(context))"/>
}
</MudTd> </MudTd>
</RowTemplate> </RowTemplate>
</MudTable> </MudTable>

View File

@ -11,6 +11,9 @@ public partial class Plugins : ComponentBase
private const string GROUP_DISABLED = "Disabled"; private const string GROUP_DISABLED = "Disabled";
private const string GROUP_INTERNAL = "Internal"; private const string GROUP_INTERNAL = "Internal";
[Inject]
private MessageBus MessageBus { get; init; } = null!;
[Inject] [Inject]
private SettingsManager SettingsManager { get; init; } = null!; private SettingsManager SettingsManager { get; init; } = null!;
@ -29,7 +32,7 @@ public partial class Plugins : ComponentBase
if (pluginMeta.IsInternal) if (pluginMeta.IsInternal)
return GROUP_INTERNAL; return GROUP_INTERNAL;
return this.SettingsManager.ConfigurationData.EnabledPlugins.Contains(pluginMeta.Id) return this.SettingsManager.IsPluginEnabled(pluginMeta)
? GROUP_ENABLED ? GROUP_ENABLED
: GROUP_DISABLED; : GROUP_DISABLED;
} }
@ -39,4 +42,15 @@ public partial class Plugins : ComponentBase
} }
#endregion #endregion
private async Task PluginActivationStateChanged(IPluginMetadata pluginMeta)
{
if (this.SettingsManager.IsPluginEnabled(pluginMeta))
this.SettingsManager.ConfigurationData.EnabledPlugins.Remove(pluginMeta.Id);
else
this.SettingsManager.ConfigurationData.EnabledPlugins.Add(pluginMeta.Id);
await this.SettingsManager.StoreSettings();
await this.MessageBus.SendMessage<bool>(this, Event.CONFIGURATION_CHANGED);
}
} }

View File

@ -4,6 +4,7 @@ using System.Text.Json.Serialization;
using AIStudio.Provider; using AIStudio.Provider;
using AIStudio.Settings.DataModel; using AIStudio.Settings.DataModel;
using AIStudio.Tools.PluginSystem;
// ReSharper disable NotAccessedPositionalProperty.Local // ReSharper disable NotAccessedPositionalProperty.Local
@ -142,6 +143,8 @@ public sealed class SettingsManager(ILogger<SettingsManager> logger)
return minimumLevel; return minimumLevel;
} }
public bool IsPluginEnabled(IPluginMetadata plugin) => this.ConfigurationData.EnabledPlugins.Contains(plugin.Id);
[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")] [SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
public Provider GetPreselectedProvider(Tools.Components component, string? currentProviderId = null, bool usePreselectionBeforeCurrentProvider = false) public Provider GetPreselectedProvider(Tools.Components component, string? currentProviderId = null, bool usePreselectionBeforeCurrentProvider = false)
{ {