|
9 | 9 | using Microsoft.AspNetCore.Components.Routing; |
10 | 10 |
|
11 | 11 | using DialogOptions = AIStudio.Dialogs.DialogOptions; |
| 12 | +using EnterpriseEnvironment = AIStudio.Tools.EnterpriseEnvironment; |
12 | 13 |
|
13 | 14 | namespace AIStudio.Layout; |
14 | 15 |
|
@@ -138,90 +139,100 @@ private void LoadNavItems() |
138 | 139 |
|
139 | 140 | public async Task ProcessMessage<TMessage>(ComponentBase? sendingComponent, Event triggeredEvent, TMessage? data) |
140 | 141 | { |
141 | | - switch (triggeredEvent) |
| 142 | + await this.InvokeAsync(async () => |
142 | 143 | { |
143 | | - case Event.UPDATE_AVAILABLE: |
144 | | - if (data is UpdateResponse updateResponse) |
145 | | - { |
146 | | - this.currentUpdateResponse = updateResponse; |
147 | | - var message = string.Format(T("An update to version {0} is available."), updateResponse.NewVersion); |
148 | | - this.Snackbar.Add(message, Severity.Info, config => |
| 144 | + switch (triggeredEvent) |
| 145 | + { |
| 146 | + case Event.UPDATE_AVAILABLE: |
| 147 | + if (data is UpdateResponse updateResponse) |
149 | 148 | { |
150 | | - config.Icon = Icons.Material.Filled.Update; |
151 | | - config.IconSize = Size.Large; |
152 | | - config.HideTransitionDuration = 600; |
153 | | - config.VisibleStateDuration = 32_000; |
154 | | - config.OnClick = async _ => |
| 149 | + this.currentUpdateResponse = updateResponse; |
| 150 | + var message = string.Format(T("An update to version {0} is available."), updateResponse.NewVersion); |
| 151 | + this.Snackbar.Add(message, Severity.Info, config => |
155 | 152 | { |
156 | | - await this.ShowUpdateDialog(); |
157 | | - }; |
158 | | - config.Action = T("Show details"); |
159 | | - config.ActionVariant = Variant.Filled; |
160 | | - }); |
161 | | - } |
162 | | - |
163 | | - break; |
164 | | - |
165 | | - case Event.CONFIGURATION_CHANGED: |
166 | | - if(this.SettingsManager.ConfigurationData.App.NavigationBehavior is NavBehavior.ALWAYS_EXPAND) |
167 | | - this.navBarOpen = true; |
168 | | - else |
169 | | - this.navBarOpen = false; |
170 | | - |
171 | | - await this.UpdateThemeConfiguration(); |
172 | | - this.LoadNavItems(); |
173 | | - this.StateHasChanged(); |
174 | | - break; |
175 | | - |
176 | | - case Event.COLOR_THEME_CHANGED: |
177 | | - this.StateHasChanged(); |
178 | | - break; |
179 | | - |
180 | | - case Event.SHOW_SUCCESS: |
181 | | - if (data is DataSuccessMessage success) |
182 | | - success.Show(this.Snackbar); |
183 | | - |
184 | | - break; |
185 | | - |
186 | | - case Event.SHOW_ERROR: |
187 | | - if (data is DataErrorMessage error) |
188 | | - error.Show(this.Snackbar); |
189 | | - |
190 | | - break; |
191 | | - |
192 | | - case Event.SHOW_WARNING: |
193 | | - if (data is DataWarningMessage warning) |
194 | | - warning.Show(this.Snackbar); |
195 | | - |
196 | | - break; |
197 | | - |
198 | | - case Event.STARTUP_PLUGIN_SYSTEM: |
199 | | - _ = Task.Run(async () => |
200 | | - { |
201 | | - // Set up the plugin system: |
202 | | - if (PluginFactory.Setup()) |
| 153 | + config.Icon = Icons.Material.Filled.Update; |
| 154 | + config.IconSize = Size.Large; |
| 155 | + config.HideTransitionDuration = 600; |
| 156 | + config.VisibleStateDuration = 32_000; |
| 157 | + config.OnClick = async _ => |
| 158 | + { |
| 159 | + await this.ShowUpdateDialog(); |
| 160 | + }; |
| 161 | + config.Action = T("Show details"); |
| 162 | + config.ActionVariant = Variant.Filled; |
| 163 | + }); |
| 164 | + } |
| 165 | + |
| 166 | + break; |
| 167 | + |
| 168 | + case Event.CONFIGURATION_CHANGED: |
| 169 | + if (this.SettingsManager.ConfigurationData.App.NavigationBehavior is NavBehavior.ALWAYS_EXPAND) |
| 170 | + this.navBarOpen = true; |
| 171 | + else |
| 172 | + this.navBarOpen = false; |
| 173 | + |
| 174 | + await this.UpdateThemeConfiguration(); |
| 175 | + this.LoadNavItems(); |
| 176 | + this.StateHasChanged(); |
| 177 | + break; |
| 178 | + |
| 179 | + case Event.COLOR_THEME_CHANGED: |
| 180 | + this.StateHasChanged(); |
| 181 | + break; |
| 182 | + |
| 183 | + case Event.SHOW_SUCCESS: |
| 184 | + if (data is DataSuccessMessage success) |
| 185 | + success.Show(this.Snackbar); |
| 186 | + |
| 187 | + break; |
| 188 | + |
| 189 | + case Event.SHOW_ERROR: |
| 190 | + if (data is DataErrorMessage error) |
| 191 | + error.Show(this.Snackbar); |
| 192 | + |
| 193 | + break; |
| 194 | + |
| 195 | + case Event.SHOW_WARNING: |
| 196 | + if (data is DataWarningMessage warning) |
| 197 | + warning.Show(this.Snackbar); |
| 198 | + |
| 199 | + break; |
| 200 | + |
| 201 | + case Event.STARTUP_PLUGIN_SYSTEM: |
| 202 | + _ = Task.Run(async () => |
203 | 203 | { |
204 | | - // Ensure that all internal plugins are present: |
205 | | - await PluginFactory.EnsureInternalPlugins(); |
| 204 | + // Set up the plugin system: |
| 205 | + if (PluginFactory.Setup()) |
| 206 | + { |
| 207 | + // Ensure that all internal plugins are present: |
| 208 | + await PluginFactory.EnsureInternalPlugins(); |
| 209 | + |
| 210 | + // |
| 211 | + // Check if there is an enterprise configuration plugin to download: |
| 212 | + // |
| 213 | + var enterpriseEnvironment = this.MessageBus.CheckDeferredMessages<EnterpriseEnvironment>(Event.STARTUP_ENTERPRISE_ENVIRONMENT).FirstOrDefault(); |
| 214 | + if (enterpriseEnvironment != default) |
| 215 | + await PluginFactory.TryDownloadingConfigPluginAsync(enterpriseEnvironment.ConfigurationId, enterpriseEnvironment.ConfigurationServerUrl); |
| 216 | + |
| 217 | + // Load (but not start) all plugins without waiting for them: |
| 218 | + var pluginLoadingTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(5)); |
| 219 | + await PluginFactory.LoadAll(pluginLoadingTimeout.Token); |
| 220 | + |
| 221 | + // Set up hot reloading for plugins: |
| 222 | + PluginFactory.SetUpHotReloading(); |
| 223 | + } |
| 224 | + }); |
| 225 | + break; |
206 | 226 |
|
207 | | - // Load (but not start) all plugins, without waiting for them: |
208 | | - var pluginLoadingTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(5)); |
209 | | - await PluginFactory.LoadAll(pluginLoadingTimeout.Token); |
| 227 | + case Event.PLUGINS_RELOADED: |
| 228 | + this.Lang = await this.SettingsManager.GetActiveLanguagePlugin(); |
| 229 | + I18N.Init(this.Lang); |
| 230 | + this.LoadNavItems(); |
210 | 231 |
|
211 | | - // Set up hot reloading for plugins: |
212 | | - PluginFactory.SetUpHotReloading(); |
213 | | - } |
214 | | - }); |
215 | | - break; |
216 | | - |
217 | | - case Event.PLUGINS_RELOADED: |
218 | | - this.Lang = await this.SettingsManager.GetActiveLanguagePlugin(); |
219 | | - I18N.Init(this.Lang); |
220 | | - this.LoadNavItems(); |
221 | | - |
222 | | - await this.InvokeAsync(this.StateHasChanged); |
223 | | - break; |
224 | | - } |
| 232 | + await this.InvokeAsync(this.StateHasChanged); |
| 233 | + break; |
| 234 | + } |
| 235 | + }); |
225 | 236 | } |
226 | 237 |
|
227 | 238 | public Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data) |
|
0 commit comments