Skip to content

Commit 4450d62

Browse files
committed
Merge branch 'feature/secure-connection' of https://github.com/ElectronNET/Electron.NET into feature/secure-connection
2 parents 834c22a + 248c64d commit 4450d62

27 files changed

+87
-1720
lines changed
File renamed without changes.

docs/SignalR-Implementation-Summary.md

Lines changed: 0 additions & 450 deletions
This file was deleted.

docs/SignalR-Startup-Mode.md

Lines changed: 0 additions & 236 deletions
This file was deleted.

src/ElectronNET.API/Bridge/ISocketConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace ElectronNET.API.Bridge
44
using System.Threading.Tasks;
55

66
/// <summary>
7-
/// Common interface for communication facades (SocketIO and SignalR).
7+
/// Common interface for communication facades.
88
/// Provides methods for bidirectional communication between .NET and Electron.
99
/// </summary>
1010
internal interface ISocketConnection : IDisposable

src/ElectronNET.API/Bridge/SocketIOConnection.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@
33
namespace ElectronNET.API;
44

55
using System;
6+
using System.Collections.Generic;
67
using System.Threading.Tasks;
78
using ElectronNET.API.Bridge;
89
using ElectronNET.API.Serialization;
910
using SocketIO.Serializer.SystemTextJson;
1011
using SocketIO = SocketIOClient.SocketIO;
12+
using SocketIOOptions = SocketIOClient.SocketIOOptions;
1113

1214
internal class SocketIOConnection : ISocketConnection
1315
{
1416
private readonly SocketIO _socket;
1517
private readonly object _lockObj = new object();
1618
private bool _isDisposed;
1719

18-
public SocketIOConnection(string uri)
20+
public SocketIOConnection(string uri, string authorization)
1921
{
20-
_socket = new SocketIO(uri);
22+
_socket = new SocketIO(uri, new SocketIOOptions
23+
{
24+
ExtraHeaders = new Dictionary<string, string>
25+
{
26+
["authorization"] = authorization
27+
},
28+
});
2129
_socket.Serializer = new SystemTextJsonSerializer(ElectronJson.Options);
2230
// Use default System.Text.Json serializer from SocketIOClient.
2331
// Outgoing args are normalized to camelCase via SerializeArg in Emit.

src/ElectronNET.API/Common/Extensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public static bool IsUnpackaged(this StartupMethod method)
1414
{
1515
case StartupMethod.UnpackedElectronFirst:
1616
case StartupMethod.UnpackedDotnetFirst:
17-
case StartupMethod.UnpackedDotnetFirstSignalR:
1817
return true;
1918
default:
2019
return false;

src/ElectronNET.API/Common/ProcessRunner.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class ProcessRunner : IDisposable
2626
private readonly StringBuilder stdOut = new StringBuilder(4 * 1024);
2727
private readonly StringBuilder stdErr = new StringBuilder(4 * 1024);
2828

29+
public event EventHandler<string> LineReceived;
30+
2931
private volatile ManualResetEvent stdOutEvent;
3032
private volatile ManualResetEvent stdErrEvent;
3133
private volatile Stopwatch stopwatch;
@@ -571,6 +573,7 @@ private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
571573
if (e.Data != null)
572574
{
573575
Console.WriteLine("|| " + e.Data);
576+
LineReceived?.Invoke(this, e.Data);
574577
}
575578
else
576579
{

src/ElectronNET.API/Runtime/Controllers/RuntimeControllerDotNetFirst.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ internal class RuntimeControllerDotNetFirst : RuntimeControllerBase
1414
{
1515
private ElectronProcessBase electronProcess;
1616
private SocketBridgeService socketBridge;
17-
private int? port;
1817

1918
public RuntimeControllerDotNetFirst()
2019
{
@@ -42,19 +41,13 @@ protected override Task StartCore()
4241
var isUnPacked = ElectronNetRuntime.StartupMethod.IsUnpackaged();
4342
var electronBinaryName = ElectronNetRuntime.ElectronExecutable;
4443
var args = string.Format("{0} {1}", ElectronNetRuntime.ElectronExtraArguments, Environment.CommandLine).Trim();
45-
this.port = ElectronNetRuntime.ElectronSocketPort;
46-
47-
if (!this.port.HasValue)
48-
{
49-
this.port = PortHelper.GetFreePort(ElectronNetRuntime.DefaultSocketPort);
50-
ElectronNetRuntime.ElectronSocketPort = this.port;
51-
}
44+
var port = ElectronNetRuntime.ElectronSocketPort ?? 0;
5245

5346
Console.Error.WriteLine("[StartCore]: isUnPacked: {0}", isUnPacked);
5447
Console.Error.WriteLine("[StartCore]: electronBinaryName: {0}", electronBinaryName);
5548
Console.Error.WriteLine("[StartCore]: args: {0}", args);
5649

57-
this.electronProcess = new ElectronProcessActive(isUnPacked, electronBinaryName, args, this.port.Value);
50+
this.electronProcess = new ElectronProcessActive(isUnPacked, electronBinaryName, args, port);
5851
this.electronProcess.Ready += this.ElectronProcess_Ready;
5952
this.electronProcess.Stopped += this.ElectronProcess_Stopped;
6053

@@ -64,8 +57,9 @@ protected override Task StartCore()
6457

6558
private void ElectronProcess_Ready(object sender, EventArgs e)
6659
{
60+
var port = ElectronNetRuntime.ElectronSocketPort.Value;
6761
this.TransitionState(LifetimeState.Started);
68-
this.socketBridge = new SocketBridgeService(this.port!.Value);
62+
this.socketBridge = new SocketBridgeService(port, "");
6963
this.socketBridge.Ready += this.SocketBridge_Ready;
7064
this.socketBridge.Stopped += this.SocketBridge_Stopped;
7165
this.socketBridge.Start();

src/ElectronNET.API/Runtime/Controllers/RuntimeControllerElectronFirst.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected override Task StartCore()
4949
}
5050

5151
this.TransitionState(LifetimeState.Starting);
52-
this.socketBridge = new SocketBridgeService(this.port!.Value);
52+
this.socketBridge = new SocketBridgeService(this.port!.Value, "");
5353
this.socketBridge.Ready += this.SocketBridge_Ready;
5454
this.socketBridge.Stopped += this.SocketBridge_Stopped;
5555
this.socketBridge.Start();

src/ElectronNET.API/Runtime/Data/StartupMethod.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,5 @@ public enum StartupMethod
3333
/// On the command lines, this is "unpackeddotnet"
3434
/// </remarks>
3535
UnpackedDotnetFirst,
36-
37-
/// <summary>Packaged Electron app where DotNet launches Electron and uses SignalR for communication.</summary>
38-
/// <remarks>
39-
/// DotNet starts first on port 0 (dynamic), launches Electron with the actual URL,
40-
/// and uses SignalR instead of socket.io for bidirectional communication.
41-
/// Optimized for Blazor Server scenarios. ASP.NET Core only.
42-
/// On the command lines, this is "dotnetpackedsignalr"
43-
/// </remarks>
44-
PackagedDotnetFirstSignalR,
45-
46-
/// <summary>Unpackaged execution where DotNet launches Electron and uses SignalR for communication.</summary>
47-
/// <remarks>
48-
/// Similar to PackagedDotnetFirstSignalR but for debugging scenarios.
49-
/// DotNet starts first on port 0 (dynamic), launches Electron with the actual URL,
50-
/// and uses SignalR instead of socket.io for bidirectional communication.
51-
/// On the command lines, this is "unpackeddotnetsignalr"
52-
/// </remarks>
53-
UnpackedDotnetFirstSignalR,
5436
}
5537
}

0 commit comments

Comments
 (0)