From 689a002dc204353edaf20762a1de74b0de9ec8ae Mon Sep 17 00:00:00 2001 From: agracio Date: Wed, 5 Nov 2025 13:25:15 +0000 Subject: [PATCH] refactoring dotnet events --- src/ElectronNET.API/API/App.cs | 158 +---- src/ElectronNET.API/API/BrowserWindow.cs | 650 ++---------------- src/ElectronNET.API/API/Tray.cs | 143 +--- src/ElectronNET.API/Common/ApiEventManager.cs | 82 +++ src/ElectronNET.Host/api/tray.js | 12 +- src/ElectronNET.Host/api/tray.js.map | 2 +- src/ElectronNET.Host/api/tray.ts | 12 +- 7 files changed, 182 insertions(+), 877 deletions(-) create mode 100644 src/ElectronNET.API/Common/ApiEventManager.cs diff --git a/src/ElectronNET.API/API/App.cs b/src/ElectronNET.API/API/App.cs index 088ed84..1c5c2e0 100644 --- a/src/ElectronNET.API/API/App.cs +++ b/src/ElectronNET.API/API/App.cs @@ -7,7 +7,9 @@ using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using ElectronNET.API.Extensions; -using static System.Collections.Specialized.BitVector32; +using ElectronNET.Common; + +// ReSharper disable InconsistentNaming namespace ElectronNET.API { @@ -217,26 +219,8 @@ namespace ElectronNET.API /// public event Action BrowserWindowBlur { - add - { - if (_browserWindowBlur == null) - { - BridgeConnector.Socket.On("app-browser-window-blur" + GetHashCode(), () => - { - _browserWindowBlur(); - }); - - BridgeConnector.Socket.Emit("register-app-browser-window-blur-event", GetHashCode()); - } - _browserWindowBlur += value; - } - remove - { - _browserWindowBlur -= value; - - if (_browserWindowBlur == null) - BridgeConnector.Socket.Off("app-browser-window-blur" + GetHashCode()); - } + add => ApiEventManager.AddEventWithSuffix("app-browser-window-blur", GetHashCode(), _browserWindowBlur, value); + remove => ApiEventManager.RemoveEvent("app-browser-window-blur", GetHashCode(), _browserWindowBlur, value); } private event Action _browserWindowBlur; @@ -246,26 +230,8 @@ namespace ElectronNET.API /// public event Action BrowserWindowFocus { - add - { - if (_browserWindowFocus == null) - { - BridgeConnector.Socket.On("app-browser-window-focus" + GetHashCode(), () => - { - _browserWindowFocus(); - }); - - BridgeConnector.Socket.Emit("register-app-browser-window-focus-event", GetHashCode()); - } - _browserWindowFocus += value; - } - remove - { - _browserWindowFocus -= value; - - if (_browserWindowFocus == null) - BridgeConnector.Socket.Off("app-browser-window-focus" + GetHashCode()); - } + add => ApiEventManager.AddEventWithSuffix("app-browser-window-focus", GetHashCode(), _browserWindowFocus, value); + remove => ApiEventManager.RemoveEvent("app-browser-window-focus", GetHashCode(), _browserWindowFocus, value); } private event Action _browserWindowFocus; @@ -275,26 +241,8 @@ namespace ElectronNET.API /// public event Action BrowserWindowCreated { - add - { - if (_browserWindowCreated == null) - { - BridgeConnector.Socket.On("app-browser-window-created" + GetHashCode(), () => - { - _browserWindowCreated(); - }); - - BridgeConnector.Socket.Emit("register-app-browser-window-created-event", GetHashCode()); - } - _browserWindowCreated += value; - } - remove - { - _browserWindowCreated -= value; - - if (_browserWindowCreated == null) - BridgeConnector.Socket.Off("app-browser-window-created" + GetHashCode()); - } + add => ApiEventManager.AddEventWithSuffix("app-browser-window-created", GetHashCode(), _browserWindowCreated, value); + remove => ApiEventManager.RemoveEvent("app-browser-window-created", GetHashCode(), _browserWindowCreated, value); } private event Action _browserWindowCreated; @@ -304,26 +252,8 @@ namespace ElectronNET.API /// public event Action WebContentsCreated { - add - { - if (_webContentsCreated == null) - { - BridgeConnector.Socket.On("app-web-contents-created" + GetHashCode(), () => - { - _webContentsCreated(); - }); - - BridgeConnector.Socket.Emit("register-app-web-contents-created-event", GetHashCode()); - } - _webContentsCreated += value; - } - remove - { - _webContentsCreated -= value; - - if (_webContentsCreated == null) - BridgeConnector.Socket.Off("app-web-contents-created" + GetHashCode()); - } + add => ApiEventManager.AddEventWithSuffix("app-web-contents-created", GetHashCode(), _webContentsCreated, value); + remove => ApiEventManager.RemoveEvent("app-web-contents-created", GetHashCode(), _webContentsCreated, value); } private event Action _webContentsCreated; @@ -335,26 +265,8 @@ namespace ElectronNET.API /// when Chrome's accessibility support is enabled, otherwise. public event Action AccessibilitySupportChanged { - add - { - if (_accessibilitySupportChanged == null) - { - BridgeConnector.Socket.On("app-accessibility-support-changed" + GetHashCode(), (state) => - { - _accessibilitySupportChanged((bool)state); - }); - - BridgeConnector.Socket.Emit("register-app-accessibility-support-changed-event", GetHashCode()); - } - _accessibilitySupportChanged += value; - } - remove - { - _accessibilitySupportChanged -= value; - - if (_accessibilitySupportChanged == null) - BridgeConnector.Socket.Off("app-accessibility-support-changed" + GetHashCode()); - } + add => ApiEventManager.AddEventWithSuffix("app-accessibility-support-changed", GetHashCode(), _accessibilitySupportChanged, value, (args) => (bool)args); + remove => ApiEventManager.RemoveEvent("app-accessibility-support-changed", GetHashCode(), _accessibilitySupportChanged, value); } private event Action _accessibilitySupportChanged; @@ -408,26 +320,8 @@ namespace ElectronNET.API /// public event Action OpenFile { - add - { - if (_openFile == null) - { - BridgeConnector.Socket.On("app-open-file" + GetHashCode(), (file) => - { - _openFile(file.ToString()); - }); - - BridgeConnector.Socket.Emit("register-app-open-file-event", GetHashCode()); - } - _openFile += value; - } - remove - { - _openFile -= value; - - if (_openFile == null) - BridgeConnector.Socket.Off("app-open-file" + GetHashCode()); - } + add => ApiEventManager.AddEventWithSuffix("app-open-file", GetHashCode(), _openFile, value, (args) => args.ToString()); + remove => ApiEventManager.RemoveEvent("app-open-file", GetHashCode(), _openFile, value); } private event Action _openFile; @@ -439,26 +333,8 @@ namespace ElectronNET.API /// public event Action OpenUrl { - add - { - if (_openUrl == null) - { - BridgeConnector.Socket.On("app-open-url" + GetHashCode(), (url) => - { - _openUrl(url.ToString()); - }); - - BridgeConnector.Socket.Emit("register-app-open-url-event", GetHashCode()); - } - _openUrl += value; - } - remove - { - _openUrl -= value; - - if (_openUrl == null) - BridgeConnector.Socket.Off("app-open-url" + GetHashCode()); - } + add => ApiEventManager.AddEventWithSuffix("app-open-url", GetHashCode(), _openUrl, value, (args) => args.ToString()); + remove => ApiEventManager.RemoveEvent("app-open-url", GetHashCode(), _openUrl, value); } private event Action _openUrl; diff --git a/src/ElectronNET.API/API/BrowserWindow.cs b/src/ElectronNET.API/API/BrowserWindow.cs index 2fd04a4..25a0b79 100644 --- a/src/ElectronNET.API/API/BrowserWindow.cs +++ b/src/ElectronNET.API/API/BrowserWindow.cs @@ -8,6 +8,8 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; +using ElectronNET.Common; +// ReSharper disable InconsistentNaming namespace ElectronNET.API; @@ -30,28 +32,8 @@ public class BrowserWindow /// public event Action OnReadyToShow { - add - { - if (_readyToShow == null) - { - BridgeConnector.Socket.On("browserWindow-ready-to-show" + Id, () => - { - _readyToShow(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-ready-to-show", Id); - } - _readyToShow += value; - } - remove - { - _readyToShow -= value; - - if (_readyToShow == null) - { - BridgeConnector.Socket.Off("browserWindow-ready-to-show" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-ready-to-show", Id, _readyToShow, value); + remove => ApiEventManager.RemoveEvent("browserWindow-ready-to-show", Id, _readyToShow, value); } private event Action _readyToShow; @@ -61,28 +43,8 @@ public class BrowserWindow /// public event Action OnPageTitleUpdated { - add - { - if (_pageTitleUpdated == null) - { - BridgeConnector.Socket.On("browserWindow-page-title-updated" + Id, (title) => - { - _pageTitleUpdated(title.ToString()); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-page-title-updated", Id); - } - _pageTitleUpdated += value; - } - remove - { - _pageTitleUpdated -= value; - - if (_pageTitleUpdated == null) - { - BridgeConnector.Socket.Off("browserWindow-page-title-updated" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-page-title-updated", Id, _pageTitleUpdated, value, (args) => args.ToString()); + remove => ApiEventManager.RemoveEvent("browserWindow-page-title-updated", Id, _pageTitleUpdated, value); } private event Action _pageTitleUpdated; @@ -92,28 +54,8 @@ public class BrowserWindow /// public event Action OnClose { - add - { - if (_close == null) - { - BridgeConnector.Socket.On("browserWindow-close" + Id, () => - { - _close(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-close", Id); - } - _close += value; - } - remove - { - _close -= value; - - if (_close == null) - { - BridgeConnector.Socket.Off("browserWindow-close" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-close", Id, _close, value); + remove => ApiEventManager.RemoveEvent("browserWindow-close", Id, _close, value); } private event Action _close; @@ -125,28 +67,8 @@ public class BrowserWindow /// public event Action OnClosed { - add - { - if (_closed == null) - { - BridgeConnector.Socket.On("browserWindow-closed" + Id, () => - { - _closed(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-closed", Id); - } - _closed += value; - } - remove - { - _closed -= value; - - if (_closed == null) - { - BridgeConnector.Socket.Off("browserWindow-closed" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-closed", Id, _closed, value); + remove => ApiEventManager.RemoveEvent("browserWindow-closed", Id, _closed, value); } private event Action _closed; @@ -156,28 +78,8 @@ public class BrowserWindow /// public event Action OnSessionEnd { - add - { - if (_sessionEnd == null) - { - BridgeConnector.Socket.On("browserWindow-session-end" + Id, () => - { - _sessionEnd(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-session-end", Id); - } - _sessionEnd += value; - } - remove - { - _sessionEnd -= value; - - if (_sessionEnd == null) - { - BridgeConnector.Socket.Off("browserWindow-session-end" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-session-end", Id, _sessionEnd, value); + remove => ApiEventManager.RemoveEvent("browserWindow-session-end", Id, _sessionEnd, value); } private event Action _sessionEnd; @@ -187,28 +89,8 @@ public class BrowserWindow /// public event Action OnUnresponsive { - add - { - if (_unresponsive == null) - { - BridgeConnector.Socket.On("browserWindow-unresponsive" + Id, () => - { - _unresponsive(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-unresponsive", Id); - } - _unresponsive += value; - } - remove - { - _unresponsive -= value; - - if (_unresponsive == null) - { - BridgeConnector.Socket.Off("browserWindow-unresponsive" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-unresponsive", Id, _unresponsive, value); + remove => ApiEventManager.RemoveEvent("browserWindow-unresponsive", Id, _unresponsive, value); } private event Action _unresponsive; @@ -218,28 +100,8 @@ public class BrowserWindow /// public event Action OnResponsive { - add - { - if (_responsive == null) - { - BridgeConnector.Socket.On("browserWindow-responsive" + Id, () => - { - _responsive(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-responsive", Id); - } - _responsive += value; - } - remove - { - _responsive -= value; - - if (_responsive == null) - { - BridgeConnector.Socket.Off("browserWindow-responsive" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-responsive", Id, _responsive, value); + remove => ApiEventManager.RemoveEvent("browserWindow-responsive", Id, _responsive, value); } private event Action _responsive; @@ -249,28 +111,8 @@ public class BrowserWindow /// public event Action OnBlur { - add - { - if (_blur == null) - { - BridgeConnector.Socket.On("browserWindow-blur" + Id, () => - { - _blur(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-blur", Id); - } - _blur += value; - } - remove - { - _blur -= value; - - if (_blur == null) - { - BridgeConnector.Socket.Off("browserWindow-blur" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-blur", Id, _blur, value); + remove => ApiEventManager.RemoveEvent("browserWindow-blur", Id, _blur, value); } private event Action _blur; @@ -280,28 +122,8 @@ public class BrowserWindow /// public event Action OnFocus { - add - { - if (_focus == null) - { - BridgeConnector.Socket.On("browserWindow-focus" + Id, () => - { - _focus(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-focus", Id); - } - _focus += value; - } - remove - { - _focus -= value; - - if (_focus == null) - { - BridgeConnector.Socket.Off("browserWindow-focus" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-focus", Id, _focus, value); + remove => ApiEventManager.RemoveEvent("browserWindow-focus", Id, _focus, value); } private event Action _focus; @@ -311,28 +133,8 @@ public class BrowserWindow /// public event Action OnShow { - add - { - if (_show == null) - { - BridgeConnector.Socket.On("browserWindow-show" + Id, () => - { - _show(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-show", Id); - } - _show += value; - } - remove - { - _show -= value; - - if (_show == null) - { - BridgeConnector.Socket.Off("browserWindow-show" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-show", Id, _show, value); + remove => ApiEventManager.RemoveEvent("browserWindow-show", Id, _show, value); } private event Action _show; @@ -342,28 +144,8 @@ public class BrowserWindow /// public event Action OnHide { - add - { - if (_hide == null) - { - BridgeConnector.Socket.On("browserWindow-hide" + Id, () => - { - _hide(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-hide", Id); - } - _hide += value; - } - remove - { - _hide -= value; - - if (_hide == null) - { - BridgeConnector.Socket.Off("browserWindow-hide" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-hide", Id, _hide, value); + remove => ApiEventManager.RemoveEvent("browserWindow-hide", Id, _hide, value); } private event Action _hide; @@ -373,28 +155,8 @@ public class BrowserWindow /// public event Action OnMaximize { - add - { - if (_maximize == null) - { - BridgeConnector.Socket.On("browserWindow-maximize" + Id, () => - { - _maximize(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-maximize", Id); - } - _maximize += value; - } - remove - { - _maximize -= value; - - if (_maximize == null) - { - BridgeConnector.Socket.Off("browserWindow-maximize" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-maximize", Id, _maximize, value); + remove => ApiEventManager.RemoveEvent("browserWindow-maximize", Id, _maximize, value); } private event Action _maximize; @@ -404,28 +166,8 @@ public class BrowserWindow /// public event Action OnUnmaximize { - add - { - if (_unmaximize == null) - { - BridgeConnector.Socket.On("browserWindow-unmaximize" + Id, () => - { - _unmaximize(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-unmaximize", Id); - } - _unmaximize += value; - } - remove - { - _unmaximize -= value; - - if (_unmaximize == null) - { - BridgeConnector.Socket.Off("browserWindow-unmaximize" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-unmaximize", Id, _unmaximize, value); + remove => ApiEventManager.RemoveEvent("browserWindow-unmaximize", Id, _unmaximize, value); } private event Action _unmaximize; @@ -435,28 +177,8 @@ public class BrowserWindow /// public event Action OnMinimize { - add - { - if (_minimize == null) - { - BridgeConnector.Socket.On("browserWindow-minimize" + Id, () => - { - _minimize(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-minimize", Id); - } - _minimize += value; - } - remove - { - _minimize -= value; - - if (_minimize == null) - { - BridgeConnector.Socket.Off("browserWindow-minimize" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-minimize", Id, _minimize, value); + remove => ApiEventManager.RemoveEvent("browserWindow-minimize", Id, _minimize, value); } private event Action _minimize; @@ -466,28 +188,8 @@ public class BrowserWindow /// public event Action OnRestore { - add - { - if (_restore == null) - { - BridgeConnector.Socket.On("browserWindow-restore" + Id, () => - { - _restore(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-restore", Id); - } - _restore += value; - } - remove - { - _restore -= value; - - if (_restore == null) - { - BridgeConnector.Socket.Off("browserWindow-restore" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-restore", Id, _restore, value); + remove => ApiEventManager.RemoveEvent("browserWindow-restore", Id, _restore, value); } private event Action _restore; @@ -497,28 +199,8 @@ public class BrowserWindow /// public event Action OnResize { - add - { - if (_resize == null) - { - BridgeConnector.Socket.On("browserWindow-resize" + Id, () => - { - _resize(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-resize", Id); - } - _resize += value; - } - remove - { - _resize -= value; - - if (_resize == null) - { - BridgeConnector.Socket.Off("browserWindow-resize" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-resize", Id, _resize, value); + remove => ApiEventManager.RemoveEvent("browserWindow-resize", Id, _resize, value); } private event Action _resize; @@ -530,28 +212,8 @@ public class BrowserWindow /// public event Action OnMove { - add - { - if (_move == null) - { - BridgeConnector.Socket.On("browserWindow-move" + Id, () => - { - _move(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-move", Id); - } - _move += value; - } - remove - { - _move -= value; - - if (_move == null) - { - BridgeConnector.Socket.Off("browserWindow-move" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-move", Id, _move, value); + remove => ApiEventManager.RemoveEvent("browserWindow-move", Id, _move, value); } private event Action _move; @@ -561,28 +223,8 @@ public class BrowserWindow /// public event Action OnMoved { - add - { - if (_moved == null) - { - BridgeConnector.Socket.On("browserWindow-moved" + Id, () => - { - _moved(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-moved", Id); - } - _moved += value; - } - remove - { - _moved -= value; - - if (_moved == null) - { - BridgeConnector.Socket.Off("browserWindow-moved" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-moved", Id, _moved, value); + remove => ApiEventManager.RemoveEvent("browserWindow-moved", Id, _moved, value); } private event Action _moved; @@ -592,28 +234,8 @@ public class BrowserWindow /// public event Action OnEnterFullScreen { - add - { - if (_enterFullScreen == null) - { - BridgeConnector.Socket.On("browserWindow-enter-full-screen" + Id, () => - { - _enterFullScreen(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-enter-full-screen", Id); - } - _enterFullScreen += value; - } - remove - { - _enterFullScreen -= value; - - if (_enterFullScreen == null) - { - BridgeConnector.Socket.Off("browserWindow-enter-full-screen" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-enter-full-screen", Id, _enterFullScreen, value); + remove => ApiEventManager.RemoveEvent("browserWindow-enter-full-screen", Id, _enterFullScreen, value); } private event Action _enterFullScreen; @@ -623,28 +245,8 @@ public class BrowserWindow /// public event Action OnLeaveFullScreen { - add - { - if (_leaveFullScreen == null) - { - BridgeConnector.Socket.On("browserWindow-leave-full-screen" + Id, () => - { - _leaveFullScreen(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-leave-full-screen", Id); - } - _leaveFullScreen += value; - } - remove - { - _leaveFullScreen -= value; - - if (_leaveFullScreen == null) - { - BridgeConnector.Socket.Off("browserWindow-leave-full-screen" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-leave-full-screen", Id, _leaveFullScreen, value); + remove => ApiEventManager.RemoveEvent("browserWindow-leave-full-screen", Id, _leaveFullScreen, value); } private event Action _leaveFullScreen; @@ -654,28 +256,8 @@ public class BrowserWindow /// public event Action OnEnterHtmlFullScreen { - add - { - if (_enterHtmlFullScreen == null) - { - BridgeConnector.Socket.On("browserWindow-enter-html-full-screen" + Id, () => - { - _enterHtmlFullScreen(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-enter-html-full-screen", Id); - } - _enterHtmlFullScreen += value; - } - remove - { - _enterHtmlFullScreen -= value; - - if (_enterHtmlFullScreen == null) - { - BridgeConnector.Socket.Off("browserWindow-enter-html-full-screen" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-enter-html-full-screen", Id, _enterHtmlFullScreen, value); + remove => ApiEventManager.RemoveEvent("browserWindow-enter-html-full-screen", Id, _enterHtmlFullScreen, value); } private event Action _enterHtmlFullScreen; @@ -685,28 +267,8 @@ public class BrowserWindow /// public event Action OnLeaveHtmlFullScreen { - add - { - if (_leaveHtmlFullScreen == null) - { - BridgeConnector.Socket.On("browserWindow-leave-html-full-screen" + Id, () => - { - _leaveHtmlFullScreen(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-leave-html-full-screen", Id); - } - _leaveHtmlFullScreen += value; - } - remove - { - _leaveHtmlFullScreen -= value; - - if (_leaveHtmlFullScreen == null) - { - BridgeConnector.Socket.Off("browserWindow-leave-html-full-screen" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-leave-html-full-screen", Id, _leaveHtmlFullScreen, value); + remove => ApiEventManager.RemoveEvent("browserWindow-leave-html-full-screen", Id, _leaveHtmlFullScreen, value); } private event Action _leaveHtmlFullScreen; @@ -722,28 +284,8 @@ public class BrowserWindow /// public event Action OnAppCommand { - add - { - if (_appCommand == null) - { - BridgeConnector.Socket.On("browserWindow-app-command" + Id, (command) => - { - _appCommand(command.ToString()); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-app-command", Id); - } - _appCommand += value; - } - remove - { - _appCommand -= value; - - if (_appCommand == null) - { - BridgeConnector.Socket.Off("browserWindow-app-command" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-app-command", Id, _appCommand, value, (args) => args.ToString()); + remove => ApiEventManager.RemoveEvent("browserWindow-app-command", Id, _appCommand, value); } private event Action _appCommand; @@ -753,28 +295,8 @@ public class BrowserWindow /// public event Action OnSwipe { - add - { - if (_swipe == null) - { - BridgeConnector.Socket.On("browserWindow-swipe" + Id, (direction) => - { - _swipe(direction.ToString()); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-swipe", Id); - } - _swipe += value; - } - remove - { - _swipe -= value; - - if (_swipe == null) - { - BridgeConnector.Socket.Off("browserWindow-swipe" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-swipe", Id, _swipe, value, (args) => args.ToString()); + remove => ApiEventManager.RemoveEvent("browserWindow-swipe", Id, _swipe, value); } private event Action _swipe; @@ -784,28 +306,8 @@ public class BrowserWindow /// public event Action OnSheetBegin { - add - { - if (_sheetBegin == null) - { - BridgeConnector.Socket.On("browserWindow-sheet-begin" + Id, () => - { - _sheetBegin(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-sheet-begin", Id); - } - _sheetBegin += value; - } - remove - { - _sheetBegin -= value; - - if (_sheetBegin == null) - { - BridgeConnector.Socket.Off("browserWindow-sheet-begin" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-sheet-begin", Id, _sheetBegin, value); + remove => ApiEventManager.RemoveEvent("browserWindow-sheet-begin", Id, _sheetBegin, value); } private event Action _sheetBegin; @@ -815,28 +317,8 @@ public class BrowserWindow /// public event Action OnSheetEnd { - add - { - if (_sheetEnd == null) - { - BridgeConnector.Socket.On("browserWindow-sheet-end" + Id, () => - { - _sheetEnd(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-sheet-end", Id); - } - _sheetEnd += value; - } - remove - { - _sheetEnd -= value; - - if (_sheetEnd == null) - { - BridgeConnector.Socket.Off("browserWindow-sheet-end" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-sheet-end", Id, _sheetEnd, value); + remove => ApiEventManager.RemoveEvent("browserWindow-sheet-end", Id, _sheetEnd, value); } private event Action _sheetEnd; @@ -846,28 +328,8 @@ public class BrowserWindow /// public event Action OnNewWindowForTab { - add - { - if (_newWindowForTab == null) - { - BridgeConnector.Socket.On("browserWindow-new-window-for-tab" + Id, () => - { - _newWindowForTab(); - }); - - BridgeConnector.Socket.Emit("register-browserWindow-new-window-for-tab", Id); - } - _newWindowForTab += value; - } - remove - { - _newWindowForTab -= value; - - if (_newWindowForTab == null) - { - BridgeConnector.Socket.Off("browserWindow-new-window-for-tab" + Id); - } - } + add => ApiEventManager.AddEvent("browserWindow-new-window-for-tab", Id, _newWindowForTab, value); + remove => ApiEventManager.RemoveEvent("browserWindow-new-window-for-tab", Id, _newWindowForTab, value); } private event Action _newWindowForTab; diff --git a/src/ElectronNET.API/API/Tray.cs b/src/ElectronNET.API/API/Tray.cs index 906a58c..f4d353d 100644 --- a/src/ElectronNET.API/API/Tray.cs +++ b/src/ElectronNET.API/API/Tray.cs @@ -6,6 +6,8 @@ using Newtonsoft.Json.Serialization; using System; using System.Collections.Generic; using System.Threading.Tasks; +using ElectronNET.Common; +// ReSharper disable InconsistentNaming namespace ElectronNET.API { @@ -19,29 +21,8 @@ namespace ElectronNET.API /// public event Action OnClick { - add - { - if (_click == null) - { - BridgeConnector.Socket.On("tray-click-event" + GetHashCode(), (result) => - { - var args = ((JArray)result).ToObject(); - var trayClickEventArgs = ((JObject)args[0]).ToObject(); - var bounds = ((JObject)args[1]).ToObject(); - _click(trayClickEventArgs, bounds); - }); - - BridgeConnector.Socket.Emit("register-tray-click", GetHashCode()); - } - _click += value; - } - remove - { - _click -= value; - - if (_click == null) - BridgeConnector.Socket.Off("tray-click-event" + GetHashCode()); - } + add => ApiEventManager.AddTrayEvent("tray-click", GetHashCode(), _click, value); + remove => ApiEventManager.RemoveTrayEvent("tray-click", GetHashCode(), _click, value); } private event Action _click; @@ -51,29 +32,8 @@ namespace ElectronNET.API /// public event Action OnRightClick { - add - { - if (_rightClick == null) - { - BridgeConnector.Socket.On("tray-right-click-event" + GetHashCode(), (result) => - { - var args = ((JArray)result).ToObject(); - var trayClickEventArgs = ((JObject)args[0]).ToObject(); - var bounds = ((JObject)args[1]).ToObject(); - _rightClick(trayClickEventArgs, bounds); - }); - - BridgeConnector.Socket.Emit("register-tray-right-click", GetHashCode()); - } - _rightClick += value; - } - remove - { - _rightClick -= value; - - if (_rightClick == null) - BridgeConnector.Socket.Off("tray-right-click-event" + GetHashCode()); - } + add => ApiEventManager.AddTrayEvent("tray-right-click", GetHashCode(), _rightClick, value); + remove => ApiEventManager.RemoveTrayEvent("tray-right-click", GetHashCode(), _rightClick, value); } private event Action _rightClick; @@ -83,29 +43,8 @@ namespace ElectronNET.API /// public event Action OnDoubleClick { - add - { - if (_doubleClick == null) - { - BridgeConnector.Socket.On("tray-double-click-event" + GetHashCode(), (result) => - { - var args = ((JArray)result).ToObject(); - var trayClickEventArgs = ((JObject)args[0]).ToObject(); - var bounds = ((JObject)args[1]).ToObject(); - _doubleClick(trayClickEventArgs, bounds); - }); - - BridgeConnector.Socket.Emit("register-tray-double-click", GetHashCode()); - } - _doubleClick += value; - } - remove - { - _doubleClick -= value; - - if (_doubleClick == null) - BridgeConnector.Socket.Off("tray-double-click-event" + GetHashCode()); - } + add => ApiEventManager.AddTrayEvent("tray-double-click", GetHashCode(), _doubleClick, value); + remove => ApiEventManager.RemoveTrayEvent("tray-double-click", GetHashCode(), _doubleClick, value); } private event Action _doubleClick; @@ -115,26 +54,8 @@ namespace ElectronNET.API /// public event Action OnBalloonShow { - add - { - if (_balloonShow == null) - { - BridgeConnector.Socket.On("tray-balloon-show-event" + GetHashCode(), () => - { - _balloonShow(); - }); - - BridgeConnector.Socket.Emit("register-tray-balloon-show", GetHashCode()); - } - _balloonShow += value; - } - remove - { - _balloonShow -= value; - - if (_balloonShow == null) - BridgeConnector.Socket.Off("tray-balloon-show-event" + GetHashCode()); - } + add => ApiEventManager.AddEvent("tray-balloon-show", GetHashCode(), _balloonShow, value); + remove => ApiEventManager.RemoveEvent("tray-balloon-show", GetHashCode(), _balloonShow, value); } private event Action _balloonShow; @@ -144,26 +65,8 @@ namespace ElectronNET.API /// public event Action OnBalloonClick { - add - { - if (_balloonClick == null) - { - BridgeConnector.Socket.On("tray-balloon-click-event" + GetHashCode(), () => - { - _balloonClick(); - }); - - BridgeConnector.Socket.Emit("register-tray-balloon-click", GetHashCode()); - } - _balloonClick += value; - } - remove - { - _balloonClick -= value; - - if (_balloonClick == null) - BridgeConnector.Socket.Off("tray-balloon-click-event" + GetHashCode()); - } + add => ApiEventManager.AddEvent("tray-balloon-click", GetHashCode(), _balloonClick, value); + remove => ApiEventManager.RemoveEvent("tray-balloon-click", GetHashCode(), _balloonClick, value); } private event Action _balloonClick; @@ -174,26 +77,8 @@ namespace ElectronNET.API /// public event Action OnBalloonClosed { - add - { - if (_balloonClosed == null) - { - BridgeConnector.Socket.On("tray-balloon-closed-event" + GetHashCode(), () => - { - _balloonClosed(); - }); - - BridgeConnector.Socket.Emit("register-tray-balloon-closed", GetHashCode()); - } - _balloonClosed += value; - } - remove - { - _balloonClosed -= value; - - if (_balloonClosed == null) - BridgeConnector.Socket.Off("tray-balloon-closed-event" + GetHashCode()); - } + add => ApiEventManager.AddEvent("tray-balloon-closed", GetHashCode(), _balloonClosed, value); + remove => ApiEventManager.RemoveEvent("tray-balloon-closed", GetHashCode(), _balloonClosed, value); } private event Action _balloonClosed; diff --git a/src/ElectronNET.API/Common/ApiEventManager.cs b/src/ElectronNET.API/Common/ApiEventManager.cs new file mode 100644 index 0000000..687d141 --- /dev/null +++ b/src/ElectronNET.API/Common/ApiEventManager.cs @@ -0,0 +1,82 @@ +using System; +using ElectronNET.API; +using ElectronNET.API.Entities; +using Newtonsoft.Json.Linq; + +namespace ElectronNET.Common; + +internal class ApiEventManager +{ + internal T Deserialize(Func action) + { + return action.Invoke(); + } + + internal static void AddEvent(string eventName, object id, Action callback, Action value, string suffix = "") + { + if (callback == null) + { + BridgeConnector.Socket.On(eventName + id, () => { callback(); }); + BridgeConnector.Socket.Emit($"register-{eventName}{suffix}", id); + } + callback += value; + } + + internal static void AddEventWithSuffix(string eventName, object id, Action callback, Action value) + { + AddEvent(eventName, id, callback, value, "-event"); + } + + internal static void AddEvent(string eventName, object id, Action callback, Action value, Func converter, string suffix = "") + { + if (callback == null) + { + BridgeConnector.Socket.On(eventName + id, (args) => + { + var converted = converter.Invoke(args); + callback(converted); + }); + BridgeConnector.Socket.Emit($"register-{eventName}{suffix}", id); + } + callback += value; + } + + internal static void AddEventWithSuffix(string eventName, object id, Action callback, Action value, Func converter) + { + AddEvent(eventName, id, callback, value, converter, "-event"); + } + + internal static void AddTrayEvent(string eventName, object id, Action callback, Action value) + { + if (callback == null) + { + BridgeConnector.Socket.On(eventName + id, (result) => + { + var args = ((JArray)result).ToObject(); + var trayClickEventArgs = ((JObject)args[0]).ToObject(); + var bounds = ((JObject)args[1]).ToObject(); + callback(trayClickEventArgs, bounds); + }); + BridgeConnector.Socket.Emit($"register-{eventName}", id); + callback += value; + } + } + + internal static void RemoveEvent(string eventName, object id, Action callback, Action value) + { + callback -= value; + if (callback == null) BridgeConnector.Socket.Off(eventName + id); + } + + internal static void RemoveEvent(string eventName, object id, Action callback, Action value) + { + callback -= value; + if (callback == null) BridgeConnector.Socket.Off(eventName + id); + } + + internal static void RemoveTrayEvent(string eventName, object id, Action callback, Action value) + { + callback -= value; + if (callback == null) BridgeConnector.Socket.Off(eventName + id); + } +} \ No newline at end of file diff --git a/src/ElectronNET.Host/api/tray.js b/src/ElectronNET.Host/api/tray.js index 98fb740..103acfb 100644 --- a/src/ElectronNET.Host/api/tray.js +++ b/src/ElectronNET.Host/api/tray.js @@ -7,42 +7,42 @@ module.exports = (socket) => { socket.on('register-tray-click', (id) => { if (tray.value) { tray.value.on('click', (event, bounds) => { - electronSocket.emit('tray-click-event' + id, [event.__proto__, bounds]); + electronSocket.emit('tray-click' + id, [event.__proto__, bounds]); }); } }); socket.on('register-tray-right-click', (id) => { if (tray.value) { tray.value.on('right-click', (event, bounds) => { - electronSocket.emit('tray-right-click-event' + id, [event.__proto__, bounds]); + electronSocket.emit('tray-right-click' + id, [event.__proto__, bounds]); }); } }); socket.on('register-tray-double-click', (id) => { if (tray.value) { tray.value.on('double-click', (event, bounds) => { - electronSocket.emit('tray-double-click-event' + id, [event.__proto__, bounds]); + electronSocket.emit('tray-double-click' + id, [event.__proto__, bounds]); }); } }); socket.on('register-tray-balloon-show', (id) => { if (tray.value) { tray.value.on('balloon-show', () => { - electronSocket.emit('tray-balloon-show-event' + id); + electronSocket.emit('tray-balloon-show' + id); }); } }); socket.on('register-tray-balloon-click', (id) => { if (tray.value) { tray.value.on('balloon-click', () => { - electronSocket.emit('tray-balloon-click-event' + id); + electronSocket.emit('tray-balloon-click' + id); }); } }); socket.on('register-tray-balloon-closed', (id) => { if (tray.value) { tray.value.on('balloon-closed', () => { - electronSocket.emit('tray-balloon-closed-event' + id); + electronSocket.emit('tray-balloon-closed' + id); }); } }); diff --git a/src/ElectronNET.Host/api/tray.js.map b/src/ElectronNET.Host/api/tray.js.map index 8328f0d..8d6584b 100644 --- a/src/ElectronNET.Host/api/tray.js.map +++ b/src/ElectronNET.Host/api/tray.js.map @@ -1 +1 @@ -{"version":3,"file":"tray.js","sourceRoot":"","sources":["tray.ts"],"names":[],"mappings":";AACA,uCAAmD;AACnD,IAAI,IAAI,GAA6B,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3F,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,EAAE;IACxB,cAAc,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,qBAAqB,EAAE,CAAC,EAAE,EAAE,EAAE;QACpC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,IAAI,C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AAG,CAAC,EAAE,CAAC;gBAChD,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC5D,CAAC;YAED,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;gBAC1B,IAAI,CAAC,KAAK,GAAG,GAAG,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9C,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;AACL,CAAC,CAAC"} \ No newline at end of file diff --git a/src/ElectronNET.Host/api/tray.ts b/src/ElectronNET.Host/api/tray.ts index 55a0f12..1481f9a 100644 --- a/src/ElectronNET.Host/api/tray.ts +++ b/src/ElectronNET.Host/api/tray.ts @@ -8,7 +8,7 @@ export = (socket: Socket) => { socket.on('register-tray-click', (id) => { if (tray.value) { tray.value.on('click', (event, bounds) => { - electronSocket.emit('tray-click-event' + id, [(event).__proto__, bounds]); + electronSocket.emit('tray-click' + id, [(event).__proto__, bounds]); }); } }); @@ -16,7 +16,7 @@ export = (socket: Socket) => { socket.on('register-tray-right-click', (id) => { if (tray.value) { tray.value.on('right-click', (event, bounds) => { - electronSocket.emit('tray-right-click-event' + id, [(event).__proto__, bounds]); + electronSocket.emit('tray-right-click' + id, [(event).__proto__, bounds]); }); } }); @@ -24,7 +24,7 @@ export = (socket: Socket) => { socket.on('register-tray-double-click', (id) => { if (tray.value) { tray.value.on('double-click', (event, bounds) => { - electronSocket.emit('tray-double-click-event' + id, [(event).__proto__, bounds]); + electronSocket.emit('tray-double-click' + id, [(event).__proto__, bounds]); }); } }); @@ -32,7 +32,7 @@ export = (socket: Socket) => { socket.on('register-tray-balloon-show', (id) => { if (tray.value) { tray.value.on('balloon-show', () => { - electronSocket.emit('tray-balloon-show-event' + id); + electronSocket.emit('tray-balloon-show' + id); }); } }); @@ -40,7 +40,7 @@ export = (socket: Socket) => { socket.on('register-tray-balloon-click', (id) => { if (tray.value) { tray.value.on('balloon-click', () => { - electronSocket.emit('tray-balloon-click-event' + id); + electronSocket.emit('tray-balloon-click' + id); }); } }); @@ -48,7 +48,7 @@ export = (socket: Socket) => { socket.on('register-tray-balloon-closed', (id) => { if (tray.value) { tray.value.on('balloon-closed', () => { - electronSocket.emit('tray-balloon-closed-event' + id); + electronSocket.emit('tray-balloon-closed' + id); }); } });