namespace InABox.Avalonia.Dialogs; public enum MessageDialogButtonPosition { Left, Right } public enum MessageDialogResult { None, OK, Cancel, Yes, No, Other } public static class MessageDialog { public static async Task ShowMessage(string message) => await MessageDialogViewModel.ShowMessage(message); public static async Task ShowError(Exception e) => await MessageDialogViewModel.ShowMessage($"Error: {e.Message}"); public static async Task ShowOkCancel(string message) => await MessageDialogViewModel.ShowOkCancel(message); public static async Task ShowYesNo(string message) => await MessageDialogViewModel.ShowYesNo(message); public static async Task ShowYesCancel(string message) => await MessageDialogViewModel.ShowYesCancel(message); public static async Task ShowYesNoCancel(string message) => await MessageDialogViewModel.ShowYesNoCancel(message); /// /// When has finished, show a message dialog with the error if the task failed. /// /// /// Call this on the main thread. Use if spinning of a task that you don't care about the result, but don't want to fail silently. /// /// /// public static Task ErrorIfFail(this Task task, bool shouldLog = true) { return task.ContinueWith(async t => { if(t.Exception is AggregateException e && e.InnerException is not null) { MobileLogging.Log(e); await ShowError(e.InnerException); } else if(t.Exception is not null) { MobileLogging.Log(t.Exception); await ShowError(t.Exception); } }, TaskScheduler.FromCurrentSynchronizationContext()); } }