@@ -38,23 +38,10 @@ public SpaProxyLaunchManager(ILogger<SpaProxyLaunchManager> logger)
38
38
_logger = logger ;
39
39
}
40
40
41
- private class SpaDevelopmentServerOptions
42
- {
43
- public string ServerUrl { get ; set ; } = "" ;
44
-
45
- public string LaunchCommand { get ; set ; } = "" ;
46
-
47
- public int MaxTimeoutInSeconds { get ; set ; }
48
-
49
- public TimeSpan MaxTimeout => TimeSpan . FromSeconds ( MaxTimeoutInSeconds ) ;
50
-
51
- public string WorkingDirectory { get ; set ; } = "" ;
52
- }
53
-
54
41
public async Task StartAsync ( CancellationToken cancellationToken )
55
42
{
56
43
_logger . LogInformation ( "Starting SPA development server" ) ;
57
- bool running = await ProbeSpaDevelopmentServerUrl ( cancellationToken ) ;
44
+ var running = await ProbeSpaDevelopmentServerUrl ( cancellationToken ) ;
58
45
if ( running )
59
46
{
60
47
_logger . LogInformation ( $ "Found SPA development server running at { _options . ServerUrl } ") ;
@@ -70,10 +57,6 @@ private async Task<bool> ProbeSpaDevelopmentServerUrl(CancellationToken cancella
70
57
{
71
58
try
72
59
{
73
- // Wait 1 second before probing. While this unconditionally adds 1 second to the startup time,
74
- // it makes sure that we don't send lots of requests and that we give the process some time to
75
- // get up and running
76
- await Task . Delay ( 1000 ) ;
77
60
var response = await _httpClient . GetAsync ( _options . ServerUrl , cancellationToken ) ;
78
61
var running = response . IsSuccessStatusCode ;
79
62
return running ;
@@ -91,14 +74,16 @@ private async Task StartSpaProcessAndProbeForLiveness(CancellationToken cancella
91
74
var sw = Stopwatch . StartNew ( ) ;
92
75
var livenessProbeSucceeded = false ;
93
76
var maxTimeoutReached = false ;
94
-
95
77
while ( _spaProcess != null && ! _spaProcess . HasExited && ! livenessProbeSucceeded && ! maxTimeoutReached )
96
78
{
97
79
livenessProbeSucceeded = await ProbeSpaDevelopmentServerUrl ( cancellationToken ) ;
98
- if ( ! livenessProbeSucceeded )
80
+ if ( livenessProbeSucceeded )
99
81
{
100
- maxTimeoutReached = sw . Elapsed >= _options . MaxTimeout ;
82
+ break ;
101
83
}
84
+
85
+ maxTimeoutReached = sw . Elapsed >= _options . MaxTimeout ;
86
+ await Task . Delay ( 1000 ) ;
102
87
}
103
88
104
89
if ( _spaProcess == null || _spaProcess . HasExited )
@@ -132,6 +117,12 @@ private void LaunchDevelopmentProxy()
132
117
133
118
var info = new ProcessStartInfo ( command , arguments )
134
119
{
120
+ // Linux and Mac OS don't have the concept of launching a terminal process in a new window.
121
+ // On those cases the process will be launched in the same terminal window and will just print
122
+ // some output during the start phase of the app.
123
+ // This is not a problem since users don't need to interact with the proxy other than to stop it
124
+ // and this is only an optimization to keep the current experience. We can always tell them to
125
+ // run the proxy manually.
135
126
CreateNoWindow = false ,
136
127
UseShellExecute = true ,
137
128
WindowStyle = ProcessWindowStyle . Normal ,
@@ -147,6 +138,7 @@ private void LaunchDevelopmentProxy()
147
138
148
139
public Task StopAsync ( CancellationToken cancellationToken )
149
140
{
141
+ // We don't need to do anything here since Dispose will take care of cleaning up the process if necessary.
150
142
return Task . CompletedTask ;
151
143
}
152
144
@@ -204,5 +196,18 @@ void IDisposable.Dispose()
204
196
Dispose ( disposing : true ) ;
205
197
GC . SuppressFinalize ( this ) ;
206
198
}
199
+
200
+ private class SpaDevelopmentServerOptions
201
+ {
202
+ public string ServerUrl { get ; set ; } = "" ;
203
+
204
+ public string LaunchCommand { get ; set ; } = "" ;
205
+
206
+ public int MaxTimeoutInSeconds { get ; set ; }
207
+
208
+ public TimeSpan MaxTimeout => TimeSpan . FromSeconds ( MaxTimeoutInSeconds ) ;
209
+
210
+ public string WorkingDirectory { get ; set ; } = "" ;
211
+ }
207
212
}
208
213
}
0 commit comments