55using System . Threading . Tasks ;
66using Flow . Launcher . Infrastructure ;
77using Flow . Launcher . Plugin ;
8+ using Meziantou . Framework . Win32 ;
89using Nerdbank . Streams ;
910
1011namespace Flow . Launcher . Core . Plugin
1112{
1213 internal abstract class ProcessStreamPluginV2 : JsonRPCPluginV2
1314 {
15+ private static JobObject _jobObject = new JobObject ( ) ;
16+
17+ static ProcessStreamPluginV2 ( )
18+ {
19+ _jobObject . SetLimits ( new JobObjectLimits ( )
20+ {
21+ Flags = JobObjectLimitFlags . KillOnJobClose | JobObjectLimitFlags . DieOnUnhandledException
22+ } ) ;
23+
24+ _jobObject . AssignProcess ( Process . GetCurrentProcess ( ) ) ;
25+ }
1426
1527 public override string SupportedLanguage { get ; set ; }
1628 protected sealed override IDuplexPipe ClientPipe { get ; set ; }
@@ -30,22 +42,22 @@ public override async Task InitAsync(PluginInitContext context)
3042
3143 ClientProcess = Process . Start ( StartInfo ) ;
3244 ArgumentNullException . ThrowIfNull ( ClientProcess ) ;
33-
45+
3446 SetupPipe ( ClientProcess ) ;
3547
3648 ErrorStream = ClientProcess . StandardError ;
3749
3850 await base . InitAsync ( context ) ;
3951 }
40-
52+
4153 private void SetupPipe ( Process process )
4254 {
4355 var ( reader , writer ) = ( PipeReader . Create ( process . StandardOutput . BaseStream ) ,
4456 PipeWriter . Create ( process . StandardInput . BaseStream ) ) ;
4557 ClientPipe = new DuplexPipe ( reader , writer ) ;
4658 }
47-
48-
59+
60+
4961 public override async Task ReloadDataAsync ( )
5062 {
5163 var oldProcess = ClientProcess ;
@@ -57,8 +69,8 @@ public override async Task ReloadDataAsync()
5769 await oldProcess . WaitForExitAsync ( ) ;
5870 oldProcess . Dispose ( ) ;
5971 }
60-
61-
72+
73+
6274 public override async ValueTask DisposeAsync ( )
6375 {
6476 ClientProcess . Kill ( true ) ;
0 commit comments