Files
EchoHub/src/EchoHub.Client/Services/AsyncRunner.cs
T
HueByte c8ea124198 Add hex color parsing helper and implement custom list sources for channels and users
- Introduced HexColorHelper for parsing hex color strings to Terminal.Gui Attributes and Colors.
- Created ChannelListSource for managing and rendering a list of channels with unread counts and active indicators.
- Developed UserListSource for displaying online users with per-user nickname colors.
- Refactored MainWindow to utilize ChatMessageManager for handling messages and channel state.
- Updated project references and removed unused content from the server project.
- Adjusted tests to reflect changes in namespaces and structure.
2026-02-22 08:08:21 +01:00

33 lines
824 B
C#

using Serilog;
using Terminal.Gui.App;
namespace EchoHub.Client.Services;
/// <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}"));
}
});
}
}