Skip to content

Conversation

@agracio
Copy link

@agracio agracio commented Nov 5, 2025

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.

@FlorianRappl
Copy link
Collaborator

Actually much appreciated - with more time this is something on my list (really cumbersome code in some areas, could benefit a lot from some refactoring... - so great job 🚀 !).

Copy link
Collaborator

@FlorianRappl FlorianRappl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely appreciated and goes in the right direction. Just let me know when you are done / want to see it merged in.

@agracio
Copy link
Author

agracio commented Nov 5, 2025

Almost done with events but would also want to clean up at least some of the tasks code. I will let you know when events are done.

@agracio
Copy link
Author

agracio commented Nov 5, 2025

Events are done. Even managed to find an error in one of them.

Task optimisation is next but you can merge event changes first if you want.

@agracio
Copy link
Author

agracio commented Nov 5, 2025

Tasks will take significantly longer. There are many different types and of course different naming.

On subject of naming - is SocketIO case sensitive, there are some tasks that end in -completed some in -Completed and some in Completed, fingers crossed there aren't more.

@FlorianRappl
Copy link
Collaborator

Yeah so in general these strings are all case sensitive - personally, I'd make it consistent (I've seen that across the codebase many things in that area a bit inconsistent to write the least... - so using the opportunity to make the naming / transported names consistent would be appreciated).

Many thanks for your efforts - so we'll merge this one right now and do another PR at some point in time later? @agracio

@agracio
Copy link
Author

agracio commented Nov 5, 2025

Yes I would suggest to merge these changes first while I work on tasks. There is more than I initially thought.

@agracio
Copy link
Author

agracio commented Nov 5, 2025

Alternatively I can refactor App API to normalize it's event naming, this would not take long at all.

@FlorianRappl
Copy link
Collaborator

Alternatively I can refactor App API to normalize it's event naming, this would not take long at all.

OK let's add this then merge! Thanks!

@agracio
Copy link
Author

agracio commented Nov 5, 2025

All done. Please give it a thorough review.

Copy link
Collaborator

@FlorianRappl FlorianRappl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - at least I could not see anything going wrong here in the review pane. Let's merge and test with the preview version.

@FlorianRappl FlorianRappl merged commit 4671b9b into ElectronNET:develop Nov 6, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants