Reputation: 33
I am starting a .NET electron app via terminal on MacOS by using .NET 7. In the process tray I can see the app itself being started, but the window is not showing. Also when trying to open the window via the system tray it indicates me "No Available Windows".
The application is rather simple as it is the "default" webapp template being created by the webapp workflow of dotnet.
Following steps have been done to create the project:
mkdir NetElectronTest
dotnet new webapp
(new default webapp project is created)Following steps have been done to setup the project to work with electron:
In terminal (project root):
dotnet add package ElectronNET.API
In VSCode (Program.cs)
using ElectronNET.API;
using ElectronNET.API.Entities;
internal class Program
{
private static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddElectron();
builder.WebHost.UseElectron(args);
if (HybridSupport.IsElectronActive)
{
CreateElectronWindow();
}
// Add services to the container.
builder.Services.AddRazorPages();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
}
private static void CreateElectronWindow() => Task.Run(async () =>
{
var window = await Electron.WindowManager.CreateWindowAsync();
window.OnClosed += () =>
{
Electron.App.Quit();
};
});
}
Following steps have been done to start the app with electron:
electronize init
dotnet build
)electronize start
The application is started and I can see it in the application tray, but the window itself is not showing.
I have tried to install different .NET runtimes (6 & 7, as below is not supported for Mac M1).
Output of dotnet --list-runtimes
:
Microsoft.AspNetCore.App 7.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.14 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Upvotes: 1
Views: 311
Reputation: 33
For anyone having the same problem: try starting the electron app with the /watch parameter
Upvotes: 1
Reputation: 22082
After adding builder.Services.AddElectron();
it works fine in my local. Not M1 machine, if you have other error, you can update question.
Change your code like below, the issue could be fixed. For more details, you need can check the link:
Creating Desktop Application using Blazor and Electron
using ElectronNET.API;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddElectron();
builder.WebHost.UseElectron(args);
// Add services to the container.
builder.Services.AddRazorPages();
if(HybridSupport.IsElectronActive){
Task.Run(async ()=>{
var window=await Electron.WindowManager.CreateWindowAsync();
window.OnClosed+=()=>{
Electron.App.Quit();
};
});
}
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
Upvotes: 0