mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 08:19:47 +00:00
Added switch to enable or disable a plugin
This commit is contained in:
parent
d77a5ab8e3
commit
6cb4cad01f
@ -63,7 +63,10 @@
|
||||
</MudStack>
|
||||
</MudTd>
|
||||
<MudTd>
|
||||
Actions...
|
||||
@if (!context.IsInternal)
|
||||
{
|
||||
<MudSwitch T="bool" Value="@this.SettingsManager.IsPluginEnabled(context)" ValueChanged="@(_ => this.PluginActivationStateChanged(context))"/>
|
||||
}
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
|
@ -11,6 +11,9 @@ public partial class Plugins : ComponentBase
|
||||
private const string GROUP_DISABLED = "Disabled";
|
||||
private const string GROUP_INTERNAL = "Internal";
|
||||
|
||||
[Inject]
|
||||
private MessageBus MessageBus { get; init; } = null!;
|
||||
|
||||
[Inject]
|
||||
private SettingsManager SettingsManager { get; init; } = null!;
|
||||
|
||||
@ -29,7 +32,7 @@ public partial class Plugins : ComponentBase
|
||||
if (pluginMeta.IsInternal)
|
||||
return GROUP_INTERNAL;
|
||||
|
||||
return this.SettingsManager.ConfigurationData.EnabledPlugins.Contains(pluginMeta.Id)
|
||||
return this.SettingsManager.IsPluginEnabled(pluginMeta)
|
||||
? GROUP_ENABLED
|
||||
: GROUP_DISABLED;
|
||||
}
|
||||
@ -39,4 +42,15 @@ public partial class Plugins : ComponentBase
|
||||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings.DataModel;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
|
||||
// ReSharper disable NotAccessedPositionalProperty.Local
|
||||
|
||||
@ -142,6 +143,8 @@ public sealed class SettingsManager(ILogger<SettingsManager> logger)
|
||||
return minimumLevel;
|
||||
}
|
||||
|
||||
public bool IsPluginEnabled(IPluginMetadata plugin) => this.ConfigurationData.EnabledPlugins.Contains(plugin.Id);
|
||||
|
||||
[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
|
||||
public Provider GetPreselectedProvider(Tools.Components component, string? currentProviderId = null, bool usePreselectionBeforeCurrentProvider = false)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user