Skip to content
Merged
3 changes: 3 additions & 0 deletions DevProxy/Commands/DevProxyConfigOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public string? ConfigFile
}

public int? ApiPort => _parseResult?.GetValueOrDefault<int?>(DevProxyCommand.ApiPortOptionName);
public bool? AsSystemProxy => _parseResult?.GetValueOrDefault<bool?>(DevProxyCommand.AsSystemProxyOptionName);
public int? Port => _parseResult?.GetValueOrDefault<int?>(DevProxyCommand.PortOptionName);
public bool Discover => _parseResult?.GetValueOrDefault<bool?>(DevProxyCommand.DiscoverOptionName) ?? false;
public string? IPAddress => _parseResult?.GetValueOrDefault<string?>(DevProxyCommand.IpAddressOptionName);
Expand Down Expand Up @@ -138,6 +139,7 @@ public DevProxyConfigOptions()
};

var apiPortOption = new Option<int?>(DevProxyCommand.ApiPortOptionName);
var asSystemProxyOption = new Option<bool?>(DevProxyCommand.AsSystemProxyOptionName);
var portOption = new Option<int?>(DevProxyCommand.PortOptionName, "-p");

var discoverOption = new Option<bool>(DevProxyCommand.DiscoverOptionName, "--discover")
Expand All @@ -153,6 +155,7 @@ public DevProxyConfigOptions()
var options = new List<Option>
{
apiPortOption,
asSystemProxyOption,
ipAddressOption,
configFileOption,
portOption,
Expand Down
13 changes: 8 additions & 5 deletions DevProxy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@

static async Task<int> StartDetachedProcessAsync(string[] args)
{
// Check if an instance is already running
if (await StateManager.IsInstanceRunningAsync())
// Check if an instance is already running as system proxy
var existingState = await StateManager.LoadStateAsync();
if (existingState is not null && existingState.AsSystemProxy)
{
var existingState = await StateManager.LoadStateAsync();
await Console.Error.WriteLineAsync($"Dev Proxy is already running (PID: {existingState?.Pid}).");
await Console.Error.WriteLineAsync($"Dev Proxy is already running (PID: {existingState.Pid}).");
await Console.Error.WriteLineAsync("Use 'devproxy stop' to stop it first.");
return 1;
Comment thread
waldekmastykarz marked this conversation as resolved.
}
Expand Down Expand Up @@ -206,14 +206,17 @@ static async Task<int> RunProxyAsync(string[] args, DevProxyConfigOptions option
var apiPort = options.ApiPort ?? app.Configuration.GetValue("apiPort", 8897);
var port = options.Port ?? app.Configuration.GetValue("port", 8000);

var asSystemProxy = options.AsSystemProxy ?? app.Configuration.GetValue("asSystemProxy", true);

var state = new ProxyInstanceState
{
Pid = Environment.ProcessId,
Comment thread
waldekmastykarz marked this conversation as resolved.
Outdated
ApiUrl = $"http://{(ipAddress is "0.0.0.0" or "::" ? "127.0.0.1" : ipAddress)}:{apiPort}",
LogFile = DevProxyCommand.DetachedLogFilePath,
StartedAt = DateTimeOffset.UtcNow,
ConfigFile = options.ConfigFile,
Port = port
Port = port,
AsSystemProxy = asSystemProxy
};

await StateManager.SaveStateAsync(state);
Comment thread
waldekmastykarz marked this conversation as resolved.
Outdated
Expand Down
3 changes: 3 additions & 0 deletions DevProxy/State/ProxyInstanceState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ internal sealed class ProxyInstanceState

[JsonPropertyName("port")]
public int Port { get; set; }

[JsonPropertyName("asSystemProxy")]
public bool AsSystemProxy { get; set; } = true;
}
Loading