|
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; |
@@ -226,43 +227,47 @@ public override async Task OnLoadedAsync() |
226 | 227 |
|
227 | 228 | protected override Task OnInitialLoadedAsync() |
228 | 229 | { |
229 | | - _ = Task.Run(async () => |
230 | | - { |
231 | | - try |
| 230 | + Task.Run(async () => |
232 | 231 | { |
233 | | - var isLoggedIn = await accountsService.HasStoredLykosAccountAsync(); |
234 | | - if (!isLoggedIn) |
| 232 | + try |
235 | 233 | { |
236 | | - return; |
237 | | - } |
| 234 | + var isLoggedIn = await accountsService.HasStoredLykosAccountAsync(); |
| 235 | + if (!isLoggedIn) |
| 236 | + { |
| 237 | + return; |
| 238 | + } |
238 | 239 |
|
239 | | - SetTokenThreshold(); |
240 | | - } |
241 | | - catch (Exception ex) |
242 | | - { |
243 | | - logger.LogError(ex, "Error refreshing account data"); |
244 | | - } |
| 240 | + SetTokenThreshold(); |
| 241 | + } |
| 242 | + catch (Exception ex) |
| 243 | + { |
| 244 | + logger.LogError(ex, "Error refreshing account data"); |
| 245 | + } |
245 | 246 |
|
246 | | - try |
247 | | - { |
248 | | - var result = await promptGenApi.AccountMeTokens(); |
249 | | - TokensRemaining = result.Available; |
250 | | - } |
251 | | - catch (ApiException e) |
252 | | - { |
253 | | - if (e.StatusCode != HttpStatusCode.Unauthorized && e.StatusCode != HttpStatusCode.NotFound) |
| 247 | + try |
254 | 248 | { |
255 | | - notificationService.Show( |
256 | | - "Error retrieving prompt amplifier data", |
257 | | - e.Message, |
258 | | - NotificationType.Error |
259 | | - ); |
260 | | - return; |
| 249 | + var result = await promptGenApi.AccountMeTokens(); |
| 250 | + TokensRemaining = result.Available; |
261 | 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 | + } |
262 | 266 |
|
263 | | - TokensRemaining = -1; |
264 | | - } |
265 | | - }); |
| 267 | + TokensRemaining = -1; |
| 268 | + } |
| 269 | + }) |
| 270 | + .SafeFireAndForget(onException: ex => logger.LogError(ex, "Error getting prompt amplifier data")); |
266 | 271 |
|
267 | 272 | return Task.CompletedTask; |
268 | 273 | } |
|
0 commit comments