From e9cf43d9687ccd1ae6ff56a623cad7d491e960c4 Mon Sep 17 00:00:00 2001 From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com> Date: Wed, 25 Aug 2021 19:20:45 +0200 Subject: [PATCH] Proper handling and logging of errors during the execution of a plugin --- src/DesktopMagic/Plugin/PluginWindow.xaml.cs | 39 ++++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs index 51dd430..fee07c4 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs @@ -191,13 +191,6 @@ namespace DesktopMagic return; } - if (instanceType.Namespace == nameof(DesktopMagic)) - { - MessageBox.Show("NO!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - Exit(); - return; - } - LoadOptions(instance); valueTimer = new System.Timers.Timer(); @@ -254,18 +247,32 @@ namespace DesktopMagic System.Drawing.Color color = newBrush.Color; string font = MainWindow.GlobalFont; - Bitmap result = pluginClassInstance.Main(); - - if (pluginClassInstance.UpdateInterval > 0) + try { - 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); + }); } - - //Update Image - Dispatcher.Invoke(() => + catch (Exception ex) { - 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) {