mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-11-16 09:21:01 +00:00
Fixed #1103
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
internal const int DefaultSocketPort = 8000;
|
||||
internal const int DefaultWebPort = 8001;
|
||||
internal const string ElectronPortArgumentName = "electronPort";
|
||||
internal const string ElectronHostArgumentName = "electronHost";
|
||||
internal const string ElectronPidArgumentName = "electronPID";
|
||||
internal const string ElectronAuthTokenArgumentName = "electronAuthToken";
|
||||
|
||||
@@ -31,6 +32,11 @@
|
||||
|
||||
public static int? ElectronSocketPort { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// The loopback address the Electron socket bridge is listening on.
|
||||
/// </summary>
|
||||
public static string ElectronSocketHost { get; internal set; }
|
||||
|
||||
public static int? AspNetWebPort { get; internal set; }
|
||||
|
||||
public static StartupMethod StartupMethod { get; internal set; }
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
[Localizable(false)]
|
||||
internal class ElectronProcessActive : ElectronProcessBase
|
||||
{
|
||||
private readonly Regex extractor = new Regex("^Electron Socket: listening on port (\\d+) at .* using ([a-f0-9]+)$");
|
||||
private readonly Regex extractor = new Regex("^Electron Socket: listening on port (\\d+) at (\\S+) using ([a-f0-9]+)$");
|
||||
|
||||
private readonly bool isUnpackaged;
|
||||
private readonly string electronBinaryName;
|
||||
@@ -179,11 +179,13 @@
|
||||
if (match?.Success ?? false)
|
||||
{
|
||||
var port = int.Parse(match.Groups[1].Value);
|
||||
var token = match.Groups[2].Value;
|
||||
var host = match.Groups[2].Value;
|
||||
var token = match.Groups[3].Value;
|
||||
|
||||
this.process.LineReceived -= Read_SocketIO_Parameters;
|
||||
ElectronNetRuntime.ElectronAuthToken = token;
|
||||
ElectronNetRuntime.ElectronSocketPort = port;
|
||||
ElectronNetRuntime.ElectronSocketHost = host;
|
||||
tcs.SetResult();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,19 @@
|
||||
{
|
||||
this.socketPort = socketPort;
|
||||
this.authorization = authorization;
|
||||
this.socketUrl = $"http://localhost:{this.socketPort}";
|
||||
this.socketUrl = $"http://{FormatHost(ElectronNetRuntime.ElectronSocketHost)}:{this.socketPort}";
|
||||
}
|
||||
|
||||
// The Electron host reports the loopback address it is actually listening on; only
|
||||
// when it is unknown we have to fall back to the ambiguous hostname.
|
||||
private static string FormatHost(string socketHost)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(socketHost))
|
||||
{
|
||||
return "localhost";
|
||||
}
|
||||
|
||||
return socketHost.Contains(':') ? $"[{socketHost}]" : socketHost;
|
||||
}
|
||||
|
||||
public int SocketPort => this.socketPort;
|
||||
|
||||
@@ -94,8 +94,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
var pidArg = argsList.FirstOrDefault(e => e.Contains(ElectronNetRuntime.ElectronPidArgumentName, StringComparison.OrdinalIgnoreCase));
|
||||
var hostArg = argsList.FirstOrDefault(e => e.Contains(ElectronNetRuntime.ElectronHostArgumentName, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (hostArg != null)
|
||||
{
|
||||
var parts = hostArg.Split('=', StringSplitOptions.TrimEntries);
|
||||
|
||||
if (parts.Length > 1 && !string.IsNullOrWhiteSpace(parts[1]))
|
||||
{
|
||||
ElectronNetRuntime.ElectronSocketHost = parts[1];
|
||||
|
||||
Console.WriteLine("Use Electron Host: " + parts[1]);
|
||||
}
|
||||
}
|
||||
var pidArg = argsList.FirstOrDefault(e => e.Contains(ElectronNetRuntime.ElectronPidArgumentName, StringComparison.OrdinalIgnoreCase));
|
||||
if (pidArg != null)
|
||||
{
|
||||
var parts = pidArg.Split('=', StringSplitOptions.TrimEntries);
|
||||
|
||||
Reference in New Issue
Block a user