mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-08 17:56:51 +00:00
Replace static property with resolver service
This commit is contained in:
@@ -61,8 +61,16 @@
|
||||
/// </example>
|
||||
public static IWebHostBuilder UseElectron(this IWebHostBuilder builder, string[] args, Func<Task> onAppReadyCallback)
|
||||
{
|
||||
ElectronNetRuntime.OnAppReadyCallback = onAppReadyCallback;
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
services.AddSingleton<IAppReadyCallbackResolver>(_ => new AppReadyCallbackResolver(onAppReadyCallback));
|
||||
});
|
||||
|
||||
return UseElectronCore(builder, args);
|
||||
}
|
||||
|
||||
private static IWebHostBuilder UseElectronCore(IWebHostBuilder builder, string[] args)
|
||||
{
|
||||
// no matter how this is set - let's unset to prevent Electron not starting as expected
|
||||
// e.g., VS Code sets this env variable, but this will cause `require("electron")` to not
|
||||
// work as expected, see issue #952
|
||||
|
||||
@@ -17,13 +17,15 @@
|
||||
{
|
||||
private readonly IServer server;
|
||||
private readonly AspNetLifetimeAdapter aspNetLifetimeAdapter;
|
||||
private readonly IAppReadyCallbackResolver callbackResolver;
|
||||
private readonly IElectronAuthenticationService authenticationService;
|
||||
private SocketBridgeService socketBridge;
|
||||
|
||||
protected RuntimeControllerAspNetBase(IServer server, AspNetLifetimeAdapter aspNetLifetimeAdapter, IElectronAuthenticationService authenticationService = null)
|
||||
protected RuntimeControllerAspNetBase(IServer server, AspNetLifetimeAdapter aspNetLifetimeAdapter, IAppReadyCallbackResolver callbackResolver, IElectronAuthenticationService authenticationService = null)
|
||||
{
|
||||
this.server = server;
|
||||
this.aspNetLifetimeAdapter = aspNetLifetimeAdapter;
|
||||
this.callbackResolver = callbackResolver;
|
||||
this.authenticationService = authenticationService;
|
||||
this.aspNetLifetimeAdapter.Ready += this.AspNetLifetimeAdapter_Ready;
|
||||
this.aspNetLifetimeAdapter.Stopping += this.AspNetLifetimeAdapter_Stopping;
|
||||
@@ -130,15 +132,15 @@
|
||||
|
||||
private async Task RunReadyCallback()
|
||||
{
|
||||
if (ElectronNetRuntime.OnAppReadyCallback == null)
|
||||
if (!callbackResolver.HasCallback)
|
||||
{
|
||||
Console.WriteLine("Warning: Non OnReadyCallback provided in UseElectron() setup.");
|
||||
Console.WriteLine("Warning: No OnReadyCallback provided in UseElectron() setup.");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await ElectronNetRuntime.OnAppReadyCallback().ConfigureAwait(false);
|
||||
await callbackResolver.Invoke().ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
{
|
||||
private ElectronProcessBase electronProcess;
|
||||
|
||||
public RuntimeControllerAspNetDotnetFirst(IServer server, AspNetLifetimeAdapter aspNetLifetimeAdapter, IElectronAuthenticationService authenticationService = null) : base(server, aspNetLifetimeAdapter, authenticationService)
|
||||
public RuntimeControllerAspNetDotnetFirst(IServer server, AspNetLifetimeAdapter aspNetLifetimeAdapter, IAppReadyCallbackResolver callbackResolver, IElectronAuthenticationService authenticationService = null) : base(server, aspNetLifetimeAdapter, callbackResolver, authenticationService)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
{
|
||||
private ElectronProcessBase electronProcess;
|
||||
|
||||
public RuntimeControllerAspNetElectronFirst(IServer server, AspNetLifetimeAdapter aspNetLifetimeAdapter, IElectronAuthenticationService authenticationService = null) : base(server, aspNetLifetimeAdapter, authenticationService)
|
||||
public RuntimeControllerAspNetElectronFirst(IServer server, AspNetLifetimeAdapter aspNetLifetimeAdapter, IAppReadyCallbackResolver callbackResolver, IElectronAuthenticationService authenticationService = null) : base(server, aspNetLifetimeAdapter, callbackResolver, authenticationService)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user