diff --git a/Source/LibationWinForms/AvaloniaUI/FormSaveExtension2.cs b/Source/LibationWinForms/AvaloniaUI/FormSaveExtension2.cs index 9c009df4..1edcf955 100644 --- a/Source/LibationWinForms/AvaloniaUI/FormSaveExtension2.cs +++ b/Source/LibationWinForms/AvaloniaUI/FormSaveExtension2.cs @@ -102,15 +102,15 @@ namespace LibationWinForms.AvaloniaUI if (Design.IsDesignMode) return; -#if WINDOWS7_0 - var handle = form.PlatformImpl.Handle.Handle; +#if WINDOWS7_0_OR_GREATER + var handle = form.PlatformImpl.Handle.Handle; var currentStyle = GetWindowLong(handle, GWL_STYLE); SetWindowLong(handle, GWL_STYLE, currentStyle & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX); #endif } -#if WINDOWS7_0 +#if WINDOWS7_0_OR_GREATER const long WS_MINIMIZEBOX = 0x00020000L; const long WS_MAXIMIZEBOX = 0x10000L; const int GWL_STYLE = -16; diff --git a/Source/LibationWinForms/AvaloniaUI/MessageBox.cs b/Source/LibationWinForms/AvaloniaUI/MessageBox.cs index 1fc42833..97020c89 100644 --- a/Source/LibationWinForms/AvaloniaUI/MessageBox.cs +++ b/Source/LibationWinForms/AvaloniaUI/MessageBox.cs @@ -224,6 +224,31 @@ namespace LibationWinForms.AvaloniaUI defaultButton); } + /// + /// Logs error. Displays a message box dialog with specified text and caption. + /// + /// Form calling this method. + /// The text to display in the message box. + /// The text to display in the title bar of the message box. + /// Exception to log. + public static async Task ShowAdminAlert(Window owner, string text, string caption, Exception exception) + { + // for development and debugging, show me what broke! + if (System.Diagnostics.Debugger.IsAttached) + throw exception; + + try + { + Serilog.Log.Logger.Error(exception, "Alert admin error: {@DebugText}", new { text, caption }); + } + catch { } + + var form = new MessageBoxAlertAdminDialog(text, caption, exception); + + await DisplayWindow(form, owner); + } + + private static async Task ShowCore(Window owner, string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) { if (Avalonia.Threading.Dispatcher.UIThread.CheckAccess()) @@ -264,11 +289,15 @@ namespace LibationWinForms.AvaloniaUI dialog.Height = dialog.MinHeight; dialog.Width = dialog.MinWidth; + return await DisplayWindow(dialog, owner); + } + private static async Task DisplayWindow(Window toDisplay, Window owner) + { if (owner is null) { if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - return await dialog.ShowDialog(desktop.MainWindow); + return await toDisplay.ShowDialog(desktop.MainWindow); } else { @@ -282,7 +311,7 @@ namespace LibationWinForms.AvaloniaUI }; window.Show(); - var result = await dialog.ShowDialog(window); + var result = await toDisplay.ShowDialog(window); window.Close(); return result; } @@ -290,7 +319,7 @@ namespace LibationWinForms.AvaloniaUI } else { - return await dialog.ShowDialog(owner); + return await toDisplay.ShowDialog(owner); } } diff --git a/Source/LibationWinForms/AvaloniaUI/ViewModels/ProductsDisplayViewModel.cs b/Source/LibationWinForms/AvaloniaUI/ViewModels/ProductsDisplayViewModel.cs index 031deb2a..8adbe2e1 100644 --- a/Source/LibationWinForms/AvaloniaUI/ViewModels/ProductsDisplayViewModel.cs +++ b/Source/LibationWinForms/AvaloniaUI/ViewModels/ProductsDisplayViewModel.cs @@ -316,7 +316,7 @@ namespace LibationWinForms.AvaloniaUI.ViewModels } catch (Exception ex) { - MessageBoxLib.ShowAdminAlert( + await MessageBox.ShowAdminAlert( null, "Error scanning library. You may still manually select books to remove from Libation's library.", "Error scanning library", diff --git a/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/AccountsDialog.axaml.cs b/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/AccountsDialog.axaml.cs index d12640b4..26cf4561 100644 --- a/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/AccountsDialog.axaml.cs +++ b/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/AccountsDialog.axaml.cs @@ -101,8 +101,8 @@ namespace LibationWinForms.AvaloniaUI.Views.Dialogs } catch (Exception ex) { - MessageBoxLib.ShowAdminAlert( - null, + await MessageBox.ShowAdminAlert( + this, $"An error occurred while importing an account from:\r\n{filePath[0]}\r\n\r\nIs the file encrypted?", "Error Importing Account", ex); @@ -149,7 +149,7 @@ namespace LibationWinForms.AvaloniaUI.Views.Dialogs } catch (Exception ex) { - MessageBoxLib.ShowAdminAlert(null, "Error attempting to save accounts", "Error saving accounts", ex); + await MessageBox.ShowAdminAlert(this, "Error attempting to save accounts", "Error saving accounts", ex); } } @@ -259,8 +259,8 @@ namespace LibationWinForms.AvaloniaUI.Views.Dialogs } catch (Exception ex) { - MessageBoxLib.ShowAdminAlert( - null, + await MessageBox.ShowAdminAlert( + this, $"An error occurred while exporting account:\r\n{account.AccountName}", "Error Exporting Account", ex); diff --git a/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/MessageBoxAlertAdminDialog.axaml b/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/MessageBoxAlertAdminDialog.axaml new file mode 100644 index 00000000..00ed3a2a --- /dev/null +++ b/Source/LibationWinForms/AvaloniaUI/Views/Dialogs/MessageBoxAlertAdminDialog.axaml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +