Skip to content

Commit a7afa17

Browse files
committed
catch exception when killing unused jsonrpc process
1 parent 77977ee commit a7afa17

File tree

1 file changed

+95
-88
lines changed

1 file changed

+95
-88
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 95 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,16 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
259259

260260
await using var registeredEvent = token.Register(() =>
261261
{
262-
if (!process.HasExited)
263-
process.Kill();
264-
sourceBuffer.Dispose();
262+
try
263+
{
264+
if (!process.HasExited)
265+
process.Kill();
266+
sourceBuffer.Dispose();
267+
}
268+
catch (Exception e)
269+
{
270+
Log.Exception("|JsonRPCPlugin.ExecuteAsync|Exception when kill process", e);
271+
}
265272
});
266273

267274
try
@@ -288,7 +295,7 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
288295
}
289296

290297
sourceBuffer.Seek(0, SeekOrigin.Begin);
291-
298+
292299
return sourceBuffer;
293300
}
294301

@@ -376,7 +383,8 @@ public Control CreateSettingPanel()
376383
sep.SetResourceReference(Separator.BackgroundProperty, "Color03B"); /* for theme change */
377384
var panel = new StackPanel
378385
{
379-
Orientation = Orientation.Vertical, VerticalAlignment = VerticalAlignment.Center,
386+
Orientation = Orientation.Vertical,
387+
VerticalAlignment = VerticalAlignment.Center,
380388
Margin = settingLabelPanelMargin
381389
};
382390
RowDefinition gridRow = new RowDefinition();
@@ -390,8 +398,10 @@ public Control CreateSettingPanel()
390398
};
391399
var desc = new TextBlock()
392400
{
393-
Text = attribute.Description, FontSize = 12,
394-
VerticalAlignment = VerticalAlignment.Center,Margin = settingDescMargin,
401+
Text = attribute.Description,
402+
FontSize = 12,
403+
VerticalAlignment = VerticalAlignment.Center,
404+
Margin = settingDescMargin,
395405
TextWrapping = TextWrapping.WrapWithOverflow
396406
};
397407
desc.SetResourceReference(TextBlock.ForegroundProperty, "Color04B");
@@ -405,7 +415,7 @@ public Control CreateSettingPanel()
405415
panel.Children.Add(name);
406416
panel.Children.Add(desc);
407417
}
408-
418+
409419

410420
Grid.SetColumn(panel, 0);
411421
Grid.SetRow(panel, rowCount);
@@ -420,20 +430,20 @@ public Control CreateSettingPanel()
420430
{
421431
Text = attribute.Description.Replace("\\r\\n", "\r\n"),
422432
Margin = settingTextBlockMargin,
423-
Padding = new Thickness(0,0,0,0),
433+
Padding = new Thickness(0, 0, 0, 0),
424434
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
425435
TextAlignment = TextAlignment.Left,
426436
TextWrapping = TextWrapping.Wrap
427437
};
428-
Grid.SetColumn(contentControl, 0);
429-
Grid.SetColumnSpan(contentControl, 2);
430-
Grid.SetRow(contentControl, rowCount);
431-
if (rowCount != 0)
432-
mainPanel.Children.Add(sep);
433-
Grid.SetRow(sep, rowCount);
434-
Grid.SetColumn(sep, 0);
435-
Grid.SetColumnSpan(sep, 2);
436-
break;
438+
Grid.SetColumn(contentControl, 0);
439+
Grid.SetColumnSpan(contentControl, 2);
440+
Grid.SetRow(contentControl, rowCount);
441+
if (rowCount != 0)
442+
mainPanel.Children.Add(sep);
443+
Grid.SetRow(sep, rowCount);
444+
Grid.SetColumn(sep, 0);
445+
Grid.SetColumnSpan(sep, 2);
446+
break;
437447
}
438448
case "input":
439449
{
@@ -449,50 +459,49 @@ public Control CreateSettingPanel()
449459
Settings[attribute.Name] = textBox.Text;
450460
};
451461
contentControl = textBox;
452-
Grid.SetColumn(contentControl, 1);
453-
Grid.SetRow(contentControl, rowCount);
454-
if (rowCount != 0)
455-
mainPanel.Children.Add(sep);
456-
Grid.SetRow(sep, rowCount);
457-
Grid.SetColumn(sep, 0);
458-
Grid.SetColumnSpan(sep, 2);
459-
break;
462+
Grid.SetColumn(contentControl, 1);
463+
Grid.SetRow(contentControl, rowCount);
464+
if (rowCount != 0)
465+
mainPanel.Children.Add(sep);
466+
Grid.SetRow(sep, rowCount);
467+
Grid.SetColumn(sep, 0);
468+
Grid.SetColumnSpan(sep, 2);
469+
break;
460470
}
461471
case "inputWithFileBtn":
472+
{
473+
var textBox = new TextBox()
462474
{
463-
var textBox = new TextBox()
464-
{
465-
Margin = new Thickness(10, 0, 0, 0),
466-
Text = Settings[attribute.Name] as string ?? string.Empty,
467-
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
468-
ToolTip = attribute.Description
469-
};
470-
textBox.TextChanged += (_, _) =>
471-
{
472-
Settings[attribute.Name] = textBox.Text;
473-
};
474-
var Btn = new System.Windows.Controls.Button()
475-
{
476-
Margin = new Thickness(10,0,0,0),
477-
Content = "Browse"
478-
};
479-
var dockPanel = new DockPanel()
480-
{
481-
Margin = settingControlMargin
482-
};
483-
DockPanel.SetDock(Btn, Dock.Right);
484-
dockPanel.Children.Add(Btn);
485-
dockPanel.Children.Add(textBox);
486-
contentControl = dockPanel;
487-
Grid.SetColumn(contentControl, 1);
488-
Grid.SetRow(contentControl, rowCount);
489-
if (rowCount != 0)
490-
mainPanel.Children.Add(sep);
491-
Grid.SetRow(sep, rowCount);
492-
Grid.SetColumn(sep, 0);
493-
Grid.SetColumnSpan(sep, 2);
494-
break;
495-
}
475+
Margin = new Thickness(10, 0, 0, 0),
476+
Text = Settings[attribute.Name] as string ?? string.Empty,
477+
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
478+
ToolTip = attribute.Description
479+
};
480+
textBox.TextChanged += (_, _) =>
481+
{
482+
Settings[attribute.Name] = textBox.Text;
483+
};
484+
var Btn = new System.Windows.Controls.Button()
485+
{
486+
Margin = new Thickness(10, 0, 0, 0), Content = "Browse"
487+
};
488+
var dockPanel = new DockPanel()
489+
{
490+
Margin = settingControlMargin
491+
};
492+
DockPanel.SetDock(Btn, Dock.Right);
493+
dockPanel.Children.Add(Btn);
494+
dockPanel.Children.Add(textBox);
495+
contentControl = dockPanel;
496+
Grid.SetColumn(contentControl, 1);
497+
Grid.SetRow(contentControl, rowCount);
498+
if (rowCount != 0)
499+
mainPanel.Children.Add(sep);
500+
Grid.SetRow(sep, rowCount);
501+
Grid.SetColumn(sep, 0);
502+
Grid.SetColumnSpan(sep, 2);
503+
break;
504+
}
496505
case "textarea":
497506
{
498507
var textBox = new TextBox()
@@ -511,14 +520,14 @@ public Control CreateSettingPanel()
511520
Settings[attribute.Name] = ((TextBox)sender).Text;
512521
};
513522
contentControl = textBox;
514-
Grid.SetColumn(contentControl, 1);
515-
Grid.SetRow(contentControl, rowCount);
516-
if (rowCount != 0)
517-
mainPanel.Children.Add(sep);
518-
Grid.SetRow(sep, rowCount);
519-
Grid.SetColumn(sep, 0);
520-
Grid.SetColumnSpan(sep, 2);
521-
break;
523+
Grid.SetColumn(contentControl, 1);
524+
Grid.SetRow(contentControl, rowCount);
525+
if (rowCount != 0)
526+
mainPanel.Children.Add(sep);
527+
Grid.SetRow(sep, rowCount);
528+
Grid.SetColumn(sep, 0);
529+
Grid.SetColumnSpan(sep, 2);
530+
break;
522531
}
523532
case "passwordBox":
524533
{
@@ -535,14 +544,14 @@ public Control CreateSettingPanel()
535544
Settings[attribute.Name] = ((PasswordBox)sender).Password;
536545
};
537546
contentControl = passwordBox;
538-
Grid.SetColumn(contentControl, 1);
539-
Grid.SetRow(contentControl, rowCount);
540-
if (rowCount != 0)
541-
mainPanel.Children.Add(sep);
542-
Grid.SetRow(sep, rowCount);
543-
Grid.SetColumn(sep, 0);
544-
Grid.SetColumnSpan(sep, 2);
545-
break;
547+
Grid.SetColumn(contentControl, 1);
548+
Grid.SetRow(contentControl, rowCount);
549+
if (rowCount != 0)
550+
mainPanel.Children.Add(sep);
551+
Grid.SetRow(sep, rowCount);
552+
Grid.SetColumn(sep, 0);
553+
Grid.SetColumnSpan(sep, 2);
554+
break;
546555
}
547556
case "dropdown":
548557
{
@@ -559,14 +568,14 @@ public Control CreateSettingPanel()
559568
Settings[attribute.Name] = (string)((System.Windows.Controls.ComboBox)sender).SelectedItem;
560569
};
561570
contentControl = comboBox;
562-
Grid.SetColumn(contentControl, 1);
563-
Grid.SetRow(contentControl, rowCount);
564-
if (rowCount != 0)
565-
mainPanel.Children.Add(sep);
566-
Grid.SetRow(sep, rowCount);
567-
Grid.SetColumn(sep, 0);
568-
Grid.SetColumnSpan(sep, 2);
569-
break;
571+
Grid.SetColumn(contentControl, 1);
572+
Grid.SetRow(contentControl, rowCount);
573+
if (rowCount != 0)
574+
mainPanel.Children.Add(sep);
575+
Grid.SetRow(sep, rowCount);
576+
Grid.SetColumn(sep, 0);
577+
Grid.SetColumnSpan(sep, 2);
578+
break;
570579
}
571580
case "checkbox":
572581
var checkBox = new CheckBox
@@ -592,13 +601,11 @@ public Control CreateSettingPanel()
592601
case "hyperlink":
593602
var hyperlink = new Hyperlink
594603
{
595-
ToolTip = attribute.Description,
596-
NavigateUri = attribute.url
604+
ToolTip = attribute.Description, NavigateUri = attribute.url
597605
};
598606
var linkbtn = new System.Windows.Controls.Button
599607
{
600-
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
601-
Margin = settingControlMargin
608+
HorizontalAlignment = System.Windows.HorizontalAlignment.Right, Margin = settingControlMargin
602609
};
603610
linkbtn.Content = attribute.urlLabel;
604611

@@ -619,7 +626,7 @@ public Control CreateSettingPanel()
619626
mainPanel.Children.Add(panel);
620627
mainPanel.Children.Add(contentControl);
621628
rowCount++;
622-
629+
623630
}
624631
return settingWindow;
625632
}

0 commit comments

Comments
 (0)