[PR #905] Initial refactoring of dotnet API #1349

Open
opened 2026-01-29 16:59:49 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/ElectronNET/Electron.NET/pull/905

State: closed
Merged: Yes


Currently events and tasks have a lot of repetitive code, this RP attempts to remove some of the repetition starting with events.

Changes summary

  • Added new helper class ApiEventManager to wrap events code.
  • Refactored events in App.cs, BrowserWindow.cs, Tray.cs, AutoUpdater.cs, NativeTheme.cs, PowerMonitor.cs, Screen.cs, WebContents.cs
  • Changed event names in Tray and Screen API.

Different event naming and Tray API changes

Currently Electron.NET API has multiple event naming schemes making it harder to implement a single method for wrapping events, examples below. Event names in .NET API correspond to event names in TypeScript/JS implementation.

  • BrowserWindow API does not add any additional names to events.
BridgeConnector.Socket.On(eventName + id, () => { callback(); });
BridgeConnector.Socket.Emit("register-" + eventName, id);
  • App API adds -event to Emit() method.
BridgeConnector.Socket.On(eventName + id, () => { callback(); });
BridgeConnector.Socket.Emit("register-" + eventName + "-event", id);
  • Tray and Screen API was adding -event to On() method.
BridgeConnector.Socket.On(eventName + id + "-event", () => { callback(); });
BridgeConnector.Socket.Emit("register-" + eventName, id);

In order to keep different method signatures to a minimum I have renamed Tray and Screen API events in line with BrowserWindow.

This is a work in progress but would like to get some feedback to make sure the change is acceptable.

**Original Pull Request:** https://github.com/ElectronNET/Electron.NET/pull/905 **State:** closed **Merged:** Yes --- #### Currently events and tasks have a lot of repetitive code, this RP attempts to remove some of the repetition starting with events. #### Changes summary - Added new helper class `ApiEventManager` to wrap events code. - Refactored events in `App.cs`, `BrowserWindow.cs`, `Tray.cs`, `AutoUpdater.cs`, `NativeTheme.cs`, `PowerMonitor.cs`, `Screen.cs`, `WebContents.cs` - Changed event names in `Tray` and `Screen` API. #### Different event naming and Tray API changes Currently Electron.NET API has multiple event naming schemes making it harder to implement a single method for wrapping events, examples below. Event names in .NET API correspond to event names in TypeScript/JS implementation. - `BrowserWindow` API does not add any additional names to events. ```cs BridgeConnector.Socket.On(eventName + id, () => { callback(); }); BridgeConnector.Socket.Emit("register-" + eventName, id); ``` - `App` API adds `-event` to `Emit()` method. ```cs BridgeConnector.Socket.On(eventName + id, () => { callback(); }); BridgeConnector.Socket.Emit("register-" + eventName + "-event", id); ``` - `Tray` and `Screen` API was adding `-event` to `On()` method. ```cs BridgeConnector.Socket.On(eventName + id + "-event", () => { callback(); }); BridgeConnector.Socket.Emit("register-" + eventName, id); ``` In order to keep different method signatures to a minimum I have renamed Tray and Screen API events in line with BrowserWindow. This is a work in progress but would like to get some feedback to make sure the change is acceptable.
claunia added the pull-request label 2026-01-29 16:59:49 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#1349