Merge pull request #1789 from Flow-Launcher/safer_kill

catch exception when killing unused jsonrpc process
This commit is contained in:
Jeremy Wu 2023-01-18 07:27:48 +11:00 committed by GitHub
commit 9ee1eee098
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -259,9 +259,16 @@ namespace Flow.Launcher.Core.Plugin
await using var registeredEvent = token.Register(() => await using var registeredEvent = token.Register(() =>
{ {
if (!process.HasExited) try
process.Kill(); {
sourceBuffer.Dispose(); if (!process.HasExited)
process.Kill();
sourceBuffer.Dispose();
}
catch (Exception e)
{
Log.Exception("|JsonRPCPlugin.ExecuteAsync|Exception when kill process", e);
}
}); });
try try
@ -376,7 +383,8 @@ namespace Flow.Launcher.Core.Plugin
sep.SetResourceReference(Separator.BackgroundProperty, "Color03B"); /* for theme change */ sep.SetResourceReference(Separator.BackgroundProperty, "Color03B"); /* for theme change */
var panel = new StackPanel var panel = new StackPanel
{ {
Orientation = Orientation.Vertical, VerticalAlignment = VerticalAlignment.Center, Orientation = Orientation.Vertical,
VerticalAlignment = VerticalAlignment.Center,
Margin = settingLabelPanelMargin Margin = settingLabelPanelMargin
}; };
RowDefinition gridRow = new RowDefinition(); RowDefinition gridRow = new RowDefinition();
@ -390,8 +398,10 @@ namespace Flow.Launcher.Core.Plugin
}; };
var desc = new TextBlock() var desc = new TextBlock()
{ {
Text = attribute.Description, FontSize = 12, Text = attribute.Description,
VerticalAlignment = VerticalAlignment.Center,Margin = settingDescMargin, FontSize = 12,
VerticalAlignment = VerticalAlignment.Center,
Margin = settingDescMargin,
TextWrapping = TextWrapping.WrapWithOverflow TextWrapping = TextWrapping.WrapWithOverflow
}; };
desc.SetResourceReference(TextBlock.ForegroundProperty, "Color04B"); desc.SetResourceReference(TextBlock.ForegroundProperty, "Color04B");
@ -420,20 +430,20 @@ namespace Flow.Launcher.Core.Plugin
{ {
Text = attribute.Description.Replace("\\r\\n", "\r\n"), Text = attribute.Description.Replace("\\r\\n", "\r\n"),
Margin = settingTextBlockMargin, Margin = settingTextBlockMargin,
Padding = new Thickness(0,0,0,0), Padding = new Thickness(0, 0, 0, 0),
HorizontalAlignment = System.Windows.HorizontalAlignment.Left, HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
TextAlignment = TextAlignment.Left, TextAlignment = TextAlignment.Left,
TextWrapping = TextWrapping.Wrap TextWrapping = TextWrapping.Wrap
}; };
Grid.SetColumn(contentControl, 0); Grid.SetColumn(contentControl, 0);
Grid.SetColumnSpan(contentControl, 2); Grid.SetColumnSpan(contentControl, 2);
Grid.SetRow(contentControl, rowCount); Grid.SetRow(contentControl, rowCount);
if (rowCount != 0) if (rowCount != 0)
mainPanel.Children.Add(sep); mainPanel.Children.Add(sep);
Grid.SetRow(sep, rowCount); Grid.SetRow(sep, rowCount);
Grid.SetColumn(sep, 0); Grid.SetColumn(sep, 0);
Grid.SetColumnSpan(sep, 2); Grid.SetColumnSpan(sep, 2);
break; break;
} }
case "input": case "input":
{ {
@ -449,50 +459,49 @@ namespace Flow.Launcher.Core.Plugin
Settings[attribute.Name] = textBox.Text; Settings[attribute.Name] = textBox.Text;
}; };
contentControl = textBox; contentControl = textBox;
Grid.SetColumn(contentControl, 1); Grid.SetColumn(contentControl, 1);
Grid.SetRow(contentControl, rowCount); Grid.SetRow(contentControl, rowCount);
if (rowCount != 0) if (rowCount != 0)
mainPanel.Children.Add(sep); mainPanel.Children.Add(sep);
Grid.SetRow(sep, rowCount); Grid.SetRow(sep, rowCount);
Grid.SetColumn(sep, 0); Grid.SetColumn(sep, 0);
Grid.SetColumnSpan(sep, 2); Grid.SetColumnSpan(sep, 2);
break; break;
} }
case "inputWithFileBtn": case "inputWithFileBtn":
{
var textBox = new TextBox()
{ {
var textBox = new TextBox() Margin = new Thickness(10, 0, 0, 0),
{ Text = Settings[attribute.Name] as string ?? string.Empty,
Margin = new Thickness(10, 0, 0, 0), HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
Text = Settings[attribute.Name] as string ?? string.Empty, ToolTip = attribute.Description
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, };
ToolTip = attribute.Description textBox.TextChanged += (_, _) =>
}; {
textBox.TextChanged += (_, _) => Settings[attribute.Name] = textBox.Text;
{ };
Settings[attribute.Name] = textBox.Text; var Btn = new System.Windows.Controls.Button()
}; {
var Btn = new System.Windows.Controls.Button() Margin = new Thickness(10, 0, 0, 0), Content = "Browse"
{ };
Margin = new Thickness(10,0,0,0), var dockPanel = new DockPanel()
Content = "Browse" {
}; Margin = settingControlMargin
var dockPanel = new DockPanel() };
{ DockPanel.SetDock(Btn, Dock.Right);
Margin = settingControlMargin dockPanel.Children.Add(Btn);
}; dockPanel.Children.Add(textBox);
DockPanel.SetDock(Btn, Dock.Right); contentControl = dockPanel;
dockPanel.Children.Add(Btn); Grid.SetColumn(contentControl, 1);
dockPanel.Children.Add(textBox); Grid.SetRow(contentControl, rowCount);
contentControl = dockPanel; if (rowCount != 0)
Grid.SetColumn(contentControl, 1); mainPanel.Children.Add(sep);
Grid.SetRow(contentControl, rowCount); Grid.SetRow(sep, rowCount);
if (rowCount != 0) Grid.SetColumn(sep, 0);
mainPanel.Children.Add(sep); Grid.SetColumnSpan(sep, 2);
Grid.SetRow(sep, rowCount); break;
Grid.SetColumn(sep, 0); }
Grid.SetColumnSpan(sep, 2);
break;
}
case "textarea": case "textarea":
{ {
var textBox = new TextBox() var textBox = new TextBox()
@ -511,14 +520,14 @@ namespace Flow.Launcher.Core.Plugin
Settings[attribute.Name] = ((TextBox)sender).Text; Settings[attribute.Name] = ((TextBox)sender).Text;
}; };
contentControl = textBox; contentControl = textBox;
Grid.SetColumn(contentControl, 1); Grid.SetColumn(contentControl, 1);
Grid.SetRow(contentControl, rowCount); Grid.SetRow(contentControl, rowCount);
if (rowCount != 0) if (rowCount != 0)
mainPanel.Children.Add(sep); mainPanel.Children.Add(sep);
Grid.SetRow(sep, rowCount); Grid.SetRow(sep, rowCount);
Grid.SetColumn(sep, 0); Grid.SetColumn(sep, 0);
Grid.SetColumnSpan(sep, 2); Grid.SetColumnSpan(sep, 2);
break; break;
} }
case "passwordBox": case "passwordBox":
{ {
@ -535,14 +544,14 @@ namespace Flow.Launcher.Core.Plugin
Settings[attribute.Name] = ((PasswordBox)sender).Password; Settings[attribute.Name] = ((PasswordBox)sender).Password;
}; };
contentControl = passwordBox; contentControl = passwordBox;
Grid.SetColumn(contentControl, 1); Grid.SetColumn(contentControl, 1);
Grid.SetRow(contentControl, rowCount); Grid.SetRow(contentControl, rowCount);
if (rowCount != 0) if (rowCount != 0)
mainPanel.Children.Add(sep); mainPanel.Children.Add(sep);
Grid.SetRow(sep, rowCount); Grid.SetRow(sep, rowCount);
Grid.SetColumn(sep, 0); Grid.SetColumn(sep, 0);
Grid.SetColumnSpan(sep, 2); Grid.SetColumnSpan(sep, 2);
break; break;
} }
case "dropdown": case "dropdown":
{ {
@ -559,14 +568,14 @@ namespace Flow.Launcher.Core.Plugin
Settings[attribute.Name] = (string)((System.Windows.Controls.ComboBox)sender).SelectedItem; Settings[attribute.Name] = (string)((System.Windows.Controls.ComboBox)sender).SelectedItem;
}; };
contentControl = comboBox; contentControl = comboBox;
Grid.SetColumn(contentControl, 1); Grid.SetColumn(contentControl, 1);
Grid.SetRow(contentControl, rowCount); Grid.SetRow(contentControl, rowCount);
if (rowCount != 0) if (rowCount != 0)
mainPanel.Children.Add(sep); mainPanel.Children.Add(sep);
Grid.SetRow(sep, rowCount); Grid.SetRow(sep, rowCount);
Grid.SetColumn(sep, 0); Grid.SetColumn(sep, 0);
Grid.SetColumnSpan(sep, 2); Grid.SetColumnSpan(sep, 2);
break; break;
} }
case "checkbox": case "checkbox":
var checkBox = new CheckBox var checkBox = new CheckBox
@ -592,13 +601,11 @@ namespace Flow.Launcher.Core.Plugin
case "hyperlink": case "hyperlink":
var hyperlink = new Hyperlink var hyperlink = new Hyperlink
{ {
ToolTip = attribute.Description, ToolTip = attribute.Description, NavigateUri = attribute.url
NavigateUri = attribute.url
}; };
var linkbtn = new System.Windows.Controls.Button var linkbtn = new System.Windows.Controls.Button
{ {
HorizontalAlignment = System.Windows.HorizontalAlignment.Right, HorizontalAlignment = System.Windows.HorizontalAlignment.Right, Margin = settingControlMargin
Margin = settingControlMargin
}; };
linkbtn.Content = attribute.urlLabel; linkbtn.Content = attribute.urlLabel;