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
+23 -16
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;
Bitmap result = pluginClassInstance.Main(); try
if (pluginClassInstance.UpdateInterval > 0)
{ {
valueTimer.Interval = pluginClassInstance.UpdateInterval; Bitmap result = pluginClassInstance.Main();
if (pluginClassInstance.UpdateInterval > 0)
{
valueTimer.Interval = pluginClassInstance.UpdateInterval;
}
else
{
valueTimer.Stop();
}
//Update Image
Dispatcher.Invoke(() =>
{
image.Source = BitmapToImageSource(result);
});
} }
catch (Exception ex)
//Update Image
Dispatcher.Invoke(() =>
{ {
image.Source = BitmapToImageSource(result); MainWindow.Logger.Log(ex.ToString(), "Plugin");
}); MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Exit();
return;
}
if (stop) if (stop)
{ {