Compare commits

...

3 Commits

Author SHA1 Message Date
Florian Rappl
8fc197b32a Proposed fix for releaseNotes serialization #1039 2026-03-18 20:12:06 +01:00
Florian Rappl
201046164c Merge pull request #1037 from ElectronNET/feature/socket-interface
Changed facade to socket connection
2026-03-05 23:18:24 +01:00
Florian Rappl
b8151a2fad Changed facade to socket connection 2026-03-05 11:25:22 +01:00
12 changed files with 90 additions and 13 deletions

View File

@@ -4,7 +4,7 @@ namespace ElectronNET.API
{
internal static class BridgeConnector
{
public static SocketIoFacade Socket
public static ISocketConnection Socket
{
get
{

View File

@@ -0,0 +1,56 @@
namespace ElectronNET.API;
using System;
using System.Threading.Tasks;
/// <summary>
/// Common interface for communication facades.
/// Provides methods for bidirectional communication between .NET and Electron.
/// </summary>
internal interface ISocketConnection : IDisposable
{
/// <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);
}

View File

@@ -8,13 +8,13 @@ using ElectronNET.API.Serialization;
using SocketIO.Serializer.SystemTextJson;
using SocketIO = SocketIOClient.SocketIO;
internal class SocketIoFacade : IDisposable
internal class SocketIOConnection : ISocketConnection
{
private readonly SocketIO _socket;
private readonly object _lockObj = new object();
private bool _isDisposed;
public SocketIoFacade(string uri)
public SocketIOConnection(string uri)
{
_socket = new SocketIO(uri);
_socket.Serializer = new SystemTextJsonSerializer(ElectronJson.Options);
@@ -140,7 +140,7 @@ internal class SocketIoFacade : IDisposable
{
if (this._isDisposed)
{
throw new ObjectDisposedException(nameof(SocketIoFacade));
throw new ObjectDisposedException(nameof(SocketIOConnection));
}
}
}

View File

@@ -49,7 +49,7 @@
internal static Func<Task> OnAppReadyCallback { get; set; }
internal static SocketIoFacade GetSocket()
internal static ISocketConnection GetSocket()
{
return RuntimeControllerCore?.Socket;
}

View File

@@ -12,7 +12,7 @@
{
}
internal abstract SocketIoFacade Socket { get; }
internal abstract ISocketConnection Socket { get; }
internal abstract ElectronProcessBase ElectronProcess { get; }

View File

@@ -19,7 +19,7 @@
{
}
internal override SocketIoFacade Socket
internal override ISocketConnection Socket
{
get
{

View File

@@ -17,7 +17,7 @@
{
}
internal override SocketIoFacade Socket
internal override ISocketConnection Socket
{
get
{

View File

@@ -9,7 +9,7 @@
{
private readonly int socketPort;
private readonly string socketUrl;
private SocketIoFacade socket;
private SocketIOConnection socket;
public SocketBridgeService(int socketPort)
{
@@ -19,11 +19,11 @@
public int SocketPort => this.socketPort;
internal SocketIoFacade Socket => this.socket;
internal SocketIOConnection Socket => this.socket;
protected override Task StartCore()
{
this.socket = new SocketIoFacade(this.socketUrl);
this.socket = new SocketIOConnection(this.socketUrl);
this.socket.BridgeConnected += this.Socket_BridgeConnected;
this.socket.BridgeDisconnected += this.Socket_BridgeDisconnected;
Task.Run(this.Connect);

View File

@@ -25,7 +25,7 @@
internal override SocketBridgeService SocketBridge => this.socketBridge;
internal override SocketIoFacade Socket
internal override ISocketConnection Socket
{
get
{

View File

@@ -1,6 +1,11 @@
"use strict";
const electron_updater_1 = require("electron-updater");
let electronSocket;
function normalize(updateInfo) {
if (typeof updateInfo?.releaseNotes === "string") {
updateInfo.releaseNotes = [updateInfo.releaseNotes];
}
}
module.exports = (socket) => {
electronSocket = socket;
socket.on("register-autoUpdater-error", (id) => {
@@ -15,11 +20,13 @@ module.exports = (socket) => {
});
socket.on("register-autoUpdater-update-available", (id) => {
electron_updater_1.autoUpdater.on("update-available", (updateInfo) => {
normalize(updateInfo);
electronSocket.emit("autoUpdater-update-available" + id, updateInfo);
});
});
socket.on("register-autoUpdater-update-not-available", (id) => {
electron_updater_1.autoUpdater.on("update-not-available", (updateInfo) => {
normalize(updateInfo);
electronSocket.emit("autoUpdater-update-not-available" + id, updateInfo);
});
});
@@ -30,6 +37,7 @@ module.exports = (socket) => {
});
socket.on("register-autoUpdater-update-downloaded", (id) => {
electron_updater_1.autoUpdater.on("update-downloaded", (updateInfo) => {
normalize(updateInfo);
electronSocket.emit("autoUpdater-update-downloaded" + id, updateInfo);
});
});
@@ -89,6 +97,7 @@ module.exports = (socket) => {
electron_updater_1.autoUpdater
.checkForUpdatesAndNotify()
.then((updateCheckResult) => {
normalize(updateCheckResult?.updateInfo);
electronSocket.emit("autoUpdater-checkForUpdatesAndNotify-completed" + guid, updateCheckResult);
})
.catch((error) => {
@@ -99,6 +108,7 @@ module.exports = (socket) => {
electron_updater_1.autoUpdater
.checkForUpdates()
.then((updateCheckResult) => {
normalize(updateCheckResult?.updateInfo);
electronSocket.emit("autoUpdater-checkForUpdates-completed" + guid, updateCheckResult);
})
.catch((error) => {

File diff suppressed because one or more lines are too long

View File

@@ -3,6 +3,12 @@ import { autoUpdater } from "electron-updater";
let electronSocket: Socket;
function normalize(updateInfo) {
if (typeof updateInfo?.releaseNotes === "string") {
updateInfo.releaseNotes = [updateInfo.releaseNotes];
}
}
export = (socket: Socket) => {
electronSocket = socket;
@@ -20,12 +26,14 @@ export = (socket: Socket) => {
socket.on("register-autoUpdater-update-available", (id) => {
autoUpdater.on("update-available", (updateInfo) => {
normalize(updateInfo);
electronSocket.emit("autoUpdater-update-available" + id, updateInfo);
});
});
socket.on("register-autoUpdater-update-not-available", (id) => {
autoUpdater.on("update-not-available", (updateInfo) => {
normalize(updateInfo);
electronSocket.emit("autoUpdater-update-not-available" + id, updateInfo);
});
});
@@ -38,6 +46,7 @@ export = (socket: Socket) => {
socket.on("register-autoUpdater-update-downloaded", (id) => {
autoUpdater.on("update-downloaded", (updateInfo) => {
normalize(updateInfo);
electronSocket.emit("autoUpdater-update-downloaded" + id, updateInfo);
});
});
@@ -143,6 +152,7 @@ export = (socket: Socket) => {
autoUpdater
.checkForUpdatesAndNotify()
.then((updateCheckResult) => {
normalize(updateCheckResult?.updateInfo);
electronSocket.emit(
"autoUpdater-checkForUpdatesAndNotify-completed" + guid,
updateCheckResult,
@@ -160,6 +170,7 @@ export = (socket: Socket) => {
autoUpdater
.checkForUpdates()
.then((updateCheckResult) => {
normalize(updateCheckResult?.updateInfo);
electronSocket.emit(
"autoUpdater-checkForUpdates-completed" + guid,
updateCheckResult,