Files
Electron.NET/src/ElectronNET.API/ElectronNetRuntime.cs
Florian Rappl 11f71feeb8 Automatic Port Selection and Secured Communication (#1038)
Adds dynamic OS-selected socket port handling and secured Electron/.NET communication.

The dotnet-first startup flow now generates the auth token on the .NET side and passes it to Electron through an environment variable. Electron reports the selected socket port through a temporary startup-info file, avoiding any dependency on parsing Electron console output.

Also avoids logging backend startup parameters because they include the auth token.
2026-05-09 17:03:32 +02:00

60 lines
2.0 KiB
C#

namespace ElectronNET
{
using ElectronNET.API;
using ElectronNET.Runtime;
using ElectronNET.Runtime.Controllers;
using ElectronNET.Runtime.Data;
using System;
using System.Collections.Immutable;
using System.Threading.Tasks;
public static class ElectronNetRuntime
{
internal static StartupManager StartupManager;
internal const int DefaultSocketPort = 8000;
internal const int DefaultWebPort = 8001;
internal const string ElectronPortArgumentName = "electronPort";
internal const string ElectronPidArgumentName = "electronPID";
internal const string ElectronAuthTokenArgumentName = "electronAuthToken";
/// <summary>Initializes the <see cref="ElectronNetRuntime"/> class.</summary>
static ElectronNetRuntime()
{
StartupManager = new StartupManager();
StartupManager.Initialize();
}
public static string ElectronExtraArguments { get; set; }
public static string ElectronAuthToken { get; internal set; }
public static int? ElectronSocketPort { get; internal set; }
public static int? AspNetWebPort { get; internal set; }
public static StartupMethod StartupMethod { get; internal set; }
public static DotnetAppType DotnetAppType { get; internal set; }
public static string ElectronExecutable { get; internal set; }
public static ImmutableList<string> ProcessArguments { get; internal set; }
public static BuildInfo BuildInfo { get; internal set; }
public static IElectronNetRuntimeController RuntimeController => RuntimeControllerCore;
// The below properties are non-public
internal static RuntimeControllerBase RuntimeControllerCore { get; set; }
internal static int? ElectronProcessId { get; set; }
internal static Func<Task> OnAppReadyCallback { get; set; }
internal static ISocketConnection GetSocket()
{
return RuntimeControllerCore?.Socket;
}
}
}