From 39c3e921283313a878c66bbe45ba699b8a9226ed Mon Sep 17 00:00:00 2001 From: Gregor Biswanger Date: Sun, 24 May 2020 22:00:32 +0200 Subject: [PATCH] implement lazy App.Ready event --- ElectronNET.API/App.cs | 21 +++++++++++++++++-- .../Controllers/MenusController.cs | 9 +------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ElectronNET.API/App.cs b/ElectronNET.API/App.cs index f87344a..9f4c717 100644 --- a/ElectronNET.API/App.cs +++ b/ElectronNET.API/App.cs @@ -356,7 +356,24 @@ namespace ElectronNET.API /// /// Emitted when the application has finished basic startup. /// - public event Action Ready; + public event Action Ready + { + add + { + if(IsReady) + { + value(); + } + + _ready += value; + } + remove + { + _ready -= value; + } + } + + private event Action _ready; /// /// Application host fully started. @@ -370,7 +387,7 @@ namespace ElectronNET.API if(value) { - Ready?.Invoke(); + _ready?.Invoke(); } } } diff --git a/ElectronNET.WebApp/Controllers/MenusController.cs b/ElectronNET.WebApp/Controllers/MenusController.cs index 8add209..a279774 100644 --- a/ElectronNET.WebApp/Controllers/MenusController.cs +++ b/ElectronNET.WebApp/Controllers/MenusController.cs @@ -11,14 +11,7 @@ namespace ElectronNET.WebApp.Controllers { if (HybridSupport.IsElectronActive) { - if(Electron.App.IsReady) - { - CreateContextMenu(); - } - else - { - Electron.App.Ready += () => CreateContextMenu(); - } + Electron.App.Ready += () => CreateContextMenu(); var menu = new MenuItem[] { new MenuItem { Label = "Edit", Submenu = new MenuItem[] {