From 0804738e45dbf3d20dccfe09d6766959a7c0c5bc Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Mon, 29 Dec 2025 00:35:23 +0100 Subject: [PATCH] Update message box style to new style --- src/DesktopMagic/App.xaml.cs | 10 ++- src/DesktopMagic/Dialogs/ThemeDialog.xaml | 4 +- src/DesktopMagic/Dialogs/ThemeDialog.xaml.cs | 6 +- .../Helpers/SettingElementGenerator.cs | 10 ++- src/DesktopMagic/Helpers/StartupManager.cs | 21 ++++-- src/DesktopMagic/MainWindow.xaml.cs | 14 +++- src/DesktopMagic/Manager.cs | 4 +- src/DesktopMagic/Pages/MainPage.xaml.cs | 36 +++++++-- src/DesktopMagic/Pages/ThemePage.xaml.cs | 34 +++++++-- src/DesktopMagic/Plugins/PluginData.cs | 13 +++- .../Plugins/PluginManager.xaml.cs | 72 +++++++++++++++--- src/DesktopMagic/Plugins/PluginWindow.xaml.cs | 73 +++++++++++++++---- .../Plugins/WebPluginWindow.xaml.cs | 21 +++++- 13 files changed, 249 insertions(+), 69 deletions(-) diff --git a/src/DesktopMagic/App.xaml.cs b/src/DesktopMagic/App.xaml.cs index 20acbf9..da9e781 100644 --- a/src/DesktopMagic/App.xaml.cs +++ b/src/DesktopMagic/App.xaml.cs @@ -134,7 +134,7 @@ public partial class App : Application Logger.LogFatal(exception + (e.IsTerminating ? "\t Process terminating!" : ""), source: exception.Source ?? "Unknown"); } - private static void Setup(bool clearLogFile) + private static async void Setup(bool clearLogFile) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; @@ -160,7 +160,13 @@ public partial class App : Application } catch (Exception ex) { - _ = MessageBox.Show(ex.ToString(), AppName, MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = AppName, + Content = ex.ToString(), + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); Logger.Log(ex.Message, "Setup", LogSeverity.Error); } diff --git a/src/DesktopMagic/Dialogs/ThemeDialog.xaml b/src/DesktopMagic/Dialogs/ThemeDialog.xaml index cf31ce8..826709f 100644 --- a/src/DesktopMagic/Dialogs/ThemeDialog.xaml +++ b/src/DesktopMagic/Dialogs/ThemeDialog.xaml @@ -56,10 +56,10 @@ - + - + diff --git a/src/DesktopMagic/Dialogs/ThemeDialog.xaml.cs b/src/DesktopMagic/Dialogs/ThemeDialog.xaml.cs index 16642fb..65e91d6 100644 --- a/src/DesktopMagic/Dialogs/ThemeDialog.xaml.cs +++ b/src/DesktopMagic/Dialogs/ThemeDialog.xaml.cs @@ -115,7 +115,7 @@ public partial class ThemeDialog : Wpf.Ui.Controls.FluentWindow private void MarginTextBox_ValueChanged(object sender, Wpf.Ui.Controls.NumberBoxValueChangedEventArgs args) { - if (args.NewValue != null) + if (args.NewValue is >= 0) { theme.Margin = (int)args.NewValue; } @@ -123,9 +123,9 @@ public partial class ThemeDialog : Wpf.Ui.Controls.FluentWindow private void CornerRadiusTextBox_ValueChanged(object sender, Wpf.Ui.Controls.NumberBoxValueChangedEventArgs args) { - if (args.NewValue != null) + if (args.NewValue is >= 0) { - theme.Margin = (int)args.NewValue; + theme.CornerRadius = (int)args.NewValue; } } } \ No newline at end of file diff --git a/src/DesktopMagic/Helpers/SettingElementGenerator.cs b/src/DesktopMagic/Helpers/SettingElementGenerator.cs index f53b602..c21acd7 100644 --- a/src/DesktopMagic/Helpers/SettingElementGenerator.cs +++ b/src/DesktopMagic/Helpers/SettingElementGenerator.cs @@ -219,10 +219,16 @@ internal class SettingElementGenerator(uint pluginId) return null; } - private void DisplayException(string message) + private async void DisplayException(string message) { App.Logger.LogInfo(message, source: "PluginInput"); - _ = System.Windows.MessageBox.Show("File execution error:\n" + message, "Error", System.Windows.MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = "Error", + Content = "File execution error:\n" + message, + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); int index = Manager.Instance.PluginWindows.FindIndex(p => p.PluginMetadata.Id == pluginId); if (index >= 0 && index < Manager.Instance.PluginWindows.Count) diff --git a/src/DesktopMagic/Helpers/StartupManager.cs b/src/DesktopMagic/Helpers/StartupManager.cs index 77bdec8..5772cec 100644 --- a/src/DesktopMagic/Helpers/StartupManager.cs +++ b/src/DesktopMagic/Helpers/StartupManager.cs @@ -3,7 +3,6 @@ using System; using System.IO; using System.Reflection; -using System.Windows; namespace DesktopMagic.Helpers; @@ -67,16 +66,24 @@ public static class StartupManager } } - public static void ToggleAutoStart() + public static async void ToggleAutoStart() { AutoStartStatus status = IsAutoStartEnabled() ? DisableAutoStart() : EnableAutoStart(); - _ = status switch + string message = status switch { - AutoStartStatus.Success => MessageBox.Show("Auto-start setting changed successfully."), - AutoStartStatus.AlreadyEnabled => MessageBox.Show("Auto-start is already enabled."), - AutoStartStatus.AlreadyDisabled => MessageBox.Show("Auto-start is already disabled."), - _ => MessageBox.Show("Failed to change auto-start setting."), + AutoStartStatus.Success => "Auto-start setting changed successfully.", + AutoStartStatus.AlreadyEnabled => "Auto-start is already enabled.", + AutoStartStatus.AlreadyDisabled => "Auto-start is already disabled.", + _ => "Failed to change auto-start setting.", }; + + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = App.AppName, + Content = message, + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); } } \ No newline at end of file diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs index 8f8eae5..6a48f11 100644 --- a/src/DesktopMagic/MainWindow.xaml.cs +++ b/src/DesktopMagic/MainWindow.xaml.cs @@ -22,13 +22,12 @@ public partial class MainWindow : FluentWindow InitializeComponent(); DataContext = _mainWindowDataContext; - _mainWindowDataContext.Settings = _manager.Settings; Resources.MergedDictionaries.Add(App.LanguageDictionary); App.DialogService.SetDialogHost(rootContentDialog); } - private void Window_Loaded(object sender, RoutedEventArgs e) + private async void Window_Loaded(object sender, RoutedEventArgs e) { try { @@ -37,8 +36,9 @@ public partial class MainWindow : FluentWindow _mainWindowDataContext.IsLoading = true; // Load plugins and settings through manager - _manager.LoadPlugins(); _manager.LoadSettings(); + _mainWindowDataContext.Settings = _manager.Settings; + _manager.LoadPlugins(); _manager.LoadLayout(); _manager.IsLoaded = true; @@ -49,7 +49,13 @@ public partial class MainWindow : FluentWindow catch (Exception ex) { App.Logger.LogError(ex.Message, source: "MainWindow"); - _ = System.Windows.MessageBox.Show(ex.ToString(), App.AppName, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = App.AppName, + Content = ex.ToString(), + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); } } diff --git a/src/DesktopMagic/Manager.cs b/src/DesktopMagic/Manager.cs index ccbd0a3..b341a34 100644 --- a/src/DesktopMagic/Manager.cs +++ b/src/DesktopMagic/Manager.cs @@ -86,7 +86,7 @@ public sealed class Manager _plugins.Clear(); // Load built-in plugins - foreach (var builtInPlugin in _builtInPlugins.Keys) + foreach (PluginMetadata builtInPlugin in _builtInPlugins.Keys) { _plugins.Add(builtInPlugin.Id, new(builtInPlugin, PluginType.DotNet, string.Empty)); } @@ -318,7 +318,7 @@ public sealed class Manager } // Remove plugins that are not loaded anymore - var pluginIdsToRemove = Settings.CurrentLayout.Plugins.Keys.Where(id => !_plugins.ContainsKey(id)).ToList(); + List pluginIdsToRemove = Settings.CurrentLayout.Plugins.Keys.Where(id => !_plugins.ContainsKey(id)).ToList(); foreach (uint pluginId in pluginIdsToRemove) { Settings.CurrentLayout.Plugins.Remove(pluginId); diff --git a/src/DesktopMagic/Pages/MainPage.xaml.cs b/src/DesktopMagic/Pages/MainPage.xaml.cs index 3a6dc29..a199ceb 100644 --- a/src/DesktopMagic/Pages/MainPage.xaml.cs +++ b/src/DesktopMagic/Pages/MainPage.xaml.cs @@ -139,7 +139,7 @@ public partial class MainPage : Page } } - private void NewLayoutButton_Click(object sender, RoutedEventArgs e) + private async void NewLayoutButton_Click(object sender, RoutedEventArgs e) { InputDialog inputDialog = new((string)FindResource("enterLayoutName")) { @@ -150,7 +150,13 @@ public partial class MainPage : Page { if (_manager.Settings.Layouts.Any(l => l.Name.Trim() == inputDialog.ResponseText.Trim())) { - _ = System.Windows.MessageBox.Show((string)FindResource("layoutAlreadyExists"), App.AppName, MessageBoxButton.OK, MessageBoxImage.Warning); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = App.AppName, + Content = (string)FindResource("layoutAlreadyExists"), + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); return; } @@ -168,16 +174,30 @@ public partial class MainPage : Page } } - private void RemoveLayoutButton_Click(object sender, RoutedEventArgs e) + private async void RemoveLayoutButton_Click(object sender, RoutedEventArgs e) { if (_manager.Settings.Layouts.Count <= 1) { - _ = System.Windows.MessageBox.Show((string)FindResource("cannotDeleteLastLayout"), App.AppName, MessageBoxButton.OK, MessageBoxImage.Warning); + Wpf.Ui.Controls.MessageBox cannotDeleteMessageBox = new Wpf.Ui.Controls.MessageBox + { + Title = App.AppName, + Content = (string)FindResource("cannotDeleteLastLayout"), + CloseButtonText = "Ok" + }; + _ = await cannotDeleteMessageBox.ShowDialogAsync(); return; } - MessageBoxResult result = System.Windows.MessageBox.Show((string)FindResource("confirmDeleteLayout"), App.AppName, MessageBoxButton.YesNo, MessageBoxImage.Question); - if (result != MessageBoxResult.Yes) + var messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = App.AppName, + Content = (string)FindResource("confirmDeleteLayout"), + PrimaryButtonText = "Yes", + SecondaryButtonText = "No", + IsCloseButtonEnabled = false + }; + Wpf.Ui.Controls.MessageBoxResult result = await messageBox.ShowDialogAsync(); + if (result != Wpf.Ui.Controls.MessageBoxResult.Primary) // Primary is "Yes" { return; } @@ -217,7 +237,7 @@ public partial class MainPage : Page // s.Input being null means the plugins has not been loaded yet but the settings are present in the saved configuration. if (pluginSettings is null || pluginSettings.Settings.Count == 0 || pluginSettings.Settings.All(s => s.Input is null)) { - _ = optionsPanel.Children.Add(new TextBlock() + _ = optionsPanel.Children.Add(new System.Windows.Controls.TextBlock() { Text = (string)FindResource(pluginSettings?.Enabled == true ? "noOptions" : "enablePluginToConfigure") }); @@ -235,7 +255,7 @@ public partial class MainPage : Page Padding = new Thickness(5) }; - TextBlock textBlock = new() + System.Windows.Controls.TextBlock textBlock = new() { Text = string.IsNullOrWhiteSpace(settingElement.Name) ? string.Empty : settingElement.Name, Padding = new Thickness(0, 0, 3, 0), diff --git a/src/DesktopMagic/Pages/ThemePage.xaml.cs b/src/DesktopMagic/Pages/ThemePage.xaml.cs index 06186d5..1bfa67d 100644 --- a/src/DesktopMagic/Pages/ThemePage.xaml.cs +++ b/src/DesktopMagic/Pages/ThemePage.xaml.cs @@ -47,7 +47,7 @@ public partial class ThemePage : Page }); } - private void AddThemeButton_Click(object sender, RoutedEventArgs e) + private async void AddThemeButton_Click(object sender, RoutedEventArgs e) { InputDialog inputDialog = new((string)FindResource("enterThemeName")) { @@ -58,7 +58,13 @@ public partial class ThemePage : Page { if (_manager.Settings.Themes.Any(l => l.Name.Trim() == inputDialog.ResponseText.Trim())) { - _ = System.Windows.MessageBox.Show((string)FindResource("themeAlreadyExists"), App.AppName, MessageBoxButton.OK, MessageBoxImage.Warning); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = App.AppName, + Content = (string)FindResource("themeAlreadyExists"), + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); return; } @@ -68,16 +74,30 @@ public partial class ThemePage : Page } } - private void DeleteThemeButton_Click(object sender, RoutedEventArgs e) + private async void DeleteThemeButton_Click(object sender, RoutedEventArgs e) { if (_manager.Settings.Themes.Count <= 1) { - _ = System.Windows.MessageBox.Show((string)FindResource("cannotDeleteLastTheme"), App.AppName, MessageBoxButton.OK, MessageBoxImage.Warning); + Wpf.Ui.Controls.MessageBox cannotDeleteMessageBox = new Wpf.Ui.Controls.MessageBox + { + Title = App.AppName, + Content = (string)FindResource("cannotDeleteLastTheme"), + CloseButtonText = "Ok" + }; + _ = await cannotDeleteMessageBox.ShowDialogAsync(); return; } - MessageBoxResult result = System.Windows.MessageBox.Show((string)FindResource("confirmDeleteTheme"), App.AppName, MessageBoxButton.YesNo, MessageBoxImage.Question); - if (result != MessageBoxResult.Yes) + var messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = App.AppName, + Content = (string)FindResource("confirmDeleteTheme"), + PrimaryButtonText = "Yes", + SecondaryButtonText = "No", + IsCloseButtonEnabled = false + }; + Wpf.Ui.Controls.MessageBoxResult result = await messageBox.ShowDialogAsync(); + if (result != Wpf.Ui.Controls.MessageBoxResult.Primary) // Primary is "Yes" { return; } @@ -91,7 +111,7 @@ public partial class ThemePage : Page private void EditThemeButton_Click(object sender, RoutedEventArgs e) { - if (sender is not Button button || button.Tag is not Theme theme) + if (sender is not System.Windows.Controls.Button button || button.Tag is not Theme theme) { return; } diff --git a/src/DesktopMagic/Plugins/PluginData.cs b/src/DesktopMagic/Plugins/PluginData.cs index fd53d7e..92fd242 100644 --- a/src/DesktopMagic/Plugins/PluginData.cs +++ b/src/DesktopMagic/Plugins/PluginData.cs @@ -5,6 +5,8 @@ using DesktopMagic.Settings; using System.Drawing; +using Wpf.Ui.Controls; + namespace DesktopMagic.Plugins; internal class PluginData(PluginWindow window, PluginSettings pluginSettings) : IPluginData @@ -38,7 +40,7 @@ internal class PluginData(PluginWindow window, PluginSettings pluginSettings) : { title ??= PluginName; - window.Dispatcher.Invoke(() => + _ = window.Dispatcher.Invoke(async () => { System.Windows.Window temporaryOwner = new() { @@ -51,7 +53,14 @@ internal class PluginData(PluginWindow window, PluginSettings pluginSettings) : temporaryOwner.Show(); - _ = System.Windows.MessageBox.Show(temporaryOwner, message, $"{App.AppName} - {title}"); + MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Owner = temporaryOwner, + Title = $"{App.AppName} - {title}", + Content = message, + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); temporaryOwner.Close(); }); diff --git a/src/DesktopMagic/Plugins/PluginManager.xaml.cs b/src/DesktopMagic/Plugins/PluginManager.xaml.cs index 2047371..b8ddc50 100644 --- a/src/DesktopMagic/Plugins/PluginManager.xaml.cs +++ b/src/DesktopMagic/Plugins/PluginManager.xaml.cs @@ -191,7 +191,13 @@ public partial class PluginManager : Page } catch (Exception ex) { - _ = MessageBox.Show(ex.Message, "Plugin Manager", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = "Plugin Manager", + Content = ex.Message, + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); App.Logger.LogError(ex.Message, source: "PluginManager"); } } @@ -261,9 +267,15 @@ public partial class PluginManager : Page if (!File.Exists(Path.Combine(pluginPath, "main.dll")) && !File.Exists(Path.Combine(pluginPath, "main.html"))) { App.Logger.LogError($"Plugin {mod.Id} does not contain main.dll or main.html", source: "PluginManager"); - _ = Remove(pluginPath, mod.Id); + await Remove(pluginPath, mod.Id); pluginManagerDataContext.IsLoading = false; - _ = MessageBox.Show("The plugin you are trying to install does not contain a \"main.dll\" or \"main.html\" file. Please contact the plugin author.", "Plugin Manager", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = "Plugin Manager", + Content = "The plugin you are trying to install does not contain a \"main.dll\" or \"main.html\" file. Please contact the plugin author.", + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); return; } @@ -293,7 +305,13 @@ public partial class PluginManager : Page catch (Exception ex) { App.Logger.LogError($"Failed to install plugin {mod.Id}: {ex.Message}", source: "PluginManager"); - _ = MessageBox.Show($"Failed to install plugin: {ex.Message}", "Plugin Manager", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = "Plugin Manager", + Content = $"Failed to install plugin: {ex.Message}", + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); } pluginManagerDataContext.IsLoading = false; @@ -370,27 +388,39 @@ public partial class PluginManager : Page pluginManagerDataContext.IsSearching = false; } - private void CreatePluginButton_Click(object sender, RoutedEventArgs e) + private async void CreatePluginButton_Click(object sender, RoutedEventArgs e) { try { - CreateNewPlugin(); + await CreateNewPlugin(); } catch (Exception ex) { App.Logger.LogError(ex.Message, source: "PluginManager"); - _ = MessageBox.Show(ex.Message, "Plugin Manager", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = "Plugin Manager", + Content = ex.Message, + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); } } - private void CreateNewPlugin() + private async Task CreateNewPlugin() { App.Logger.LogInfo("Creating new plugin", source: "PluginManager"); if (!FileUtilities.ExistsOnPath("dotnet.exe")) { App.Logger.LogError(".NET SDK not found on PATH", source: "PluginManager"); - _ = MessageBox.Show("The .NET SDK is required to create a plugin. Please install it and try again.", "Plugin Manager", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = "Plugin Manager", + Content = "The .NET SDK is required to create a plugin. Please install it and try again.", + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); return; } @@ -428,7 +458,13 @@ public partial class PluginManager : Page if (Directory.Exists(pluginProjectPath)) { App.Logger.LogWarn($"Plugin project already exists: {pluginProjectPath}", source: "PluginManager"); - _ = MessageBox.Show("A plugin with the same name already exists. Please choose a different name.", "Plugin Manager", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = "Plugin Manager", + Content = "A plugin with the same name already exists. Please choose a different name.", + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); return; } @@ -524,7 +560,13 @@ public class {pluginSafeName}Plugin : Plugin else { App.Logger.LogError("PropertyGroup element not found in .csproj", source: "PluginManager"); - _ = MessageBox.Show("PropertyGroup element not found in .csproj", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = "Error", + Content = "PropertyGroup element not found in .csproj", + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); return; } @@ -622,7 +664,13 @@ public class {pluginSafeName}Plugin : Plugin catch (Exception ex) { App.Logger.LogError($"Authentication failed: {ex.Message}", source: "PluginManager"); - _ = MessageBox.Show(ex.Message, "Plugin Manager", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = "Plugin Manager", + Content = ex.Message, + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); } pluginManagerDataContext.IsLoading = false; diff --git a/src/DesktopMagic/Plugins/PluginWindow.xaml.cs b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs index d656d89..3942518 100644 --- a/src/DesktopMagic/Plugins/PluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs @@ -16,6 +16,7 @@ using System.Reflection; using System.Runtime.Loader; using System.Text.Json; using System.Threading; +using System.Threading.Tasks; using System.Timers; using System.Windows; using System.Windows.Interop; @@ -72,6 +73,11 @@ public partial class PluginWindow : Window, IPluginWindow } }; + settings.Theme.PropertyChanged += (se, ev) => + { + ThemeChanged(); + }; + PluginMetadata = pluginMetadata; this.settings = settings; @@ -183,18 +189,24 @@ public partial class PluginWindow : Window, IPluginWindow private void Window_ContentRendered(object? sender, EventArgs e) { App.Logger.LogInfo($"\"{PluginMetadata.Name}\" - Starting plugin thread", source: "Plugin"); - pluginThread = new Thread(LoadPlugin); + pluginThread = new Thread(async () => await LoadPlugin()); pluginThread.Start(); } - private void LoadPlugin() + private async Task LoadPlugin() { App.Logger.LogInfo($"\"{PluginMetadata.Name}\" - Loading plugin", source: "Plugin"); if (pluginClassInstance is null && !File.Exists($"{PluginFolderPath}\\main.dll")) { App.Logger.LogError($"\"{PluginMetadata.Name}\" - File \"main.dll\" does not exist", source: "Plugin"); - _ = MessageBox.Show("File \"main.dll\" does not exist!", $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = $"Error \"{PluginMetadata.Name}\"", + Content = "File \"main.dll\" does not exist!", + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); Exit(); return; @@ -202,18 +214,24 @@ public partial class PluginWindow : Window, IPluginWindow try { - ExecuteSource(); + await ExecuteSource(); } catch (Exception ex) { App.Logger.LogError($"\"{PluginMetadata.Name}\" - {ex}", source: "Plugin"); - _ = MessageBox.Show("File execution error:\n" + ex, $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = $"Error \"{PluginMetadata.Name}\"", + Content = "File execution error:\n" + ex, + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); Exit(); return; } PluginLoaded?.Invoke(); - _ = Dispatcher.Invoke(() => busyMask.IsBusy = false); + _ = await Dispatcher.InvokeAsync(() => busyMask.IsBusy = false); } private void ThemeChanged() @@ -230,7 +248,7 @@ public partial class PluginWindow : Window, IPluginWindow } } - private void ExecuteSource() + private async Task ExecuteSource() { object? instance = pluginClassInstance; if (instance is null) @@ -239,7 +257,7 @@ public partial class PluginWindow : Window, IPluginWindow if (PluginMetadata.SupportsUnloading) { - byte[] assemblyData = File.ReadAllBytes($"{PluginFolderPath}\\main.dll"); + byte[] assemblyData = await File.ReadAllBytesAsync($"{PluginFolderPath}\\main.dll"); using MemoryStream assemblyStream = new(assemblyData); dll = assemblyLoadContext.LoadFromStream(assemblyStream); @@ -254,8 +272,13 @@ public partial class PluginWindow : Window, IPluginWindow if (instanceType is null) { App.Logger.LogError($"\"{PluginMetadata.Name}\" - The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", source: "Plugin"); - _ = MessageBox.Show($"The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error); - + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = $"Error \"{PluginMetadata.Name}\"", + Content = $"The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); Exit(); return; } @@ -270,13 +293,19 @@ public partial class PluginWindow : Window, IPluginWindow else { App.Logger.LogError($"\"{PluginMetadata.Name}\" - The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", source: "Plugin"); - _ = MessageBox.Show($"The \"Plugin\" class has to inherit from \"{typeof(Plugin).FullName}\"", $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = $"Error \"{PluginMetadata.Name}\"", + Content = $"The \"Plugin\" class has to inherit from \"{typeof(Plugin).FullName}\"", + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); Exit(); return; } LoadState(pluginClassInstance); - LoadOptions(pluginClassInstance); + await LoadOptions(pluginClassInstance); BindDefaultSettings(pluginClassInstance); updateTimer = new System.Timers.Timer @@ -287,7 +316,7 @@ public partial class PluginWindow : Window, IPluginWindow pluginClassInstance.Start(); UpdatePluginWindow(); - Dispatcher.Invoke(ThemeChanged); + await Dispatcher.InvokeAsync(ThemeChanged); if (pluginClassInstance.UpdateInterval > 0) { @@ -367,7 +396,7 @@ public partial class PluginWindow : Window, IPluginWindow } } - private void LoadOptions(object instance) + private async Task LoadOptions(object instance) { App.Logger.LogInfo($"\"{PluginMetadata.Name}\" - Loading plugin options", source: "Plugin"); @@ -418,7 +447,13 @@ public partial class PluginWindow : Window, IPluginWindow { IsRunning = false; App.Logger.LogError($"\"{PluginMetadata.Name}\" - {ex}", source: "Plugin"); - _ = MessageBox.Show("File execution error:\n" + ex, $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = $"Error \"{PluginMetadata.Name}\"", + Content = "File execution error:\n" + ex, + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); Exit(); } } @@ -608,7 +643,13 @@ public partial class PluginWindow : Window, IPluginWindow { IsRunning = false; App.Logger.LogError($"\"{PluginMetadata.Name}\" - {ex}", source: "Plugin"); - _ = MessageBox.Show("File execution error:\n" + ex, $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = $"Error \"{PluginMetadata.Name}\"", + Content = "File execution error:\n" + ex, + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); Exit(); return; } diff --git a/src/DesktopMagic/Plugins/WebPluginWindow.xaml.cs b/src/DesktopMagic/Plugins/WebPluginWindow.xaml.cs index 9c9f27b..ff92680 100644 --- a/src/DesktopMagic/Plugins/WebPluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugins/WebPluginWindow.xaml.cs @@ -57,6 +57,11 @@ public partial class WebPluginWindow : Window, IPluginWindow } }; + settings.Theme.PropertyChanged += (se, ev) => + { + ThemeChanged(); + }; + PluginMetadata = pluginMetadata; this.settings = settings; @@ -122,7 +127,13 @@ public partial class WebPluginWindow : Window, IPluginWindow catch (Exception ex) { App.Logger.LogError($"\"{PluginMetadata.Name}\" - {ex}", source: "WebPlugin"); - _ = MessageBox.Show("WebView2 initialization error:\n" + ex, $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = $"Error \"{PluginMetadata.Name}\"", + Content = "WebView2 initialization error:\n" + ex, + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); Exit(); } } @@ -169,7 +180,13 @@ public partial class WebPluginWindow : Window, IPluginWindow if (!File.Exists(htmlPath)) { App.Logger.LogError($"\"{PluginMetadata.Name}\" - File \"main.html\" does not exist", source: "WebPlugin"); - _ = MessageBox.Show("File \"main.html\" does not exist!", $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error); + Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox + { + Title = $"Error \"{PluginMetadata.Name}\"", + Content = "File \"main.html\" does not exist!", + CloseButtonText = "Ok" + }; + _ = await messageBox.ShowDialogAsync(); Exit(); return; }