diff --git a/app/MindWork AI Studio/Components/MSGComponentBase.cs b/app/MindWork AI Studio/Components/MSGComponentBase.cs index 739f6c68..a04865c2 100644 --- a/app/MindWork AI Studio/Components/MSGComponentBase.cs +++ b/app/MindWork AI Studio/Components/MSGComponentBase.cs @@ -45,11 +45,13 @@ public abstract class MSGComponentBase : ComponentBase, IDisposable, IMessageBus public async Task ProcessMessage(ComponentBase? sendingComponent, Event triggeredEvent, T? data) { - switch (triggeredEvent) + await this.InvokeAsync(async () => { - case Event.COLOR_THEME_CHANGED: - this.StateHasChanged(); - break; + switch (triggeredEvent) + { + case Event.COLOR_THEME_CHANGED: + this.StateHasChanged(); + break; case Event.PLUGINS_RELOADED: this.Lang = await this.SettingsManager.GetActiveLanguagePlugin(); @@ -57,7 +59,8 @@ public abstract class MSGComponentBase : ComponentBase, IDisposable, IMessageBus break; } - await this.ProcessIncomingMessage(sendingComponent, triggeredEvent, data); + await this.ProcessIncomingMessage(sendingComponent, triggeredEvent, data); + }); } public async Task ProcessMessageWithResult(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data) diff --git a/app/MindWork AI Studio/Layout/MainLayout.razor.cs b/app/MindWork AI Studio/Layout/MainLayout.razor.cs index b2691b74..385ba5df 100644 --- a/app/MindWork AI Studio/Layout/MainLayout.razor.cs +++ b/app/MindWork AI Studio/Layout/MainLayout.razor.cs @@ -139,97 +139,100 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan public async Task ProcessMessage(ComponentBase? sendingComponent, Event triggeredEvent, TMessage? data) { - switch (triggeredEvent) + await this.InvokeAsync(async () => { - case Event.UPDATE_AVAILABLE: - if (data is UpdateResponse updateResponse) - { - this.currentUpdateResponse = updateResponse; - var message = string.Format(T("An update to version {0} is available."), updateResponse.NewVersion); - this.Snackbar.Add(message, Severity.Info, config => + switch (triggeredEvent) + { + case Event.UPDATE_AVAILABLE: + if (data is UpdateResponse updateResponse) { - config.Icon = Icons.Material.Filled.Update; - config.IconSize = Size.Large; - config.HideTransitionDuration = 600; - config.VisibleStateDuration = 32_000; - config.OnClick = async _ => + this.currentUpdateResponse = updateResponse; + var message = string.Format(T("An update to version {0} is available."), updateResponse.NewVersion); + this.Snackbar.Add(message, Severity.Info, config => { - await this.ShowUpdateDialog(); - }; - config.Action = T("Show details"); - config.ActionVariant = Variant.Filled; - }); - } - - break; - - case Event.CONFIGURATION_CHANGED: - if(this.SettingsManager.ConfigurationData.App.NavigationBehavior is NavBehavior.ALWAYS_EXPAND) - this.navBarOpen = true; - else - this.navBarOpen = false; - - await this.UpdateThemeConfiguration(); - this.LoadNavItems(); - this.StateHasChanged(); - break; - - case Event.COLOR_THEME_CHANGED: - this.StateHasChanged(); - break; - - case Event.SHOW_SUCCESS: - if (data is DataSuccessMessage success) - success.Show(this.Snackbar); - - break; - - case Event.SHOW_ERROR: - if (data is DataErrorMessage error) - error.Show(this.Snackbar); - - break; - - case Event.SHOW_WARNING: - if (data is DataWarningMessage warning) - warning.Show(this.Snackbar); - - break; - - case Event.STARTUP_PLUGIN_SYSTEM: - _ = Task.Run(async () => - { - // Set up the plugin system: - if (PluginFactory.Setup()) - { - // Ensure that all internal plugins are present: - await PluginFactory.EnsureInternalPlugins(); - - // - // Check if there is an enterprise configuration plugin to download: - // - var enterpriseEnvironment = this.MessageBus.CheckDeferredMessages(Event.STARTUP_ENTERPRISE_ENVIRONMENT).FirstOrDefault(); - if(enterpriseEnvironment != default) - await PluginFactory.TryDownloadingConfigPluginAsync(enterpriseEnvironment.ConfigurationId, enterpriseEnvironment.ConfigurationServerUrl); - - // Load (but not start) all plugins without waiting for them: - var pluginLoadingTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(5)); - await PluginFactory.LoadAll(pluginLoadingTimeout.Token); - - // Set up hot reloading for plugins: - PluginFactory.SetUpHotReloading(); + config.Icon = Icons.Material.Filled.Update; + config.IconSize = Size.Large; + config.HideTransitionDuration = 600; + config.VisibleStateDuration = 32_000; + config.OnClick = async _ => + { + await this.ShowUpdateDialog(); + }; + config.Action = T("Show details"); + config.ActionVariant = Variant.Filled; + }); } - }); - break; - - case Event.PLUGINS_RELOADED: - this.Lang = await this.SettingsManager.GetActiveLanguagePlugin(); - I18N.Init(this.Lang); - this.LoadNavItems(); - - await this.InvokeAsync(this.StateHasChanged); - break; - } + + break; + + case Event.CONFIGURATION_CHANGED: + if (this.SettingsManager.ConfigurationData.App.NavigationBehavior is NavBehavior.ALWAYS_EXPAND) + this.navBarOpen = true; + else + this.navBarOpen = false; + + await this.UpdateThemeConfiguration(); + this.LoadNavItems(); + this.StateHasChanged(); + break; + + case Event.COLOR_THEME_CHANGED: + this.StateHasChanged(); + break; + + case Event.SHOW_SUCCESS: + if (data is DataSuccessMessage success) + success.Show(this.Snackbar); + + break; + + case Event.SHOW_ERROR: + if (data is DataErrorMessage error) + error.Show(this.Snackbar); + + break; + + case Event.SHOW_WARNING: + if (data is DataWarningMessage warning) + warning.Show(this.Snackbar); + + break; + + case Event.STARTUP_PLUGIN_SYSTEM: + _ = Task.Run(async () => + { + // Set up the plugin system: + if (PluginFactory.Setup()) + { + // Ensure that all internal plugins are present: + await PluginFactory.EnsureInternalPlugins(); + + // + // Check if there is an enterprise configuration plugin to download: + // + var enterpriseEnvironment = this.MessageBus.CheckDeferredMessages(Event.STARTUP_ENTERPRISE_ENVIRONMENT).FirstOrDefault(); + if (enterpriseEnvironment != default) + await PluginFactory.TryDownloadingConfigPluginAsync(enterpriseEnvironment.ConfigurationId, enterpriseEnvironment.ConfigurationServerUrl); + + // Load (but not start) all plugins without waiting for them: + var pluginLoadingTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(5)); + await PluginFactory.LoadAll(pluginLoadingTimeout.Token); + + // Set up hot reloading for plugins: + PluginFactory.SetUpHotReloading(); + } + }); + break; + + case Event.PLUGINS_RELOADED: + this.Lang = await this.SettingsManager.GetActiveLanguagePlugin(); + I18N.Init(this.Lang); + this.LoadNavItems(); + + await this.InvokeAsync(this.StateHasChanged); + break; + } + }); } public Task ProcessMessageWithResult(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)