Skip to content

Commit 5fcd90b

Browse files
committed
Cleanup
1 parent d0f351a commit 5fcd90b

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

src/Middleware/Spa/SpaProxy/src/SpaProxyLaunchManager.cs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,10 @@ public SpaProxyLaunchManager(ILogger<SpaProxyLaunchManager> logger)
3838
_logger = logger;
3939
}
4040

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-
5441
public async Task StartAsync(CancellationToken cancellationToken)
5542
{
5643
_logger.LogInformation("Starting SPA development server");
57-
bool running = await ProbeSpaDevelopmentServerUrl(cancellationToken);
44+
var running = await ProbeSpaDevelopmentServerUrl(cancellationToken);
5845
if (running)
5946
{
6047
_logger.LogInformation($"Found SPA development server running at {_options.ServerUrl}");
@@ -70,10 +57,6 @@ private async Task<bool> ProbeSpaDevelopmentServerUrl(CancellationToken cancella
7057
{
7158
try
7259
{
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);
7760
var response = await _httpClient.GetAsync(_options.ServerUrl, cancellationToken);
7861
var running = response.IsSuccessStatusCode;
7962
return running;
@@ -91,14 +74,16 @@ private async Task StartSpaProcessAndProbeForLiveness(CancellationToken cancella
9174
var sw = Stopwatch.StartNew();
9275
var livenessProbeSucceeded = false;
9376
var maxTimeoutReached = false;
94-
9577
while (_spaProcess != null && !_spaProcess.HasExited && !livenessProbeSucceeded && !maxTimeoutReached)
9678
{
9779
livenessProbeSucceeded = await ProbeSpaDevelopmentServerUrl(cancellationToken);
98-
if (!livenessProbeSucceeded)
80+
if (livenessProbeSucceeded)
9981
{
100-
maxTimeoutReached = sw.Elapsed >= _options.MaxTimeout;
82+
break;
10183
}
84+
85+
maxTimeoutReached = sw.Elapsed >= _options.MaxTimeout;
86+
await Task.Delay(1000);
10287
}
10388

10489
if (_spaProcess == null || _spaProcess.HasExited)
@@ -132,6 +117,12 @@ private void LaunchDevelopmentProxy()
132117

133118
var info = new ProcessStartInfo(command, arguments)
134119
{
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.
135126
CreateNoWindow = false,
136127
UseShellExecute = true,
137128
WindowStyle = ProcessWindowStyle.Normal,
@@ -147,6 +138,7 @@ private void LaunchDevelopmentProxy()
147138

148139
public Task StopAsync(CancellationToken cancellationToken)
149140
{
141+
// We don't need to do anything here since Dispose will take care of cleaning up the process if necessary.
150142
return Task.CompletedTask;
151143
}
152144

@@ -204,5 +196,18 @@ void IDisposable.Dispose()
204196
Dispose(disposing: true);
205197
GC.SuppressFinalize(this);
206198
}
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+
}
207212
}
208213
}

0 commit comments

Comments
 (0)