From ab694e22fc522f2050c493d9269febcd8bbc7b69 Mon Sep 17 00:00:00 2001 From: Daniel Gidman Date: Wed, 23 Feb 2022 14:57:05 -0600 Subject: [PATCH] Change IsReady logic to also wait for connection to be open. This is to prevent actions occurring before the app can act upon them. --- ElectronNET.API/LifetimeServiceHost.cs | 9 +++++++-- ElectronNET.WebApp/Startup.cs | 7 +++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ElectronNET.API/LifetimeServiceHost.cs b/ElectronNET.API/LifetimeServiceHost.cs index cb58eb1..c99392a 100644 --- a/ElectronNET.API/LifetimeServiceHost.cs +++ b/ElectronNET.API/LifetimeServiceHost.cs @@ -2,6 +2,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Hosting; +using Quobject.SocketIoClientDotNet.Client; namespace ElectronNET.API { @@ -12,10 +13,14 @@ namespace ElectronNET.API { public LifetimeServiceHost(IHostApplicationLifetime lifetime) { - lifetime.ApplicationStarted.Register(() => + lifetime.ApplicationStarted.Register(async () => { - App.Instance.IsReady = true; + // wait till the socket is open before setting app to ready + while(BridgeConnector.Socket.Io().ReadyState != Manager.ReadyStateEnum.OPEN) { + await Task.Delay(50).ConfigureAwait(false); + } + App.Instance.IsReady = true; Console.WriteLine("ASP.NET Core host has fully started."); }); } diff --git a/ElectronNET.WebApp/Startup.cs b/ElectronNET.WebApp/Startup.cs index f6c0c33..ae9b5cc 100644 --- a/ElectronNET.WebApp/Startup.cs +++ b/ElectronNET.WebApp/Startup.cs @@ -43,7 +43,7 @@ namespace ElectronNET.WebApp if (HybridSupport.IsElectronActive) { - ElectronBootstrap(); + Electron.App.Ready += () => ElectronBootstrap(); } } @@ -55,12 +55,11 @@ namespace ElectronNET.WebApp { Width = 1152, Height = 940, - Show = false - }); + Show = true + }).ConfigureAwait(false); await browserWindow.WebContents.Session.ClearCacheAsync(); - browserWindow.OnReadyToShow += () => browserWindow.Show(); browserWindow.SetTitle(Configuration["DemoTitleInSettings"]); }