mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 00:46:12 +02:00
Show error dialogs on UI thread using Dispatcher.InvokeAsync
This commit is contained in:
@@ -202,6 +202,8 @@ public partial class PluginWindow : Window, IPluginWindow
|
||||
if (pluginClassInstance is null && !File.Exists($"{PluginFolderPath}\\main.dll"))
|
||||
{
|
||||
App.Logger.LogError($"\"{PluginMetadata.Name}\" - File \"main.dll\" does not exist", source: "Plugin");
|
||||
_ = await Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox
|
||||
{
|
||||
Title = $"Error \"{PluginMetadata.Name}\"",
|
||||
@@ -209,6 +211,7 @@ public partial class PluginWindow : Window, IPluginWindow
|
||||
CloseButtonText = "Ok"
|
||||
};
|
||||
_ = await messageBox.ShowDialogAsync();
|
||||
});
|
||||
|
||||
Exit();
|
||||
return;
|
||||
@@ -277,6 +280,8 @@ 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");
|
||||
_ = await Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox
|
||||
{
|
||||
Title = $"Error \"{PluginMetadata.Name}\"",
|
||||
@@ -284,6 +289,7 @@ public partial class PluginWindow : Window, IPluginWindow
|
||||
CloseButtonText = "Ok"
|
||||
};
|
||||
_ = await messageBox.ShowDialogAsync();
|
||||
});
|
||||
Exit();
|
||||
return;
|
||||
}
|
||||
@@ -298,6 +304,8 @@ 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");
|
||||
_ = await Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox
|
||||
{
|
||||
Title = $"Error \"{PluginMetadata.Name}\"",
|
||||
@@ -305,6 +313,7 @@ public partial class PluginWindow : Window, IPluginWindow
|
||||
CloseButtonText = "Ok"
|
||||
};
|
||||
_ = await messageBox.ShowDialogAsync();
|
||||
});
|
||||
Exit();
|
||||
return;
|
||||
}
|
||||
@@ -413,10 +422,7 @@ public partial class PluginWindow : Window, IPluginWindow
|
||||
|
||||
try
|
||||
{
|
||||
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||
FieldInfo[] props = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetField);
|
||||
#pragma warning restore S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||
|
||||
List<SettingElement> settingElements = [];
|
||||
foreach (FieldInfo prop in props)
|
||||
{
|
||||
@@ -458,6 +464,8 @@ public partial class PluginWindow : Window, IPluginWindow
|
||||
{
|
||||
IsRunning = false;
|
||||
App.Logger.LogError($"\"{PluginMetadata.Name}\" - {ex}", source: "Plugin");
|
||||
_ = await Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox
|
||||
{
|
||||
Title = $"Error \"{PluginMetadata.Name}\"",
|
||||
@@ -465,6 +473,7 @@ public partial class PluginWindow : Window, IPluginWindow
|
||||
CloseButtonText = "Ok"
|
||||
};
|
||||
_ = await messageBox.ShowDialogAsync();
|
||||
});
|
||||
Exit();
|
||||
}
|
||||
}
|
||||
@@ -481,10 +490,8 @@ public partial class PluginWindow : Window, IPluginWindow
|
||||
return;
|
||||
}
|
||||
|
||||
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||
FieldInfo[] fields = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
PropertyInfo[] properties = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
#pragma warning restore S3011
|
||||
|
||||
// Load fields
|
||||
foreach (FieldInfo field in fields)
|
||||
@@ -546,10 +553,8 @@ public partial class PluginWindow : Window, IPluginWindow
|
||||
|
||||
try
|
||||
{
|
||||
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||
FieldInfo[] fields = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
PropertyInfo[] properties = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
#pragma warning restore S3011
|
||||
|
||||
// Save fields
|
||||
foreach (FieldInfo field in fields)
|
||||
@@ -655,6 +660,8 @@ public partial class PluginWindow : Window, IPluginWindow
|
||||
{
|
||||
IsRunning = false;
|
||||
App.Logger.LogError($"\"{PluginMetadata.Name}\" - {ex}", source: "Plugin");
|
||||
_ = await Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
Wpf.Ui.Controls.MessageBox messageBox = new Wpf.Ui.Controls.MessageBox
|
||||
{
|
||||
Title = $"Error \"{PluginMetadata.Name}\"",
|
||||
@@ -662,6 +669,7 @@ public partial class PluginWindow : Window, IPluginWindow
|
||||
CloseButtonText = "Ok"
|
||||
};
|
||||
_ = await messageBox.ShowDialogAsync();
|
||||
});
|
||||
Exit();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user