diff --git a/ElectronNET.API/App.cs b/ElectronNET.API/App.cs index b14ccb8..f48976d 100644 --- a/ElectronNET.API/App.cs +++ b/ElectronNET.API/App.cs @@ -6,6 +6,7 @@ using System; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Hosting; namespace ElectronNET.API { @@ -352,6 +353,11 @@ namespace ElectronNET.API private event Action _accessibilitySupportChanged; + /// + /// Application host fully started. + /// + public bool IsReady { get; internal set; } + /// /// A property that indicates the current application's name, which is the /// name in the application's `package.json` file. diff --git a/ElectronNET.API/LifetimeServiceHost.cs b/ElectronNET.API/LifetimeServiceHost.cs new file mode 100644 index 0000000..cb58eb1 --- /dev/null +++ b/ElectronNET.API/LifetimeServiceHost.cs @@ -0,0 +1,41 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Hosting; + +namespace ElectronNET.API +{ + /// + /// Base class that reports if ASP.NET Core has fully started. + /// + internal class LifetimeServiceHost : IHostedService + { + public LifetimeServiceHost(IHostApplicationLifetime lifetime) + { + lifetime.ApplicationStarted.Register(() => + { + App.Instance.IsReady = true; + + Console.WriteLine("ASP.NET Core host has fully started."); + }); + } + + /// + /// Triggered when the application host is ready to start the service. + /// + /// Indicates that the start process has been aborted. + public Task StartAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + /// + /// Triggered when the application host is performing a graceful shutdown. + /// + /// Indicates that the shutdown process should no longer be graceful. + public Task StopAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/ElectronNET.API/WebHostBuilderExtensions.cs b/ElectronNET.API/WebHostBuilderExtensions.cs index 8680cf6..af7cf91 100644 --- a/ElectronNET.API/WebHostBuilderExtensions.cs +++ b/ElectronNET.API/WebHostBuilderExtensions.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Hosting; using System; using System.IO; +using Microsoft.Extensions.DependencyInjection; namespace ElectronNET.API { @@ -32,6 +33,11 @@ namespace ElectronNET.API if (HybridSupport.IsElectronActive) { + builder.ConfigureServices(services => + { + services.AddHostedService(); + }); + // check for the content folder if its exists in base director otherwise no need to include // It was used before because we are publishing the project which copies everything to bin folder and contentroot wwwroot was folder there. // now we have implemented the live reload if app is run using /watch then we need to use the default project path. @@ -49,4 +55,4 @@ namespace ElectronNET.API return builder; } } -} +} \ No newline at end of file diff --git a/ElectronNET.WebApp/Startup.cs b/ElectronNET.WebApp/Startup.cs index 863b7b6..f6131b3 100644 --- a/ElectronNET.WebApp/Startup.cs +++ b/ElectronNET.WebApp/Startup.cs @@ -4,7 +4,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Hosting; namespace ElectronNET.WebApp