From e204daa8443aad283feba9dabeed576e16d13c7e Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 15 Sep 2025 21:33:21 +0800 Subject: [PATCH] Catch exception when creating setting panel --- Flow.Launcher/ViewModel/PluginViewModel.cs | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/ViewModel/PluginViewModel.cs b/Flow.Launcher/ViewModel/PluginViewModel.cs index d889bdd52..36c509902 100644 --- a/Flow.Launcher/ViewModel/PluginViewModel.cs +++ b/Flow.Launcher/ViewModel/PluginViewModel.cs @@ -131,11 +131,45 @@ namespace Flow.Launcher.ViewModel => IsExpanded ? _settingControl ??= HasSettingControl - ? ((ISettingProvider)PluginPair.Plugin).CreateSettingPanel() + ? TryCreateSettingPanel(PluginPair) : null : null; private ImageSource _image = ImageLoader.MissingImage; + private static readonly Thickness SettingPanelMargin = (Thickness)Application.Current.FindResource("SettingPanelMargin"); + private static readonly Thickness SettingPanelItemTopBottomMargin = (Thickness)Application.Current.FindResource("SettingPanelItemTopBottomMargin"); + private static Control TryCreateSettingPanel(PluginPair pair) + { + try + { + // We can safely cast here as we already check this in HasSettingControl + return ((ISettingProvider)pair.Plugin).CreateSettingPanel(); + } + catch (System.Exception e) + { + var errorMsg = $"Error creating setting panel for plugin {pair.Metadata}\n{e.Message}"; + var grid = new Grid() + { + Margin = SettingPanelMargin + }; + var textBox = new TextBox + { + Text = errorMsg, + IsReadOnly = true, + HorizontalAlignment = HorizontalAlignment.Stretch, + VerticalAlignment = VerticalAlignment.Top, + TextWrapping = TextWrapping.Wrap, + Margin = SettingPanelItemTopBottomMargin + }; + textBox.SetResourceReference(TextBlock.ForegroundProperty, "Color04B"); + grid.Children.Add(textBox); + return new UserControl + { + Content = grid + }; + } + } + public Visibility ActionKeywordsVisibility => PluginPair.Metadata.HideActionKeywordPanel ? Visibility.Collapsed : Visibility.Visible; public string InitializeTime => PluginPair.Metadata.InitTime + "ms";