mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-08-21 04:12:56 +00:00
Wrap message processing logic in InvokeAsync
calls
This commit is contained in:
parent
ea41e84cf3
commit
bc80f93047
@ -45,11 +45,13 @@ public abstract class MSGComponentBase : ComponentBase, IDisposable, IMessageBus
|
|||||||
|
|
||||||
public async Task ProcessMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data)
|
public async Task ProcessMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data)
|
||||||
{
|
{
|
||||||
switch (triggeredEvent)
|
await this.InvokeAsync(async () =>
|
||||||
{
|
{
|
||||||
case Event.COLOR_THEME_CHANGED:
|
switch (triggeredEvent)
|
||||||
this.StateHasChanged();
|
{
|
||||||
break;
|
case Event.COLOR_THEME_CHANGED:
|
||||||
|
this.StateHasChanged();
|
||||||
|
break;
|
||||||
|
|
||||||
case Event.PLUGINS_RELOADED:
|
case Event.PLUGINS_RELOADED:
|
||||||
this.Lang = await this.SettingsManager.GetActiveLanguagePlugin();
|
this.Lang = await this.SettingsManager.GetActiveLanguagePlugin();
|
||||||
@ -57,7 +59,8 @@ public abstract class MSGComponentBase : ComponentBase, IDisposable, IMessageBus
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.ProcessIncomingMessage(sendingComponent, triggeredEvent, data);
|
await this.ProcessIncomingMessage(sendingComponent, triggeredEvent, data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
|
public async Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
|
||||||
|
@ -139,97 +139,100 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
|
|||||||
|
|
||||||
public async Task ProcessMessage<TMessage>(ComponentBase? sendingComponent, Event triggeredEvent, TMessage? data)
|
public async Task ProcessMessage<TMessage>(ComponentBase? sendingComponent, Event triggeredEvent, TMessage? data)
|
||||||
{
|
{
|
||||||
switch (triggeredEvent)
|
await this.InvokeAsync(async () =>
|
||||||
{
|
{
|
||||||
case Event.UPDATE_AVAILABLE:
|
switch (triggeredEvent)
|
||||||
if (data is UpdateResponse updateResponse)
|
{
|
||||||
{
|
case Event.UPDATE_AVAILABLE:
|
||||||
this.currentUpdateResponse = updateResponse;
|
if (data is UpdateResponse updateResponse)
|
||||||
var message = string.Format(T("An update to version {0} is available."), updateResponse.NewVersion);
|
|
||||||
this.Snackbar.Add(message, Severity.Info, config =>
|
|
||||||
{
|
{
|
||||||
config.Icon = Icons.Material.Filled.Update;
|
this.currentUpdateResponse = updateResponse;
|
||||||
config.IconSize = Size.Large;
|
var message = string.Format(T("An update to version {0} is available."), updateResponse.NewVersion);
|
||||||
config.HideTransitionDuration = 600;
|
this.Snackbar.Add(message, Severity.Info, config =>
|
||||||
config.VisibleStateDuration = 32_000;
|
|
||||||
config.OnClick = async _ =>
|
|
||||||
{
|
{
|
||||||
await this.ShowUpdateDialog();
|
config.Icon = Icons.Material.Filled.Update;
|
||||||
};
|
config.IconSize = Size.Large;
|
||||||
config.Action = T("Show details");
|
config.HideTransitionDuration = 600;
|
||||||
config.ActionVariant = Variant.Filled;
|
config.VisibleStateDuration = 32_000;
|
||||||
});
|
config.OnClick = async _ =>
|
||||||
}
|
{
|
||||||
|
await this.ShowUpdateDialog();
|
||||||
break;
|
};
|
||||||
|
config.Action = T("Show details");
|
||||||
case Event.CONFIGURATION_CHANGED:
|
config.ActionVariant = Variant.Filled;
|
||||||
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<EnterpriseEnvironment>(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:
|
break;
|
||||||
this.Lang = await this.SettingsManager.GetActiveLanguagePlugin();
|
|
||||||
I18N.Init(this.Lang);
|
|
||||||
this.LoadNavItems();
|
|
||||||
|
|
||||||
await this.InvokeAsync(this.StateHasChanged);
|
case Event.CONFIGURATION_CHANGED:
|
||||||
break;
|
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<EnterpriseEnvironment>(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<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
|
public Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
|
||||||
|
Loading…
Reference in New Issue
Block a user