Skip to content

Commit 03c9b99

Browse files
committed
feat: added WebApplicationBuilder overload, removed Obsolete attribute, removed static OnAppReadyCallback in favor of Events.OnReady
1 parent 98b421c commit 03c9b99

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

src/ElectronNET.API/ElectronNetRuntime.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ static ElectronNetRuntime()
4747

4848
internal static int? ElectronProcessId { get; set; }
4949

50-
internal static Func<Task> OnAppReadyCallback { get; set; }
51-
5250
/// <summary>
5351
/// Global configuration options for the Electron.NET runtime, including
5452
/// lifecycle events that can be configured from the ASP.NET host builder.

src/ElectronNET.AspNet/API/WebApplicationBuilderExtensions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,18 @@ public static class WebApplicationBuilderExtensions
4040
/// </example>
4141
public static WebApplicationBuilder UseElectron(this WebApplicationBuilder builder, string[] args, Func<Task> onAppReadyCallback)
4242
{
43-
builder.WebHost.UseElectron(args, onAppReadyCallback);
43+
return UseElectron(builder, options =>
44+
{
45+
options.Events = new()
46+
{
47+
OnReady = onAppReadyCallback
48+
};
49+
});
50+
}
51+
52+
public static WebApplicationBuilder UseElectron(this WebApplicationBuilder builder, Action<ElectronNetOptions> configure)
53+
{
54+
builder.WebHost.UseElectron(configure);
4455

4556
return builder;
4657
}

src/ElectronNET.AspNet/API/WebHostBuilderExtensions.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public static class WebHostBuilderExtensions
5858
/// }
5959
/// </code>
6060
/// </example>
61-
[Obsolete("This method is deprecated. Please use the overload with the configure parameter")]
6261
public static IWebHostBuilder UseElectron(this IWebHostBuilder builder, string[] args, Func<Task> onAppReadyCallback)
6362
{
6463
if (onAppReadyCallback == null)
@@ -67,7 +66,7 @@ public static IWebHostBuilder UseElectron(this IWebHostBuilder builder, string[]
6766
}
6867

6968
// Backwards compatible overload – wraps the single callback into the new options model.
70-
return UseElectron(builder, args, options =>
69+
return UseElectron(builder, options =>
7170
{
7271
options.Events.OnReady = onAppReadyCallback;
7372
});
@@ -78,7 +77,7 @@ public static IWebHostBuilder UseElectron(this IWebHostBuilder builder, string[]
7877
/// configuration. The provided <see cref="ElectronNetOptions"/> allows registration of callbacks
7978
/// for different phases of the Electron runtime.
8079
/// </summary>
81-
public static IWebHostBuilder UseElectron(this IWebHostBuilder builder, string[] args, Action<ElectronNetOptions> configure)
80+
public static IWebHostBuilder UseElectron(this IWebHostBuilder builder, Action<ElectronNetOptions> configure)
8281
{
8382
if (configure == null)
8483
{
@@ -89,9 +88,6 @@ public static IWebHostBuilder UseElectron(this IWebHostBuilder builder, string[]
8988
configure(options);
9089
ElectronNetRuntime.Options = options;
9190

92-
// Preserve behaviour of the original API by mapping OnReady to the legacy callback.
93-
ElectronNetRuntime.OnAppReadyCallback = options.Events?.OnReady;
94-
9591
var webPort = PortHelper.GetFreePort(ElectronNetRuntime.AspNetWebPort ?? ElectronNetRuntime.DefaultWebPort);
9692
ElectronNetRuntime.AspNetWebPort = webPort;
9793

src/ElectronNET.AspNet/Runtime/Controllers/RuntimeControllerAspNetBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ private async Task RunReadyCallback()
183183
}
184184
}
185185

186-
if (ElectronNetRuntime.OnAppReadyCallback == null)
186+
if (events.OnReady == null)
187187
{
188188
Console.WriteLine("Warning: Non OnReadyCallback provided in UseElectron() setup.");
189189
return;
190190
}
191191

192192
try
193193
{
194-
await ElectronNetRuntime.OnAppReadyCallback().ConfigureAwait(false);
194+
await events.OnReady().ConfigureAwait(false);
195195
}
196196
catch (Exception ex)
197197
{

src/ElectronNET.WebApp/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args)
2020
{
2121
return WebHost.CreateDefaultBuilder(args)
2222
.ConfigureLogging((hostingContext, logging) => { logging.AddConsole(); })
23-
.UseElectron(args, ElectronBootstrap)
23+
.UseElectron(ElectronBootstrap)
2424
.UseStartup<Startup>();
2525
}
2626

0 commit comments

Comments
 (0)