Added possibility to inform the entire system about changed settings

This commit is contained in:
Thorsten Sommer 2024-07-24 14:15:09 +02:00
parent c12bfa5a25
commit 9d28d8379e
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
4 changed files with 10 additions and 1 deletions

View File

@ -1,4 +1,5 @@
using AIStudio.Settings; using AIStudio.Settings;
using AIStudio.Tools;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
@ -23,7 +24,12 @@ public partial class ConfigurationBase : ComponentBase
public string OptionHelp { get; set; } = string.Empty; public string OptionHelp { get; set; } = string.Empty;
[Inject] [Inject]
public SettingsManager SettingsManager { get; init; } = null!; protected SettingsManager SettingsManager { get; init; } = null!;
[Inject]
protected MessageBus MessageBus { get; init; } = null!;
protected const string MARGIN_CLASS = "mb-6"; protected const string MARGIN_CLASS = "mb-6";
protected async Task InformAboutChange() => await this.MessageBus.SendMessage<bool>(this, Event.CONFIGURATION_CHANGED);
} }

View File

@ -35,5 +35,6 @@ public partial class ConfigurationOption : ConfigurationBase
{ {
this.StateUpdate(updatedState); this.StateUpdate(updatedState);
await this.SettingsManager.StoreSettings(); await this.SettingsManager.StoreSettings();
await this.InformAboutChange();
} }
} }

View File

@ -30,6 +30,7 @@ public partial class ConfigurationSelect<T> : ConfigurationBase
{ {
this.SelectionUpdate(updatedValue); this.SelectionUpdate(updatedValue);
await this.SettingsManager.StoreSettings(); await this.SettingsManager.StoreSettings();
await this.InformAboutChange();
} }
private static string GetClass => $"{MARGIN_CLASS} rounded-lg"; private static string GetClass => $"{MARGIN_CLASS} rounded-lg";

View File

@ -6,6 +6,7 @@ public enum Event
// Common events: // Common events:
STATE_HAS_CHANGED, STATE_HAS_CHANGED,
CONFIGURATION_CHANGED,
// Update events: // Update events:
USER_SEARCH_FOR_UPDATE, USER_SEARCH_FOR_UPDATE,