Update message box style to new style

This commit is contained in:
Stone_Red
2025-12-29 00:35:23 +01:00
parent 727324ca9a
commit 0804738e45
13 changed files with 249 additions and 69 deletions
+8 -2
View File
@@ -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);
}
+2 -2
View File
@@ -56,10 +56,10 @@
<ComboBox x:Name="fontComboBox" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Top" SelectionChanged="FontComboBox_SelectionChanged" Margin="0,0,0,5" />
<TextBlock Text="Corner Radius: " Grid.Column="0" Grid.Row="1" VerticalAlignment="Center"></TextBlock>
<ui:NumberBox x:Name="cornerRadiusTextBox" Grid.Column="1" Grid.Row="1" ValueChanged="CornerRadiusTextBox_ValueChanged" PlaceholderText="Enter a number" Margin="0,0,0,5" />
<ui:NumberBox x:Name="cornerRadiusTextBox" Minimum="0" Grid.Column="1" Grid.Row="1" ValueChanged="CornerRadiusTextBox_ValueChanged" PlaceholderText="Enter a number" Margin="0,0,0,5" />
<TextBlock Text="Margin: " Grid.Column="0" Grid.Row="3" VerticalAlignment="Center"></TextBlock>
<ui:NumberBox x:Name="marginTextBox" Grid.Column="1" Grid.Row="3" ValueChanged="MarginTextBox_ValueChanged" PlaceholderText="Enter a number"/>
<ui:NumberBox x:Name="marginTextBox" Minimum="0" Grid.Column="1" Grid.Row="3" ValueChanged="MarginTextBox_ValueChanged" PlaceholderText="Enter a number"/>
</Grid>
<Grid Grid.Column="1" Margin="{StaticResource DefaultMargin}" HorizontalAlignment="Stretch">
+3 -3
View File
@@ -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;
}
}
}
@@ -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)
+14 -7
View File
@@ -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();
}
}
+10 -4
View File
@@ -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();
}
}
+2 -2
View File
@@ -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<uint> pluginIdsToRemove = Settings.CurrentLayout.Plugins.Keys.Where(id => !_plugins.ContainsKey(id)).ToList();
foreach (uint pluginId in pluginIdsToRemove)
{
Settings.CurrentLayout.Plugins.Remove(pluginId);
+28 -8
View File
@@ -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),
+27 -7
View File
@@ -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;
}
+11 -2
View File
@@ -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();
});
+60 -12
View File
@@ -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;
+57 -16
View File
@@ -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;
}
@@ -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;
}