mirror of
https://github.com/Stone-Red-Code/EchoHub.git
synced 2026-09-04 00:56:05 +02:00
- Updated launchSettings.json for consistency. - Refactored FileValidationHelper to improve image validation logic. - Enhanced ServerDirectoryService for better connection handling and user count updates. - Improved DatabaseSetup for legacy database handling and seeding default channels. - Refined FirstRunSetup to ensure JWT secret generation. - Removed appsettings.Development.json as it is no longer needed. - Updated EchoHub.Tests project file for consistency. - Added unit tests for FileValidationHelper and PresenceTracker with improved assertions. - Updated ValidationConstantsTests to ensure regex validations are correct. - Cleaned up solution file formatting for better readability.
33 lines
815 B
C#
33 lines
815 B
C#
using Serilog;
|
|
using Terminal.Gui.App;
|
|
|
|
namespace EchoHub.Client;
|
|
|
|
/// <summary>
|
|
/// Eliminates repeated Task.Run/try/catch/app.Invoke(ShowError) boilerplate.
|
|
/// Runs async work on a background thread and routes exceptions to the UI.
|
|
/// </summary>
|
|
public static class AsyncRunner
|
|
{
|
|
public static void Run(
|
|
IApplication app,
|
|
Func<Task> work,
|
|
Action<string> showError,
|
|
string errorPrefix,
|
|
string? logContext = null)
|
|
{
|
|
Task.Run(async () =>
|
|
{
|
|
try
|
|
{
|
|
await work();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "{Context} failed", logContext ?? errorPrefix);
|
|
app.Invoke(() => showError($"{errorPrefix}: {ex.Message}"));
|
|
}
|
|
});
|
|
}
|
|
}
|