Skip to content

Commit e204daa

Browse files
committed
Catch exception when creating setting panel
1 parent 51df66e commit e204daa

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

Flow.Launcher/ViewModel/PluginViewModel.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,45 @@ public Control SettingControl
131131
=> IsExpanded
132132
? _settingControl
133133
??= HasSettingControl
134-
? ((ISettingProvider)PluginPair.Plugin).CreateSettingPanel()
134+
? TryCreateSettingPanel(PluginPair)
135135
: null
136136
: null;
137137
private ImageSource _image = ImageLoader.MissingImage;
138138

139+
private static readonly Thickness SettingPanelMargin = (Thickness)Application.Current.FindResource("SettingPanelMargin");
140+
private static readonly Thickness SettingPanelItemTopBottomMargin = (Thickness)Application.Current.FindResource("SettingPanelItemTopBottomMargin");
141+
private static Control TryCreateSettingPanel(PluginPair pair)
142+
{
143+
try
144+
{
145+
// We can safely cast here as we already check this in HasSettingControl
146+
return ((ISettingProvider)pair.Plugin).CreateSettingPanel();
147+
}
148+
catch (System.Exception e)
149+
{
150+
var errorMsg = $"Error creating setting panel for plugin {pair.Metadata}\n{e.Message}";
151+
var grid = new Grid()
152+
{
153+
Margin = SettingPanelMargin
154+
};
155+
var textBox = new TextBox
156+
{
157+
Text = errorMsg,
158+
IsReadOnly = true,
159+
HorizontalAlignment = HorizontalAlignment.Stretch,
160+
VerticalAlignment = VerticalAlignment.Top,
161+
TextWrapping = TextWrapping.Wrap,
162+
Margin = SettingPanelItemTopBottomMargin
163+
};
164+
textBox.SetResourceReference(TextBlock.ForegroundProperty, "Color04B");
165+
grid.Children.Add(textBox);
166+
return new UserControl
167+
{
168+
Content = grid
169+
};
170+
}
171+
}
172+
139173
public Visibility ActionKeywordsVisibility => PluginPair.Metadata.HideActionKeywordPanel ?
140174
Visibility.Collapsed : Visibility.Visible;
141175
public string InitializeTime => PluginPair.Metadata.InitTime + "ms";

0 commit comments

Comments
 (0)