mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-11 03:08:45 +00:00
Refactor: Introduce IFacade interface for SocketIO and SignalR facades
- Create IFacade interface defining common API for SocketIO and SignalR - Update SocketIoFacade to implement IFacade - Update SignalRFacade to implement IFacade (add Connect no-op) - Update RuntimeControllerBase.Socket to return IFacade - Update RuntimeControllerAspNetBase.Socket to return IFacade - Update RuntimeControllerDotNetFirst.Socket to return IFacade - Update ElectronNetRuntime.GetSocket() to return IFacade - Update BridgeConnector.Socket to return IFacade This enables polymorphic usage of both facades throughout the codebase and prepares for full Electron API integration with SignalR mode.
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
using ElectronNET.API.Bridge;
|
||||
|
||||
internal static class BridgeConnector
|
||||
{
|
||||
public static SocketIoFacade Socket
|
||||
public static IFacade Socket
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
62
src/ElectronNET.API/Bridge/IFacade.cs
Normal file
62
src/ElectronNET.API/Bridge/IFacade.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
namespace ElectronNET.API.Bridge
|
||||
{
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// Common interface for communication facades (SocketIO and SignalR).
|
||||
/// Provides methods for bidirectional communication between .NET and Electron.
|
||||
/// </summary>
|
||||
internal interface IFacade
|
||||
{
|
||||
/// <summary>
|
||||
/// Raised when the bridge connection is established.
|
||||
/// </summary>
|
||||
event EventHandler BridgeConnected;
|
||||
|
||||
/// <summary>
|
||||
/// Raised when the bridge connection is lost.
|
||||
/// </summary>
|
||||
event EventHandler BridgeDisconnected;
|
||||
|
||||
/// <summary>
|
||||
/// Establishes the connection to Electron.
|
||||
/// </summary>
|
||||
void Connect();
|
||||
|
||||
/// <summary>
|
||||
/// Registers a persistent event handler.
|
||||
/// </summary>
|
||||
void On(string eventName, Action action);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a persistent event handler with a typed parameter.
|
||||
/// </summary>
|
||||
void On<T>(string eventName, Action<T> action);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a one-time event handler.
|
||||
/// </summary>
|
||||
void Once(string eventName, Action action);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a one-time event handler with a typed parameter.
|
||||
/// </summary>
|
||||
void Once<T>(string eventName, Action<T> action);
|
||||
|
||||
/// <summary>
|
||||
/// Removes an event handler.
|
||||
/// </summary>
|
||||
void Off(string eventName);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a message to Electron.
|
||||
/// </summary>
|
||||
Task Emit(string eventName, params object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the connection.
|
||||
/// </summary>
|
||||
void DisposeSocket();
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,12 @@ namespace ElectronNET.API;
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Bridge;
|
||||
using ElectronNET.API.Serialization;
|
||||
using SocketIO.Serializer.SystemTextJson;
|
||||
using SocketIO = SocketIOClient.SocketIO;
|
||||
|
||||
internal class SocketIoFacade
|
||||
internal class SocketIoFacade : IFacade
|
||||
{
|
||||
private readonly SocketIO _socket;
|
||||
private readonly object _lockObj = new object();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace ElectronNET
|
||||
{
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.API.Bridge;
|
||||
using ElectronNET.Runtime;
|
||||
using ElectronNET.Runtime.Controllers;
|
||||
using ElectronNET.Runtime.Data;
|
||||
@@ -49,7 +50,7 @@
|
||||
|
||||
internal static Func<Task> OnAppReadyCallback { get; set; }
|
||||
|
||||
internal static SocketIoFacade GetSocket()
|
||||
internal static IFacade GetSocket()
|
||||
{
|
||||
return RuntimeControllerCore?.Socket;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace ElectronNET.Runtime.Controllers
|
||||
{
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.API.Bridge;
|
||||
using ElectronNET.Runtime.Services;
|
||||
using ElectronNET.Runtime.Services.ElectronProcess;
|
||||
using ElectronNET.Runtime.Services.SocketBridge;
|
||||
@@ -12,7 +13,7 @@
|
||||
{
|
||||
}
|
||||
|
||||
internal abstract SocketIoFacade Socket { get; }
|
||||
internal abstract IFacade Socket { get; }
|
||||
|
||||
internal abstract ElectronProcessBase ElectronProcess { get; }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace ElectronNET.Runtime.Controllers
|
||||
{
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.API.Bridge;
|
||||
using ElectronNET.Common;
|
||||
using ElectronNET.Runtime.Data;
|
||||
using ElectronNET.Runtime.Helpers;
|
||||
@@ -19,7 +20,7 @@
|
||||
{
|
||||
}
|
||||
|
||||
internal override SocketIoFacade Socket
|
||||
internal override IFacade Socket
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user