[PR #905] [MERGED] Initial refactoring of dotnet API #1344

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

📋 Pull Request Information

Original PR: https://github.com/ElectronNET/Electron.NET/pull/905
Author: @agracio
Created: 11/5/2025
Status: Merged
Merged: 11/6/2025
Merged by: @FlorianRappl

Base: developHead: develop


📝 Commits (6)

  • 689a002 refactoring dotnet events
  • 408f83e refactoring dotnet events
  • b6b9292 refactoring dotnet events
  • ea68802 refactoring dotnet events
  • 87668f5 removing '-event' suffix from event names to normalise naming convention
  • de7f981 removing '-event' suffix from event names to normalise naming convention

📊 Changes

23 files changed (+306 additions, -1452 deletions)

View changed files

📝 src/ElectronNET.API/API/App.cs (+21 -145)
📝 src/ElectronNET.API/API/AutoUpdater.cs (+14 -120)
📝 src/ElectronNET.API/API/BrowserWindow.cs (+56 -594)
📝 src/ElectronNET.API/API/NativeTheme.cs (+3 -22)
📝 src/ElectronNET.API/API/PowerMonitor.cs (+17 -142)
📝 src/ElectronNET.API/API/Screen.cs (+7 -63)
📝 src/ElectronNET.API/API/Tray.cs (+14 -129)
📝 src/ElectronNET.API/API/WebContents.cs (+20 -182)
📝 src/ElectronNET.API/API/WindowManager.cs (+1 -1)
src/ElectronNET.API/Common/ApiEventManager.cs (+99 -0)
📝 src/ElectronNET.Host/api/app.js (+9 -9)
📝 src/ElectronNET.Host/api/app.ts (+9 -9)
📝 src/ElectronNET.Host/api/autoUpdater.js (+6 -6)
📝 src/ElectronNET.Host/api/autoUpdater.ts (+6 -6)
📝 src/ElectronNET.Host/api/nativeTheme.js (+1 -1)
📝 src/ElectronNET.Host/api/nativeTheme.ts (+1 -1)
📝 src/ElectronNET.Host/api/screen.js (+3 -3)
📝 src/ElectronNET.Host/api/screen.js.map (+1 -1)
📝 src/ElectronNET.Host/api/screen.ts (+3 -3)
📝 src/ElectronNET.Host/api/tray.js (+6 -6)

...and 3 more files

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ElectronNET/Electron.NET/pull/905 **Author:** [@agracio](https://github.com/agracio) **Created:** 11/5/2025 **Status:** ✅ Merged **Merged:** 11/6/2025 **Merged by:** [@FlorianRappl](https://github.com/FlorianRappl) **Base:** `develop` ← **Head:** `develop` --- ### 📝 Commits (6) - [`689a002`](https://github.com/ElectronNET/Electron.NET/commit/689a002dc204353edaf20762a1de74b0de9ec8ae) refactoring dotnet events - [`408f83e`](https://github.com/ElectronNET/Electron.NET/commit/408f83e401064dd40de71e8320ea44af1f1dbb3e) refactoring dotnet events - [`b6b9292`](https://github.com/ElectronNET/Electron.NET/commit/b6b9292478f7dc3a281e8711d50973cd96c343fd) refactoring dotnet events - [`ea68802`](https://github.com/ElectronNET/Electron.NET/commit/ea688026d0d15c1268455d7f114ef33088622745) refactoring dotnet events - [`87668f5`](https://github.com/ElectronNET/Electron.NET/commit/87668f5606e2be191773b91f771bda7b06919302) removing '-event' suffix from event names to normalise naming convention - [`de7f981`](https://github.com/ElectronNET/Electron.NET/commit/de7f98136e101494031613ccddf8d22a1ddff17e) removing '-event' suffix from event names to normalise naming convention ### 📊 Changes **23 files changed** (+306 additions, -1452 deletions) <details> <summary>View changed files</summary> 📝 `src/ElectronNET.API/API/App.cs` (+21 -145) 📝 `src/ElectronNET.API/API/AutoUpdater.cs` (+14 -120) 📝 `src/ElectronNET.API/API/BrowserWindow.cs` (+56 -594) 📝 `src/ElectronNET.API/API/NativeTheme.cs` (+3 -22) 📝 `src/ElectronNET.API/API/PowerMonitor.cs` (+17 -142) 📝 `src/ElectronNET.API/API/Screen.cs` (+7 -63) 📝 `src/ElectronNET.API/API/Tray.cs` (+14 -129) 📝 `src/ElectronNET.API/API/WebContents.cs` (+20 -182) 📝 `src/ElectronNET.API/API/WindowManager.cs` (+1 -1) ➕ `src/ElectronNET.API/Common/ApiEventManager.cs` (+99 -0) 📝 `src/ElectronNET.Host/api/app.js` (+9 -9) 📝 `src/ElectronNET.Host/api/app.ts` (+9 -9) 📝 `src/ElectronNET.Host/api/autoUpdater.js` (+6 -6) 📝 `src/ElectronNET.Host/api/autoUpdater.ts` (+6 -6) 📝 `src/ElectronNET.Host/api/nativeTheme.js` (+1 -1) 📝 `src/ElectronNET.Host/api/nativeTheme.ts` (+1 -1) 📝 `src/ElectronNET.Host/api/screen.js` (+3 -3) 📝 `src/ElectronNET.Host/api/screen.js.map` (+1 -1) 📝 `src/ElectronNET.Host/api/screen.ts` (+3 -3) 📝 `src/ElectronNET.Host/api/tray.js` (+6 -6) _...and 3 more files_ </details> ### 📄 Description #### 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 16:59:48 +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#1344