Closed sheapa closed 1 year ago
Anyone has got any tips on how to do this?
Found an example here: https://learn.microsoft.com/en-us/aspnet/core/migration/50-to-60-samples?view=aspnetcore-7.0#customize-iwebhostbuilder
Which explains how to convert the WebHostBuilder, but not the
app.Run(async () => await Electron.WindowManager.CreateWindowAsync());
of https://github.com/ElectronNET/Electron.NET#startupcs.
Honestly, it didn't work I fiddled with it for about three days, then I just ported it to MAUI 👀. (It, is a project, which used ElectronNet)
I need this also.
@sheapa if you use this fork, you can do something like this:
Electron.ReadAuth(); //Must be first thing, to read the auth key necessary for the Electron socket comms
var webport = Electron.Experimental.FreeTcpPort();
var socketport = int.Parse(BridgeSettings.SocketPort);
foreach (var arg in args)
{
if (arg.ToUpper().Contains("ELECTRONPORT"))
{
socketport = int.Parse(arg.ToUpper().Replace("/ELECTRONPORT=", ""));
}
else if (arg.ToUpper().Contains("ELECTRONWEBPORT"))
{
webport = int.Parse(arg.ToUpper().Replace("/ELECTRONWEBPORT=", ""));
}
}
BridgeSettings.InitializePorts(socketport, webport); //As we do not use UseElectron, we must manually do this here
This will hopefully be merged back to the main repo in the future.
@sheapa if you use this fork, you can do something like this:
Electron.ReadAuth(); //Must be first thing, to read the auth key necessary for the Electron socket comms var webport = Electron.Experimental.FreeTcpPort(); var socketport = int.Parse(BridgeSettings.SocketPort); foreach (var arg in args) { if (arg.ToUpper().Contains("ELECTRONPORT")) { socketport = int.Parse(arg.ToUpper().Replace("/ELECTRONPORT=", "")); } else if (arg.ToUpper().Contains("ELECTRONWEBPORT")) { webport = int.Parse(arg.ToUpper().Replace("/ELECTRONWEBPORT=", "")); } } BridgeSettings.InitializePorts(socketport, webport); //As we do not use UseElectron, we must manually do this here
This will hopefully be merged back to the main repo in the future.
It works!! Thanks When will you merge it?
How i can configure Electron.NET?
This worked for me: https://github.com/ElectronNET/Electron.NET/issues/685#issuecomment-1252042885
Hi all,
I have this minimal example working with a .NET web application, using top-level statements and no Startup.cs. You shouldn't have to do manual handling to sync Electron, you can just use the WebHost from builder. Here's what it looks like:
using ElectronNET.API;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseElectron(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World");
if (HybridSupport.IsElectronActive)
{
Task.Run(async () =>
{
BrowserWindow window = await Electron.WindowManager.CreateWindowAsync();
window.OnReadyToShow += () => window.Show();
window.OnClosed += () => Electron.App.Quit();
});
}
app.Run();
Here's an example from a Blazor Server side app using Electron.NET:
using electron7_demo.Data;
using ElectronNET.API;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseElectron(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
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.MapBlazorHub();
app.MapFallbackToPage("/_Host");
await app.StartAsync();
await Electron.WindowManager.CreateWindowAsync();
app.WaitForShutdown();
The documentation does not explain how to configure the Program.cs file for new .NET 6 projects that don't have Startup.cs.