Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Fixed startup failure with host lockfile (#1125) @DYH1319
- Fixed hanging host when Electron exists before bridge (#1124) @DYH1319
- Fixed dev mode launches passing the script file instead of the app directory (#1121) @Denny09310
- Added support for `WebContentsView` as an alternative to `BrowserWindow` (#1131)

# 0.6.0

Expand Down
17 changes: 17 additions & 0 deletions src/ElectronNET.Samples.AppIcons/Assets/app.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<!-- Icon of the .NET executable itself (Windows only, shown e.g. in Task Manager) -->
<ApplicationIcon>Assets\icons\app.ico</ApplicationIcon>
<!-- Enable Electron.NET Dev Mode to use the local projects instead of the NuGet packages -->
<ElectronNetDevMode>true</ElectronNetDevMode>
</PropertyGroup>

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

<PropertyGroup Label="ElectronNetCommon">
<Title>Electron.NET App Icons Sample</Title>
<Version>1.0.0</Version>
<Product>com.electronnet.app-icons-sample</Product>
<Description>Shows how to provide app icons for Windows, Linux and macOS</Description>
<Company>Electron.NET</Company>
<Copyright>Copyright © 2026, Electron.NET</Copyright>
<ElectronVersion>30.4.0</ElectronVersion>
<License>MIT</License>
</PropertyGroup>

<ItemGroup>
<!-- Ship the icons with the .NET app. When publishing, they end up in "bin/Assets/icons",
which is where Properties/electron-builder.json picks them up for packaging.
At runtime, Program.cs uses them for the window (Windows/Linux) and dock (macOS) icon. -->
<None Update="Assets\icons\**\*" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ElectronNET.API\ElectronNET.API.csproj" Condition="$(ElectronNetDevMode)" />
<ProjectReference Include="..\ElectronNET.AspNet\ElectronNET.AspNet.csproj" Condition="$(ElectronNetDevMode)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ElectronNET.Core" Version="0.7.0" Condition="'$(ElectronNetDevMode)' != 'true'" />
<PackageReference Include="ElectronNET.Core.AspNet" Version="0.7.0" Condition="'$(ElectronNetDevMode)' != 'true'" />
</ItemGroup>

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

</Project>
54 changes: 54 additions & 0 deletions src/ElectronNET.Samples.AppIcons/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using ElectronNET.API;
using ElectronNET.API.Entities;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddElectron();

builder.WebHost.UseElectron(args, async () =>
{
// The icons are copied next to the .NET assemblies (see the .csproj), so this works
// both during development and in the packaged app (where the .NET app lives in resources/bin).
var iconsDir = Path.Combine(AppContext.BaseDirectory, "Assets", "icons");

var options = new BrowserWindowOptions
{
Width = 800,
Height = 600,
Show = true,
Title = "App Icons Sample",
};

if (OperatingSystem.IsWindows())
{
// Window + taskbar icon. Packaged apps already get the icon from the executable,
// but during development (unpackaged) the default Electron icon would be shown.
options.Icon = Path.Combine(iconsDir, "app.ico");
options.AutoHideMenuBar = true;
}
else if (OperatingSystem.IsLinux())
{
// Window icon. Linux has no icon embedded in the executable, so this is also relevant
// for packaged apps (in addition to the icon of the desktop entry).
options.Icon = Path.Combine(iconsDir, "linux", "512x512.png");
options.AutoHideMenuBar = true;
}
else if (OperatingSystem.IsMacOS())
{
// macOS windows have no icon. In the packaged app, the dock icon comes from the .icns
// inside the app bundle - but during development (unpackaged) the Electron icon would be
// shown, so we set the dock icon explicitly (harmless for the packaged app).
Electron.Dock.SetIcon(Path.Combine(iconsDir, "linux", "512x512.png"));
}

var window = await Electron.WindowManager.CreateWindowAsync(options);

window.OnReadyToShow += () => window.Show();
});

var app = builder.Build();

app.UseDefaultFiles();
app.UseStaticFiles();

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<DeleteExistingFiles>true</DeleteExistingFiles>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<ProjectGuid>7c3e5b1a-4d2f-4e8a-9b6c-1f0a2d3e4c5b</ProjectGuid>
<SelfContained>true</SelfContained>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<DeleteExistingFiles>true</DeleteExistingFiles>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>osx-arm64</RuntimeIdentifier>
<ProjectGuid>7c3e5b1a-4d2f-4e8a-9b6c-1f0a2d3e4c5b</ProjectGuid>
<SelfContained>true</SelfContained>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<DeleteExistingFiles>true</DeleteExistingFiles>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
<ProjectGuid>7c3e5b1a-4d2f-4e8a-9b6c-1f0a2d3e4c5b</ProjectGuid>
<SelfContained>true</SelfContained>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<DeleteExistingFiles>true</DeleteExistingFiles>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ProjectGuid>7c3e5b1a-4d2f-4e8a-9b6c-1f0a2d3e4c5b</ProjectGuid>
<SelfContained>true</SelfContained>
</PropertyGroup>
</Project>
29 changes: 29 additions & 0 deletions src/ElectronNET.Samples.AppIcons/Properties/electron-builder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/refs/heads/master/packages/app-builder-lib/scheme.json",
"compression": "maximum",
"win": {
"target": [
{
"target": "portable",
"arch": "x64"
}
],
"icon": "bin/Assets/icons/app.ico"
},
"linux": {
"target": [
"AppImage",
"tar.xz"
],
"executableArgs": [ "--no-sandbox" ],
"icon": "bin/Assets/icons/linux",
"category": "Utility",
"artifactName": "${name}-${arch}-${version}.${ext}"
},
"mac": {
"target": [
"dmg"
],
"icon": "bin/Assets/icons/app.icns"
}
}
14 changes: 14 additions & 0 deletions src/ElectronNET.Samples.AppIcons/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:0",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
66 changes: 66 additions & 0 deletions src/ElectronNET.Samples.AppIcons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Electron.NET Sample: App Icons

A working sample with app icons for all three platforms: Windows, Linux and macOS.

There are two separate places where icons matter:

1. **Packaging** — the icon of the executable, installer, app bundle or desktop entry. It is set by electron-builder via `Properties/electron-builder.json`.
2. **Runtime** — the icon of the window, taskbar or dock while the app runs. It is set in `Program.cs`. This matters most during development, because the unpackaged app would otherwise show the default Electron icon. On Linux, it is also needed in the packaged app.

## Files

```
Assets/
├── app.svg source artwork (not used at runtime)
└── icons/
├── app.ico Windows: 16, 24, 32, 48, 64, 128, 256 px
├── app.icns macOS: 16 to 1024 px (incl. @2x variants)
└── linux/
├── 16x16.png Linux: one PNG per size, named <size>x<size>.png
├── ...
└── 512x512.png
```

The `.csproj` copies `Assets/icons` to the build and publish output. During publishing, the .NET app is placed in the `bin` folder of the electron-builder project, so `electron-builder.json` references the icons as `bin/Assets/icons/...`:

```json
{
"win": { "icon": "bin/Assets/icons/app.ico" },
"linux": { "icon": "bin/Assets/icons/linux" },
"mac": { "icon": "bin/Assets/icons/app.icns" }
}
```

`<ApplicationIcon>` in the `.csproj` also sets the icon of the .NET executable itself on Windows (e.g., shown in Task Manager).

## Platform notes

| Platform | Requirements |
| --- | --- |
| Windows | `.ico` with at least a 256×256 image. Include smaller sizes (16, 32, 48) so that the taskbar and Explorer don't have to scale down. |
| Linux | A folder with `<size>x<size>.png` files, or a single PNG of at least 256×256 px. The icon is only part of formats that have a desktop entry (AppImage, deb, rpm, ...) — a plain `tar.xz` archive has none, so there only the runtime window icon applies. |
| macOS | `.icns` with sizes up to 1024×1024 (512×512@2x). Windows on macOS have no icon, so at runtime only the dock icon can be set (`Electron.Dock.SetIcon`). The modern `.icon` format (Icon Composer) is supported too, see [Configuration](../../docs/Using/Configuration.md#app-icon-path). |

## Creating your own icons

Start with a square artwork of 1024×1024 px (e.g., `Assets/app.svg`) and export it into the formats above. For example:

- **ImageMagick** (`.ico` and PNGs):
```sh
magick app.svg -background none -define icon:auto-resize=256,128,64,48,32,24,16 app.ico
for s in 16 24 32 48 64 128 256 512; do magick app.svg -background none -resize ${s}x${s} linux/${s}x${s}.png; done
```
- **iconutil** on macOS (`.icns` from an `.iconset` folder):
```sh
iconutil -c icns app.iconset -o app.icns
```

## Run and package

```sh
# Run during development
dotnet run

# Create a package, e.g., for Windows (see Properties/PublishProfiles for the others)
dotnet publish /p:PublishProfile=win-x64
```
45 changes: 45 additions & 0 deletions src/ElectronNET.Samples.AppIcons/wwwroot/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>App Icons Sample</title>
<style>
:root { color-scheme: light dark; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { max-width: 720px; margin: 0 auto; padding: 1.5rem; line-height: 1.5; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid #8884; vertical-align: top; }
code { font-size: 0.9em; }
</style>
</head>
<body>
<h1>App Icons Sample</h1>
<p>
Look at the window, the taskbar / dock and - after packaging - the installer and executable:
they should all show the sample icon instead of the default Electron icon.
</p>

<table>
<thead>
<tr><th>Platform</th><th>Packaged app (electron-builder)</th><th>Runtime (Program.cs)</th></tr>
</thead>
<tbody>
<tr>
<td>Windows</td>
<td><code>Assets/icons/app.ico</code></td>
<td>Window icon <code>app.ico</code></td>
</tr>
<tr>
<td>Linux</td>
<td><code>Assets/icons/linux/*.png</code></td>
<td>Window icon <code>linux/512x512.png</code></td>
</tr>
<tr>
<td>macOS</td>
<td><code>Assets/icons/app.icns</code></td>
<td>Dock icon <code>linux/512x512.png</code></td>
</tr>
</tbody>
</table>
</body>
</html>
28 changes: 28 additions & 0 deletions src/ElectronNET.Samples.BlazorServer/Components/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<ResourcePreloader />
<link rel="stylesheet" href="@Assets["app.css"]" />
<ImportMap />
<HeadOutlet @rendermode="PageRenderMode" />
</head>

<body>
@* A desktop app has no reason to mix render modes: the whole app is interactive (except the error page). *@
<Routes @rendermode="PageRenderMode" />
<script src="@Assets["_framework/blazor.web.js"]"></script>
</body>

</html>

@code {
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;

private IComponentRenderMode? PageRenderMode =>
HttpContext.AcceptsInteractiveRouting() ? InteractiveServer : null;
}
Loading
Loading