|
2 | 2 | using System.Text; |
3 | 3 | using System.Text.Json; |
4 | 4 | using System.Text.Json.Nodes; |
| 5 | +using AsyncAwaitBestPractices; |
5 | 6 | using Avalonia.Controls.Notifications; |
6 | 7 | using AvaloniaEdit; |
7 | 8 | using AvaloniaEdit.Document; |
@@ -222,43 +223,53 @@ public override async Task OnLoadedAsync() |
222 | 223 | { |
223 | 224 | IsPromptAmplifyTeachingTipOpen = true; |
224 | 225 | } |
| 226 | + } |
225 | 227 |
|
226 | | - _ = Task.Run(async () => |
227 | | - { |
228 | | - try |
| 228 | + protected override Task OnInitialLoadedAsync() |
| 229 | + { |
| 230 | + Task.Run(async () => |
229 | 231 | { |
230 | | - if (accountsService.LykosStatus == null) |
| 232 | + try |
231 | 233 | { |
232 | | - await accountsService.RefreshAsync(); |
233 | | - } |
| 234 | + var isLoggedIn = await accountsService.HasStoredLykosAccountAsync(); |
| 235 | + if (!isLoggedIn) |
| 236 | + { |
| 237 | + return; |
| 238 | + } |
234 | 239 |
|
235 | | - SetTokenThreshold(); |
236 | | - } |
237 | | - catch (Exception ex) |
238 | | - { |
239 | | - logger.LogError(ex, "Error refreshing account data"); |
240 | | - } |
| 240 | + SetTokenThreshold(); |
| 241 | + } |
| 242 | + catch (Exception ex) |
| 243 | + { |
| 244 | + logger.LogError(ex, "Error refreshing account data"); |
| 245 | + } |
241 | 246 |
|
242 | | - try |
243 | | - { |
244 | | - var result = await promptGenApi.AccountMeTokens(); |
245 | | - TokensRemaining = result.Available; |
246 | | - } |
247 | | - catch (ApiException e) |
248 | | - { |
249 | | - if (e.StatusCode != HttpStatusCode.Unauthorized && e.StatusCode != HttpStatusCode.NotFound) |
| 247 | + try |
250 | 248 | { |
251 | | - notificationService.Show( |
252 | | - "Error retrieving prompt amplifier data", |
253 | | - e.Message, |
254 | | - NotificationType.Error |
255 | | - ); |
256 | | - return; |
| 249 | + var result = await promptGenApi.AccountMeTokens(); |
| 250 | + TokensRemaining = result.Available; |
| 251 | + } |
| 252 | + catch (ApiException e) |
| 253 | + { |
| 254 | + if ( |
| 255 | + e.StatusCode != HttpStatusCode.Unauthorized |
| 256 | + && e.StatusCode != HttpStatusCode.NotFound |
| 257 | + ) |
| 258 | + { |
| 259 | + notificationService.Show( |
| 260 | + "Error retrieving prompt amplifier data", |
| 261 | + e.Message, |
| 262 | + NotificationType.Error |
| 263 | + ); |
| 264 | + return; |
| 265 | + } |
| 266 | + |
| 267 | + TokensRemaining = -1; |
257 | 268 | } |
| 269 | + }) |
| 270 | + .SafeFireAndForget(onException: ex => logger.LogError(ex, "Error getting prompt amplifier data")); |
258 | 271 |
|
259 | | - TokensRemaining = -1; |
260 | | - } |
261 | | - }); |
| 272 | + return Task.CompletedTask; |
262 | 273 | } |
263 | 274 |
|
264 | 275 | private void SetTokenThreshold() |
|
0 commit comments