Skip to content

Commit 10bf461

Browse files
committed
Prepare for Blazor support
1 parent 5b0ab76 commit 10bf461

File tree

20 files changed

+1419
-1147
lines changed

20 files changed

+1419
-1147
lines changed

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 0.2.0
2+
3+
## ElectronNET.Core
4+
5+
- Added `IsRunningBlazor` option to `BrowserWindowOptions` (#926)
6+
17
# 0.1.0
28

39
## ElectronNET.Core

README.md

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,22 @@ To do so, use the `UseElectron` extension method on a `WebApplicationBuilder`, a
5858
using ElectronNET.API;
5959
using ElectronNET.API.Entities;
6060

61-
public static void Main(string[] args)
62-
{
63-
WebHost.CreateDefaultBuilder(args)
64-
.UseElectron(args, ElectronAppReady)
65-
.UseStartup<Startup>()
66-
.Build()
67-
.Run();
68-
}
69-
70-
public static async Task ElectronAppReady()
71-
{
72-
var browserWindow = await Electron.WindowManager.CreateWindowAsync(
73-
new BrowserWindowOptions { Show = false });
74-
75-
browserWindow.OnReadyToShow += () => browserWindow.Show();
76-
}
61+
public static void Main(string[] args)
62+
{
63+
WebHost.CreateDefaultBuilder(args)
64+
.UseElectron(args, ElectronAppReady)
65+
.UseStartup<Startup>()
66+
.Build()
67+
.Run();
68+
}
69+
70+
public static async Task ElectronAppReady()
71+
{
72+
var browserWindow = await Electron.WindowManager.CreateWindowAsync(
73+
new BrowserWindowOptions { Show = false });
74+
75+
browserWindow.OnReadyToShow += () => browserWindow.Show();
76+
}
7777
```
7878

7979
### Minimal API Example
@@ -113,6 +113,56 @@ app.MapRazorPages();
113113
app.Run();
114114
```
115115

116+
### Blazor
117+
118+
For a project with Blazor you can use:
119+
120+
```cs
121+
using ElectronNET.API;
122+
using ElectronNET.API.Entities;
123+
124+
var builder = WebApplication.CreateBuilder(args);
125+
126+
builder.Services
127+
.AddRazorComponents()
128+
.AddInteractiveWebAssemblyComponents();
129+
130+
builder.Services.AddElectron(); // <-- might be useful to set up DI
131+
132+
builder.UseElectron(args, async () =>
133+
{
134+
var options = new BrowserWindowOptions {
135+
Show = false,
136+
AutoHideMenuBar = true,
137+
IsRunningBlazor = true, // <-- crucial
138+
};
139+
var browserWindow = await Electron.WindowManager.CreateWindowAsync(options);
140+
browserWindow.OnReadyToShow += () => browserWindow.Show();
141+
});
142+
143+
var app = builder.Build();
144+
145+
// Configure the HTTP request pipeline.
146+
if (app.Environment.IsDevelopment())
147+
{
148+
app.UseWebAssemblyDebugging();
149+
}
150+
else
151+
{
152+
app.UseExceptionHandler("/Error", createScopeForErrors: true);
153+
}
154+
155+
app.UseStaticFiles();
156+
app.UseAntiforgery();
157+
158+
app.MapRazorComponents<BlazorApp.Components.App>()
159+
.AddInteractiveWebAssemblyRenderMode();
160+
161+
app.Run();
162+
```
163+
164+
The `IsRunningBlazor` option makes sure to set up the renderer in a way that Blazor can just run without any interference. This includes things such as HMR for development.
165+
116166
## 🚀 Starting and Debugging the Application
117167

118168
Just press `F5` in Visual Studio or use dotnet for debugging.

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.1.0" />
57+
<PackageReference Include="ElectronNET.Core" Version="0.2.0" />
5858
</ItemGroup>
5959
```
6060

src/ElectronNET.API/API/Entities/BrowserWindowOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ public class BrowserWindowOptions
126126
/// </summary>
127127
public bool SkipTaskbar { get; set; }
128128

129+
/// <summary>
130+
/// Determines if Blazor is used. Will disable "module" and "process" globals. Default is false.
131+
/// </summary>
132+
public bool IsRunningBlazor { get; set; }
133+
129134
/// <summary>
130135
/// The kiosk mode. Default is false.
131136
/// </summary>

src/ElectronNET.ConsoleApp/ElectronNET.ConsoleApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<ProjectReference Include="..\ElectronNET.API\ElectronNET.API.csproj" Condition="$(ElectronNetDevMode)" />
7070
</ItemGroup>
7171
<ItemGroup>
72-
<PackageReference Include="ElectronNET.Core" Version="0.1.0" Condition="'$(ElectronNetDevMode)' != 'true'" />
72+
<PackageReference Include="ElectronNET.Core" Version="0.2.0" Condition="'$(ElectronNetDevMode)' != 'true'" />
7373
</ItemGroup>
7474

7575
<Import Project="..\ElectronNET\build\ElectronNET.targets" Condition="$(ElectronNetDevMode)" />

src/ElectronNET.Host/api/autoUpdater.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ElectronNET.Host/api/browserView.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)