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 1/5] 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 d889bdd52ab..36c50990222 100644
--- a/Flow.Launcher/ViewModel/PluginViewModel.cs
+++ b/Flow.Launcher/ViewModel/PluginViewModel.cs
@@ -131,11 +131,45 @@ public Control SettingControl
=> 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";
From 0355993b009b3e29b399a3fdbc02fba481337303 Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Mon, 15 Sep 2025 21:38:53 +0800
Subject: [PATCH 2/5] Use translation
---
Flow.Launcher/Languages/en.xaml | 1 +
Flow.Launcher/ViewModel/PluginViewModel.cs | 8 +++++---
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml
index f7fd0c8e588..e97bd6cf596 100644
--- a/Flow.Launcher/Languages/en.xaml
+++ b/Flow.Launcher/Languages/en.xaml
@@ -219,6 +219,7 @@
Fail to uninstall {0}
Unable to find plugin.json from the extracted zip file, or this path {0} does not exist
A plugin with the same ID and version already exists, or the version is greater than this downloaded plugin
+ Error creating setting panel for plugin {0}:{1}{2}
Plugin Store
diff --git a/Flow.Launcher/ViewModel/PluginViewModel.cs b/Flow.Launcher/ViewModel/PluginViewModel.cs
index 36c50990222..4de1ae6611e 100644
--- a/Flow.Launcher/ViewModel/PluginViewModel.cs
+++ b/Flow.Launcher/ViewModel/PluginViewModel.cs
@@ -1,4 +1,5 @@
-using System.Threading.Tasks;
+using System;
+using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
@@ -145,9 +146,10 @@ private static Control TryCreateSettingPanel(PluginPair pair)
// We can safely cast here as we already check this in HasSettingControl
return ((ISettingProvider)pair.Plugin).CreateSettingPanel();
}
- catch (System.Exception e)
+ catch (Exception e)
{
- var errorMsg = $"Error creating setting panel for plugin {pair.Metadata}\n{e.Message}";
+ var errorMsg = string.Format(App.API.GetTranslation("errorCreatingSettingPanel"),
+ pair.Metadata.Name, Environment.NewLine, e.Message);
var grid = new Grid()
{
Margin = SettingPanelMargin
From 18c8a04cbcc5fe062730abef62af7c0760682eae Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Mon, 15 Sep 2025 21:46:03 +0800
Subject: [PATCH 3/5] Log exception
---
Flow.Launcher/ViewModel/PluginViewModel.cs | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/Flow.Launcher/ViewModel/PluginViewModel.cs b/Flow.Launcher/ViewModel/PluginViewModel.cs
index 4de1ae6611e..59bb53a4a98 100644
--- a/Flow.Launcher/ViewModel/PluginViewModel.cs
+++ b/Flow.Launcher/ViewModel/PluginViewModel.cs
@@ -15,6 +15,8 @@ namespace Flow.Launcher.ViewModel
{
public partial class PluginViewModel : BaseModel
{
+ private static readonly string ClassName = nameof(PluginViewModel);
+
private static readonly Settings Settings = Ioc.Default.GetRequiredService();
private readonly PluginPair _pluginPair;
@@ -148,6 +150,10 @@ private static Control TryCreateSettingPanel(PluginPair pair)
}
catch (Exception e)
{
+ // Log exception
+ App.API.LogException(ClassName, $"Failed to create setting panel for {pair.Metadata.Name}", e);
+
+ // Show error message in UI
var errorMsg = string.Format(App.API.GetTranslation("errorCreatingSettingPanel"),
pair.Metadata.Name, Environment.NewLine, e.Message);
var grid = new Grid()
From 245c492906aad3cd138b501363e9cdee914c484d Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Thu, 18 Sep 2025 21:13:12 +0800
Subject: [PATCH 4/5] Improve code quality
---
Flow.Launcher/ViewModel/PluginViewModel.cs | 48 ++++++++++++----------
1 file changed, 27 insertions(+), 21 deletions(-)
diff --git a/Flow.Launcher/ViewModel/PluginViewModel.cs b/Flow.Launcher/ViewModel/PluginViewModel.cs
index 59bb53a4a98..c42791e8fd2 100644
--- a/Flow.Launcher/ViewModel/PluginViewModel.cs
+++ b/Flow.Launcher/ViewModel/PluginViewModel.cs
@@ -19,6 +19,9 @@ public partial class PluginViewModel : BaseModel
private static readonly Settings Settings = Ioc.Default.GetRequiredService();
+ private static readonly Thickness SettingPanelMargin = (Thickness)Application.Current.FindResource("SettingPanelMargin");
+ private static readonly Thickness SettingPanelItemTopBottomMargin = (Thickness)Application.Current.FindResource("SettingPanelItemTopBottomMargin");
+
private readonly PluginPair _pluginPair;
public PluginPair PluginPair
{
@@ -139,8 +142,6 @@ public Control SettingControl
: 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
@@ -156,25 +157,7 @@ private static Control TryCreateSettingPanel(PluginPair pair)
// Show error message in UI
var errorMsg = string.Format(App.API.GetTranslation("errorCreatingSettingPanel"),
pair.Metadata.Name, Environment.NewLine, 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
- };
+ return CreateErrorSettingPanel(errorMsg);
}
}
@@ -228,5 +211,28 @@ private void SetActionKeywords()
var changeKeywordsWindow = new ActionKeywords(this);
changeKeywordsWindow.ShowDialog();
}
+
+ private static UserControl CreateErrorSettingPanel(string text)
+ {
+ var grid = new Grid()
+ {
+ Margin = SettingPanelMargin
+ };
+ var textBox = new TextBox
+ {
+ Text = text,
+ 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
+ };
+ }
}
}
From 72dae631fe8c3fd8e9cd7c466c3481be8ae3da7a Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Thu, 18 Sep 2025 21:19:49 +0800
Subject: [PATCH 5/5] Use TextBox.ForegroundProperty
---
Flow.Launcher/ViewModel/PluginViewModel.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Flow.Launcher/ViewModel/PluginViewModel.cs b/Flow.Launcher/ViewModel/PluginViewModel.cs
index c42791e8fd2..29f2b9b4370 100644
--- a/Flow.Launcher/ViewModel/PluginViewModel.cs
+++ b/Flow.Launcher/ViewModel/PluginViewModel.cs
@@ -227,7 +227,7 @@ private static UserControl CreateErrorSettingPanel(string text)
TextWrapping = TextWrapping.Wrap,
Margin = SettingPanelItemTopBottomMargin
};
- textBox.SetResourceReference(TextBlock.ForegroundProperty, "Color04B");
+ textBox.SetResourceReference(TextBox.ForegroundProperty, "Color04B");
grid.Children.Add(textBox);
return new UserControl
{