77using System . Threading ;
88using System . Threading . Tasks ;
99using ElectronNET . API . Extensions ;
10- using static System . Collections . Specialized . BitVector32 ;
10+ using ElectronNET . Common ;
11+
12+ // ReSharper disable InconsistentNaming
1113
1214namespace ElectronNET . API
1315{
@@ -39,7 +41,7 @@ public event Action WindowAllClosed
3941 }
4042 } ) ;
4143
42- BridgeConnector . Socket . Emit ( "register-app-window-all-closed-event " , GetHashCode ( ) ) ;
44+ BridgeConnector . Socket . Emit ( "register-app-window-all-closed" , GetHashCode ( ) ) ;
4345 }
4446 _windowAllClosed += value ;
4547 }
@@ -111,7 +113,7 @@ public event Func<QuitEventArgs, Task> BeforeQuit
111113 }
112114 } ) ;
113115
114- BridgeConnector . Socket . Emit ( "register-app-before-quit-event " , GetHashCode ( ) ) ;
116+ BridgeConnector . Socket . Emit ( "register-app-before-quit" , GetHashCode ( ) ) ;
115117 }
116118 _beforeQuit += value ;
117119 }
@@ -162,7 +164,7 @@ public event Func<QuitEventArgs, Task> WillQuit
162164 }
163165 } ) ;
164166
165- BridgeConnector . Socket . Emit ( "register-app-will-quit-event " , GetHashCode ( ) ) ;
167+ BridgeConnector . Socket . Emit ( "register-app-will-quit" , GetHashCode ( ) ) ;
166168 }
167169 _willQuit += value ;
168170 }
@@ -197,7 +199,7 @@ public event Func<Task> Quitting
197199 }
198200 } ) ;
199201
200- BridgeConnector . Socket . Emit ( "register-app-will-quit-event " , GetHashCode ( ) + "quitting" ) ;
202+ BridgeConnector . Socket . Emit ( "register-app-will-quit" , GetHashCode ( ) + "quitting" ) ;
201203 }
202204 _quitting += value ;
203205 }
@@ -217,26 +219,8 @@ public event Func<Task> Quitting
217219 /// </summary>
218220 public event Action BrowserWindowBlur
219221 {
220- add
221- {
222- if ( _browserWindowBlur == null )
223- {
224- BridgeConnector . Socket . On ( "app-browser-window-blur" + GetHashCode ( ) , ( ) =>
225- {
226- _browserWindowBlur ( ) ;
227- } ) ;
228-
229- BridgeConnector . Socket . Emit ( "register-app-browser-window-blur-event" , GetHashCode ( ) ) ;
230- }
231- _browserWindowBlur += value ;
232- }
233- remove
234- {
235- _browserWindowBlur -= value ;
236-
237- if ( _browserWindowBlur == null )
238- BridgeConnector . Socket . Off ( "app-browser-window-blur" + GetHashCode ( ) ) ;
239- }
222+ add => ApiEventManager . AddEvent ( "app-browser-window-blur" , GetHashCode ( ) , _browserWindowBlur , value ) ;
223+ remove => ApiEventManager . RemoveEvent ( "app-browser-window-blur" , GetHashCode ( ) , _browserWindowBlur , value ) ;
240224 }
241225
242226 private event Action _browserWindowBlur ;
@@ -246,26 +230,8 @@ public event Action BrowserWindowBlur
246230 /// </summary>
247231 public event Action BrowserWindowFocus
248232 {
249- add
250- {
251- if ( _browserWindowFocus == null )
252- {
253- BridgeConnector . Socket . On ( "app-browser-window-focus" + GetHashCode ( ) , ( ) =>
254- {
255- _browserWindowFocus ( ) ;
256- } ) ;
257-
258- BridgeConnector . Socket . Emit ( "register-app-browser-window-focus-event" , GetHashCode ( ) ) ;
259- }
260- _browserWindowFocus += value ;
261- }
262- remove
263- {
264- _browserWindowFocus -= value ;
265-
266- if ( _browserWindowFocus == null )
267- BridgeConnector . Socket . Off ( "app-browser-window-focus" + GetHashCode ( ) ) ;
268- }
233+ add => ApiEventManager . AddEvent ( "app-browser-window-focus" , GetHashCode ( ) , _browserWindowFocus , value ) ;
234+ remove => ApiEventManager . RemoveEvent ( "app-browser-window-focus" , GetHashCode ( ) , _browserWindowFocus , value ) ;
269235 }
270236
271237 private event Action _browserWindowFocus ;
@@ -275,26 +241,8 @@ public event Action BrowserWindowFocus
275241 /// </summary>
276242 public event Action BrowserWindowCreated
277243 {
278- add
279- {
280- if ( _browserWindowCreated == null )
281- {
282- BridgeConnector . Socket . On ( "app-browser-window-created" + GetHashCode ( ) , ( ) =>
283- {
284- _browserWindowCreated ( ) ;
285- } ) ;
286-
287- BridgeConnector . Socket . Emit ( "register-app-browser-window-created-event" , GetHashCode ( ) ) ;
288- }
289- _browserWindowCreated += value ;
290- }
291- remove
292- {
293- _browserWindowCreated -= value ;
294-
295- if ( _browserWindowCreated == null )
296- BridgeConnector . Socket . Off ( "app-browser-window-created" + GetHashCode ( ) ) ;
297- }
244+ add => ApiEventManager . AddEvent ( "app-browser-window-created" , GetHashCode ( ) , _browserWindowCreated , value ) ;
245+ remove => ApiEventManager . RemoveEvent ( "app-browser-window-created" , GetHashCode ( ) , _browserWindowCreated , value ) ;
298246 }
299247
300248 private event Action _browserWindowCreated ;
@@ -304,26 +252,8 @@ public event Action BrowserWindowCreated
304252 /// </summary>
305253 public event Action WebContentsCreated
306254 {
307- add
308- {
309- if ( _webContentsCreated == null )
310- {
311- BridgeConnector . Socket . On ( "app-web-contents-created" + GetHashCode ( ) , ( ) =>
312- {
313- _webContentsCreated ( ) ;
314- } ) ;
315-
316- BridgeConnector . Socket . Emit ( "register-app-web-contents-created-event" , GetHashCode ( ) ) ;
317- }
318- _webContentsCreated += value ;
319- }
320- remove
321- {
322- _webContentsCreated -= value ;
323-
324- if ( _webContentsCreated == null )
325- BridgeConnector . Socket . Off ( "app-web-contents-created" + GetHashCode ( ) ) ;
326- }
255+ add => ApiEventManager . AddEvent ( "app-web-contents-created" , GetHashCode ( ) , _webContentsCreated , value ) ;
256+ remove => ApiEventManager . RemoveEvent ( "app-web-contents-created" , GetHashCode ( ) , _webContentsCreated , value ) ;
327257 }
328258
329259 private event Action _webContentsCreated ;
@@ -335,26 +265,8 @@ public event Action WebContentsCreated
335265 /// <returns><see langword="true"/> when Chrome's accessibility support is enabled, <see langword="false"/> otherwise.</returns>
336266 public event Action < bool > AccessibilitySupportChanged
337267 {
338- add
339- {
340- if ( _accessibilitySupportChanged == null )
341- {
342- BridgeConnector . Socket . On ( "app-accessibility-support-changed" + GetHashCode ( ) , ( state ) =>
343- {
344- _accessibilitySupportChanged ( ( bool ) state ) ;
345- } ) ;
346-
347- BridgeConnector . Socket . Emit ( "register-app-accessibility-support-changed-event" , GetHashCode ( ) ) ;
348- }
349- _accessibilitySupportChanged += value ;
350- }
351- remove
352- {
353- _accessibilitySupportChanged -= value ;
354-
355- if ( _accessibilitySupportChanged == null )
356- BridgeConnector . Socket . Off ( "app-accessibility-support-changed" + GetHashCode ( ) ) ;
357- }
268+ add => ApiEventManager . AddEvent ( "app-accessibility-support-changed" , GetHashCode ( ) , _accessibilitySupportChanged , value , ( args ) => ( bool ) args ) ;
269+ remove => ApiEventManager . RemoveEvent ( "app-accessibility-support-changed" , GetHashCode ( ) , _accessibilitySupportChanged , value ) ;
358270 }
359271
360272 private event Action < bool > _accessibilitySupportChanged ;
@@ -408,26 +320,8 @@ internal set
408320 /// </summary>
409321 public event Action < string > OpenFile
410322 {
411- add
412- {
413- if ( _openFile == null )
414- {
415- BridgeConnector . Socket . On ( "app-open-file" + GetHashCode ( ) , ( file ) =>
416- {
417- _openFile ( file . ToString ( ) ) ;
418- } ) ;
419-
420- BridgeConnector . Socket . Emit ( "register-app-open-file-event" , GetHashCode ( ) ) ;
421- }
422- _openFile += value ;
423- }
424- remove
425- {
426- _openFile -= value ;
427-
428- if ( _openFile == null )
429- BridgeConnector . Socket . Off ( "app-open-file" + GetHashCode ( ) ) ;
430- }
323+ add => ApiEventManager . AddEvent ( "app-open-file" , GetHashCode ( ) , _openFile , value , ( args ) => args . ToString ( ) ) ;
324+ remove => ApiEventManager . RemoveEvent ( "app-open-file" , GetHashCode ( ) , _openFile , value ) ;
431325 }
432326
433327 private event Action < string > _openFile ;
@@ -439,26 +333,8 @@ public event Action<string> OpenFile
439333 /// </summary>
440334 public event Action < string > OpenUrl
441335 {
442- add
443- {
444- if ( _openUrl == null )
445- {
446- BridgeConnector . Socket . On ( "app-open-url" + GetHashCode ( ) , ( url ) =>
447- {
448- _openUrl ( url . ToString ( ) ) ;
449- } ) ;
450-
451- BridgeConnector . Socket . Emit ( "register-app-open-url-event" , GetHashCode ( ) ) ;
452- }
453- _openUrl += value ;
454- }
455- remove
456- {
457- _openUrl -= value ;
458-
459- if ( _openUrl == null )
460- BridgeConnector . Socket . Off ( "app-open-url" + GetHashCode ( ) ) ;
461- }
336+ add => ApiEventManager . AddEvent ( "app-open-url" , GetHashCode ( ) , _openUrl , value , ( args ) => args . ToString ( ) ) ;
337+ remove => ApiEventManager . RemoveEvent ( "app-open-url" , GetHashCode ( ) , _openUrl , value ) ;
462338 }
463339
464340 private event Action < string > _openUrl ;
0 commit comments