Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 52 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@

| Requirement | Version |
|---|---|
| .NET SDK | 8.0 or later |
| .NET SDK | 8.0 or later (the example projects target `net10.0`) |
| Node.js | 22.x or later (must be available in `PATH`) |
| XAF Blazor Server application | Created with the [Template Kit](https://docs.devexpress.com/eXpressAppFramework/405447/installation-upgrade-version-history/visual-studio-integration/template-kit) |

To check the installed Node.js version, run the following command:

```powershell
```shell
node --version
```

> [!NOTE]
> The example solution uses SQL Server LocalDB, which is available on Windows only. To run the example on macOS, see [Run the Example on macOS](#run-the-example-on-macos).

## Step 1. Add NuGet Packages

Check warning on line 31 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L31

[DX.HeadingPunctuation] Don't use end punctuation at the end of headings.
Raw output
{"message": "[DX.HeadingPunctuation] Don't use end punctuation at the end of headings.", "location": {"path": "README.md", "range": {"start": {"line": 31, "column": 4}}}, "severity": "WARNING"}

Add the following packages to the *YourApplicationName.Blazor.Server* project:

```powershell
```shell
dotnet add package ElectronNET.Core
dotnet add package ElectronNET.Core.AspNet
```
Expand All @@ -44,7 +47,7 @@
> [!NOTE]
> ElectronNET.Core does not require the legacy `electronize` CLI tool or the `electron.manifest.json` file. The library configures the Electron host through MSBuild.

## Step 2. Register Electron in the Application Builder

Check warning on line 50 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L50

[DX.HeadingPunctuation] Don't use end punctuation at the end of headings.
Raw output
{"message": "[DX.HeadingPunctuation] Don't use end punctuation at the end of headings.", "location": {"path": "README.md", "range": {"start": {"line": 50, "column": 4}}}, "severity": "WARNING"}

Open the *YourApplicationName.Blazor.Server/Program.cs* file and add the following namespaces:

Expand Down Expand Up @@ -87,7 +90,7 @@
- `Show = false` in combination with the `OnReadyToShow` event handler prevents an empty window from being displayed while the XAF application loads.
- The `USE_ELECTRON` check keeps the default browser hosting unchanged. Do not call `UseElectron` if the setting is not specified.

## Step 3. Resolve the App Component Name Conflict

Check warning on line 93 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L93

[DX.HeadingPunctuation] Don't use end punctuation at the end of headings.
Raw output
{"message": "[DX.HeadingPunctuation] Don't use end punctuation at the end of headings.", "location": {"path": "README.md", "range": {"start": {"line": 93, "column": 4}}}, "severity": "WARNING"}

The `ElectronNET.API` namespace contains an `App` type. After you add the `using ElectronNET.API;` directive, the `App` identifier conflicts with the Blazor root component and the build fails with the [CS0104](https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0104) error.

Expand All @@ -103,7 +106,7 @@

### Disable HTTPS Redirection in Electron Mode

logs the "Failed to determine the https port for redirect" warning.
In Electron mode, the application listens on HTTP only. If you call `UseHttpsRedirection`, the middleware cannot determine the HTTPS port and logs the "Failed to determine the https port for redirect" warning. Call `UseHttpsRedirection` only if the application does not run in Electron mode:

```csharp
if (!useElectron) {
Expand All @@ -113,7 +116,7 @@

Traffic between the Electron window and Kestrel does not leave the local machine, so HTTPS is not required. `UseHsts` does not need changes: the HSTS middleware ignores `localhost` by default.

## Step 4. Add an Electron Launch Profile

Check warning on line 119 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L119

[DX.HeadingPunctuation] Don't use end punctuation at the end of headings.
Raw output
{"message": "[DX.HeadingPunctuation] Don't use end punctuation at the end of headings.", "location": {"path": "README.md", "range": {"start": {"line": 119, "column": 4}}}, "severity": "WARNING"}

Open the *YourApplicationName.Blazor.Server/Properties/launchSettings.json* file and add a profile that sets the `USE_ELECTRON` environment variable and disables browser launch:

Expand All @@ -130,20 +133,25 @@
}
```

## Step 5. Run the Application

Check warning on line 136 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L136

[DX.HeadingPunctuation] Don't use end punctuation at the end of headings.
Raw output
{"message": "[DX.HeadingPunctuation] Don't use end punctuation at the end of headings.", "location": {"path": "README.md", "range": {"start": {"line": 136, "column": 4}}}, "severity": "WARNING"}

1. If your solution uses the [Middle Tier Security](https://docs.devexpress.com/eXpressAppFramework/404389/data-security-and-safety/security-system/security-tiers/middle-tier-security), start the *YourApplicationName.MiddleTierWebApi* project first.
1. If your solution uses the [Middle Tier Security](https://docs.devexpress.com/eXpressAppFramework/404389/data-security-and-safety/security-system/security-tiers/middle-tier-security), start the *YourApplicationName.MiddleTierWebApi* project first. In the example solution, run the following command in the *ElectronExample.MiddleTier* folder:

```shell
dotnet run --launch-profile ElectronExample.MiddleTier
```

2. Run the *YourApplicationName.Blazor.Server* project with the **Electron** launch profile:
- In Visual Studio, select the **Electron** profile and press **F5**.
- In the command line, run `dotnet run --launch-profile Electron`.
- In Visual Studio or JetBrains Rider, select the **Electron** profile and start the project.
- In the command line, run `dotnet run --launch-profile Electron` in the project folder.
3. The first run restores and installs Electron npm packages, so it takes longer than subsequent runs.
4. A desktop window opens and displays the XAF application's logon page.

To run the application in a browser, use any other launch profile. The application then behaves as a standard XAF Blazor application.

## Step 6. (Optional) Use Native Electron APIs from XAF Actions

Check warning on line 152 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L152

[DX.HeadingPunctuation] Don't use end punctuation at the end of headings.
Raw output
{"message": "[DX.HeadingPunctuation] Don't use end punctuation at the end of headings.", "location": {"path": "README.md", "range": {"start": {"line": 152, "column": 4}}}, "severity": "WARNING"}

In this setup, the XAF Blazor application and the Electron shell run on the same machine. The .NET process hosts the Kestrel server, and Electron displays it in a native window. This allows XAF Controllers to call the Electron.NET API (the static `Electron` class) and access native OS features that a regular browser cannot reach: message boxes, file dialogs, notifications, the system tray, the clipboard, and so on.

Check failure on line 154 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L154

[DX.SentenceStart] Do not start a sentence with a 'This allows'. It sounds vague.
Raw output
{"message": "[DX.SentenceStart] Do not start a sentence with a 'This allows'. It sounds vague.", "location": {"path": "README.md", "range": {"start": {"line": 154, "column": 179}}}, "severity": "ERROR"}

How it works:

Expand Down Expand Up @@ -235,6 +243,43 @@
| `Electron.Shell.OpenExternalAsync` | Open a URL in the default browser. |
| `Electron.Menu.SetApplicationMenu` | A native application menu. |

## Run the Example on macOS

The example solution runs on macOS (tested on Apple silicon) with the following changes.

### Use SQLite Instead of LocalDB

The *ElectronExample.MiddleTier/appsettings.json* file specifies a SQL Server LocalDB connection string. LocalDB is available on Windows only. To use SQLite instead, follow the steps below:

1. Add the `Microsoft.Data.Sqlite` package to the *ElectronExample.MiddleTier* project:

```shell
dotnet add CS/ElectronExample.MiddleTier package Microsoft.Data.Sqlite
```

2. Override the connection string with an environment variable when you start the Middle Tier server:

```shell
cd CS/ElectronExample.MiddleTier
ConnectionStrings__ConnectionString="XpoProvider=SQLite;Data Source=ElectronExample.db" \
dotnet run --launch-profile ElectronExample.MiddleTier
```

The server creates the database and the demo users on the first run.

The Middle Tier server also listens on HTTPS and requires a trusted development certificate. If the certificate is missing, run `dotnet dev-certs https --trust`.

### Start the Electron Application

In a separate terminal, run the following commands:

```shell
cd CS/ElectronExample.Blazor.Server
dotnet run --launch-profile Electron
```

To log in, use the **Admin** or **User** user name with an empty password.

## See Also
- [ElectronNET.Core on GitHub](https://github.com/ElectronNET/Electron.NET)
- [Electron Documentation](https://www.electronjs.org/docs/latest)
Expand Down
Loading