Files
Electron.NET/ElectronNET.WebApp/Program.cs

52 lines
1.8 KiB
C#
Raw Normal View History

using ElectronNET.API;
using Microsoft.AspNetCore;
2017-10-02 20:40:28 +02:00
using Microsoft.AspNetCore.Hosting;
2019-10-03 22:30:58 +02:00
using Microsoft.Extensions.Logging;
using System;
2021-07-12 19:50:39 +02:00
using System.Diagnostics;
using System.IO;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
2017-10-02 20:40:28 +02:00
namespace ElectronNET.WebApp
{
public class Program
{
public static async Task Main(string[] args)
2017-10-02 20:40:28 +02:00
{
IWebHostBuilder builder;
#if DEBUG
var webPort = Electron.Experimental.FreeTcpPort();
await Electron.Experimental.StartElectronForDevelopment(webPort);
builder = CreateWebHostBuilder(args);
// check for the content folder if its exists in base director otherwise no need to include
// It was used before because we are publishing the project which copies everything to bin folder and contentroot wwwroot was folder there.
// now we have implemented the live reload if app is run using /watch then we need to use the default project path.
if (Directory.Exists($"{AppDomain.CurrentDomain.BaseDirectory}\\wwwroot"))
{
builder.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory);
}
builder.UseUrls("http://localhost:" + webPort);
#else
builder = CreateWebHostBuilder(args);
Debugger.Launch();
Electron.ReadAuth();
builder.UseElectron(args);
#endif
await builder.Build().RunAsync();
2017-10-03 04:17:14 +02:00
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
2017-10-06 00:37:14 +02:00
{
2017-10-06 05:06:11 +02:00
return WebHost.CreateDefaultBuilder(args)
2019-10-03 22:30:58 +02:00
.ConfigureLogging((hostingContext, logging) => { logging.AddConsole(); })
.UseStartup<Startup>();
2017-10-06 00:37:14 +02:00
}
2017-10-02 20:40:28 +02:00
}
}