Skip to content

Commit 20f09bb

Browse files
committed
stuff
1 parent 5ab4b9b commit 20f09bb

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

StabilityMatrix.Avalonia/ViewModels/Inference/PromptCardViewModel.cs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Text;
33
using System.Text.Json;
44
using System.Text.Json.Nodes;
5+
using AsyncAwaitBestPractices;
56
using Avalonia.Controls.Notifications;
67
using AvaloniaEdit;
78
using AvaloniaEdit.Document;
@@ -226,43 +227,47 @@ public override async Task OnLoadedAsync()
226227

227228
protected override Task OnInitialLoadedAsync()
228229
{
229-
_ = Task.Run(async () =>
230-
{
231-
try
230+
Task.Run(async () =>
232231
{
233-
var isLoggedIn = await accountsService.HasStoredLykosAccountAsync();
234-
if (!isLoggedIn)
232+
try
235233
{
236-
return;
237-
}
234+
var isLoggedIn = await accountsService.HasStoredLykosAccountAsync();
235+
if (!isLoggedIn)
236+
{
237+
return;
238+
}
238239

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+
}
245246

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
254248
{
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;
261251
}
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+
}
262266

263-
TokensRemaining = -1;
264-
}
265-
});
267+
TokensRemaining = -1;
268+
}
269+
})
270+
.SafeFireAndForget(onException: ex => logger.LogError(ex, "Error getting prompt amplifier data"));
266271

267272
return Task.CompletedTask;
268273
}

0 commit comments

Comments
 (0)