Proper handling and logging of errors during the execution of a plugin

This commit is contained in:
Stone-Red-Code
2021-08-25 19:20:45 +02:00
parent 8df53ef190
commit e9cf43d968
+14 -7
View File
@@ -191,13 +191,6 @@ namespace DesktopMagic
return; return;
} }
if (instanceType.Namespace == nameof(DesktopMagic))
{
MessageBox.Show("NO!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Exit();
return;
}
LoadOptions(instance); LoadOptions(instance);
valueTimer = new System.Timers.Timer(); valueTimer = new System.Timers.Timer();
@@ -254,18 +247,32 @@ namespace DesktopMagic
System.Drawing.Color color = newBrush.Color; System.Drawing.Color color = newBrush.Color;
string font = MainWindow.GlobalFont; string font = MainWindow.GlobalFont;
try
{
Bitmap result = pluginClassInstance.Main(); Bitmap result = pluginClassInstance.Main();
if (pluginClassInstance.UpdateInterval > 0) if (pluginClassInstance.UpdateInterval > 0)
{ {
valueTimer.Interval = pluginClassInstance.UpdateInterval; valueTimer.Interval = pluginClassInstance.UpdateInterval;
} }
else
{
valueTimer.Stop();
}
//Update Image //Update Image
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
{ {
image.Source = BitmapToImageSource(result); image.Source = BitmapToImageSource(result);
}); });
}
catch (Exception ex)
{
MainWindow.Logger.Log(ex.ToString(), "Plugin");
MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Exit();
return;
}
if (stop) if (stop)
{ {