Skip to content

Commit 7fe3f9b

Browse files
authored
Merge pull request #1093 from ElectronNET/develop
Release 0.5.2
2 parents 18944fe + 16cbc5f commit 7fe3f9b

36 files changed

Lines changed: 940 additions & 170 deletions

Changelog.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# 0.5.2
2+
3+
## ElectronNET.Core
4+
5+
- Fixed token param being appended to external URLs (#1075)
6+
- Fixed startup mode discriminator in case of existing `wwwroot` (#1050)
7+
- Fixed CA1416 on ASP.NET project (#1091) @epsnm
8+
- Fixed loading issue in plain Visual Studio (#1084) @epsnm
9+
- Fixed bloated ASAR file (#1080) @epsnm
10+
- Improved selection of runtime identifier (#1081) @epsnm
11+
- Added more variants for `UseElectron` (#1076) @AeonSake
12+
- Added support for modern MacOS app icon (#1047)
13+
114
# 0.5.1
215

316
## ElectronNET.Core

Directory.Packages.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
4+
<!-- This file prevents unintended imports of unrelated MSBuild files -->
5+
<!-- Uncomment to include parent Directory.Packages.props file -->
6+
<!--<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Packages.props', '$(MSBuildThisFileDirectory)../'))" />-->
7+
8+
</Project>

docs/GettingStarted/Console-App.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Add the Electron.NET configuration to your `.csproj` file:
5454
</PropertyGroup>
5555

5656
<ItemGroup>
57-
<PackageReference Include="ElectronNET.Core" Version="0.5.0" />
57+
<PackageReference Include="ElectronNET.Core" Version="0.5.2" />
5858
</ItemGroup>
5959
```
6060

docs/Using/Configuration.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ Since electron builder still expects a `package.json` file to exist, ElectronNET
7070
}
7171
```
7272

73+
### App Icon Path
74+
75+
The `ElectronIcon` property supports classic icon files (such as `.ico` and `.icns`) and modern macOS `.icon` app icon packages.
76+
77+
For `.icon`, provide the folder path (for example `Assets/MyApp.icon`). During build/publish, Electron.NET copies the full directory into the Electron output so `electron-builder.json` can reference it (for example `"mac": { "icon": "MyApp.icon" }`).
78+
7379
### Node.js Integration
7480

7581
Electron.NET requires Node.js integration to be enabled for IPC to function. If you are not using the IPC functionality you can disable Node.js integration like so:

src/ElectronNET.API/API/WindowManager.cs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public sealed class WindowManager
1919

2020
internal WindowManager()
2121
{
22+
EnsureBrowserWindowClosedSubscription();
2223
}
2324

2425
internal static WindowManager Instance
@@ -106,17 +107,6 @@ public async Task<BrowserWindow> CreateWindowAsync(BrowserWindowOptions options,
106107
tcs.SetResult(browserWindow);
107108
});
108109

109-
BridgeConnector.Socket.Once<int[]>("BrowserWindowClosed", (ids) =>
110-
{
111-
for (int index = 0; index < _browserWindows.Count; index++)
112-
{
113-
if (!ids.Contains(_browserWindows[index].Id))
114-
{
115-
_browserWindows.RemoveAt(index);
116-
}
117-
}
118-
});
119-
120110
if (loadUrl.Equals("http://localhost", StringComparison.OrdinalIgnoreCase) && ElectronNetRuntime.AspNetWebPort.HasValue)
121111
{
122112
loadUrl = $"{loadUrl}:{ElectronNetRuntime.AspNetWebPort}";
@@ -149,6 +139,40 @@ public async Task<BrowserWindow> CreateWindowAsync(BrowserWindowOptions options,
149139
return await tcs.Task.ConfigureAwait(false);
150140
}
151141

142+
private readonly object _browserWindowSubscriptionSync = new();
143+
private bool _browserWindowClosedSubscribed;
144+
145+
private void EnsureBrowserWindowClosedSubscription()
146+
{
147+
if (_browserWindowClosedSubscribed)
148+
{
149+
return;
150+
}
151+
152+
lock (_browserWindowSubscriptionSync)
153+
{
154+
if (_browserWindowClosedSubscribed)
155+
{
156+
return;
157+
}
158+
159+
BridgeConnector.Socket.On<int[]>("BrowserWindowClosed", HandleBrowserWindowClosed);
160+
_browserWindowClosedSubscribed = true;
161+
}
162+
}
163+
164+
private void HandleBrowserWindowClosed(int[] ids)
165+
{
166+
if (ids == null || ids.Length == 0)
167+
{
168+
_browserWindows.Clear();
169+
return;
170+
}
171+
172+
var existingIds = ids.ToHashSet();
173+
_browserWindows.RemoveAll(window => !existingIds.Contains(window.Id));
174+
}
175+
152176
private bool IsWindows10()
153177
{
154178
return RuntimeInformation.OSDescription.Contains("Windows 10");

src/ElectronNET.API/ElectronNetRuntime.cs

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

5151
internal static int? ElectronProcessId { get; set; }
5252

53-
internal static Func<Task> OnAppReadyCallback { get; set; }
54-
5553
internal static ISocketConnection GetSocket()
5654
{
5755
return RuntimeControllerCore?.Socket;

src/ElectronNET.AspNet/API/WebApplicationBuilderExtensions.cs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,98 @@ public static WebApplicationBuilder UseElectron(this WebApplicationBuilder build
4444

4545
return builder;
4646
}
47+
48+
/// <summary>
49+
/// Adds Electron.NET support to the current ASP.NET Core application and registers an application-ready callback.
50+
/// </summary>
51+
/// <param name="builder">The <see cref="WebApplicationBuilder"/> to extend.</param>
52+
/// <param name="args">The command-line arguments passed to the process, forwarded to Electron.</param>
53+
/// <param name="onAppReadyCallback">
54+
/// An asynchronous callback invoked when the Electron app is ready. Use this to create windows or perform initialization.
55+
/// </param>
56+
/// <returns>
57+
/// The same <see cref="WebApplicationBuilder"/> instance to enable fluent configuration.
58+
/// </returns>
59+
/// <example>
60+
/// <code language="csharp">
61+
/// var builder = WebApplication.CreateBuilder(args)
62+
/// .UseElectron(args, async (processArgs) =>
63+
/// {
64+
/// // Create the main browser window or perform other startup tasks.
65+
/// });
66+
///
67+
/// var app = builder.Build();
68+
/// app.MapRazorPages();
69+
/// app.Run();
70+
/// </code>
71+
/// </example>
72+
public static WebApplicationBuilder UseElectron(this WebApplicationBuilder builder, string[] args, Func<string[], Task> onAppReadyCallback)
73+
{
74+
builder.WebHost.UseElectron(args, onAppReadyCallback);
75+
76+
return builder;
77+
}
78+
79+
/// <summary>
80+
/// Adds Electron.NET support to the current ASP.NET Core application and registers an application-ready callback.
81+
/// </summary>
82+
/// <param name="builder">The <see cref="WebApplicationBuilder"/> to extend.</param>
83+
/// <param name="args">The command-line arguments passed to the process, forwarded to Electron.</param>
84+
/// <param name="onAppReadyCallback">
85+
/// An asynchronous callback invoked when the Electron app is ready. Use this to create windows or perform initialization.
86+
/// </param>
87+
/// <returns>
88+
/// The same <see cref="WebApplicationBuilder"/> instance to enable fluent configuration.
89+
/// </returns>
90+
/// <example>
91+
/// <code language="csharp">
92+
/// var builder = WebApplication.CreateBuilder(args)
93+
/// .UseElectron(args, async (serviceProvider) =>
94+
/// {
95+
/// // Create the main browser window or perform other startup tasks.
96+
/// });
97+
///
98+
/// var app = builder.Build();
99+
/// app.MapRazorPages();
100+
/// app.Run();
101+
/// </code>
102+
/// </example>
103+
public static WebApplicationBuilder UseElectron(this WebApplicationBuilder builder, string[] args, Func<IServiceProvider, Task> onAppReadyCallback)
104+
{
105+
builder.WebHost.UseElectron(args, onAppReadyCallback);
106+
107+
return builder;
108+
}
109+
110+
/// <summary>
111+
/// Adds Electron.NET support to the current ASP.NET Core application and registers an application-ready callback.
112+
/// </summary>
113+
/// <param name="builder">The <see cref="WebApplicationBuilder"/> to extend.</param>
114+
/// <param name="args">The command-line arguments passed to the process, forwarded to Electron.</param>
115+
/// <param name="onAppReadyCallback">
116+
/// An asynchronous callback invoked when the Electron app is ready. Use this to create windows or perform initialization.
117+
/// </param>
118+
/// <returns>
119+
/// The same <see cref="WebApplicationBuilder"/> instance to enable fluent configuration.
120+
/// </returns>
121+
/// <example>
122+
/// <code language="csharp">
123+
/// var builder = WebApplication.CreateBuilder(args)
124+
/// .UseElectron(args, async (serviceProvider, processArgs) =>
125+
/// {
126+
/// // Create the main browser window or perform other startup tasks.
127+
/// });
128+
///
129+
/// var app = builder.Build();
130+
/// app.MapRazorPages();
131+
/// app.Run();
132+
/// </code>
133+
/// </example>
134+
public static WebApplicationBuilder UseElectron(this WebApplicationBuilder builder, string[] args, Func<IServiceProvider, string[], Task> onAppReadyCallback)
135+
{
136+
builder.WebHost.UseElectron(args, onAppReadyCallback);
137+
138+
return builder;
139+
}
47140
}
48141
}

0 commit comments

Comments
 (0)