5
5
using System . Threading . Tasks ;
6
6
using Flow . Launcher . Infrastructure ;
7
7
using Flow . Launcher . Plugin ;
8
+ using Meziantou . Framework . Win32 ;
8
9
using Nerdbank . Streams ;
9
10
10
11
namespace Flow . Launcher . Core . Plugin
11
12
{
12
13
internal abstract class ProcessStreamPluginV2 : JsonRPCPluginV2
13
14
{
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
+ }
14
26
15
27
public override string SupportedLanguage { get ; set ; }
16
28
protected sealed override IDuplexPipe ClientPipe { get ; set ; }
@@ -30,22 +42,22 @@ public override async Task InitAsync(PluginInitContext context)
30
42
31
43
ClientProcess = Process . Start ( StartInfo ) ;
32
44
ArgumentNullException . ThrowIfNull ( ClientProcess ) ;
33
-
45
+
34
46
SetupPipe ( ClientProcess ) ;
35
47
36
48
ErrorStream = ClientProcess . StandardError ;
37
49
38
50
await base . InitAsync ( context ) ;
39
51
}
40
-
52
+
41
53
private void SetupPipe ( Process process )
42
54
{
43
55
var ( reader , writer ) = ( PipeReader . Create ( process . StandardOutput . BaseStream ) ,
44
56
PipeWriter . Create ( process . StandardInput . BaseStream ) ) ;
45
57
ClientPipe = new DuplexPipe ( reader , writer ) ;
46
58
}
47
-
48
-
59
+
60
+
49
61
public override async Task ReloadDataAsync ( )
50
62
{
51
63
var oldProcess = ClientProcess ;
@@ -57,8 +69,8 @@ public override async Task ReloadDataAsync()
57
69
await oldProcess . WaitForExitAsync ( ) ;
58
70
oldProcess . Dispose ( ) ;
59
71
}
60
-
61
-
72
+
73
+
62
74
public override async ValueTask DisposeAsync ( )
63
75
{
64
76
ClientProcess . Kill ( true ) ;
0 commit comments