2017-10-06 05:04:56 +02:00
|
|
|
|
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;
|
2022-07-14 16:56:50 +02:00
|
|
|
|
using System;
|
2021-07-12 19:50:39 +02:00
|
|
|
|
using System.Diagnostics;
|
2022-07-14 16:56:50 +02:00
|
|
|
|
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
|
|
|
|
|
|
{
|
2022-07-14 16:56:50 +02:00
|
|
|
|
public static async Task Main(string[] args)
|
2017-10-02 20:40:28 +02:00
|
|
|
|
{
|
2022-07-14 16:56:50 +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);
|
2021-09-03 15:28:32 +02:00
|
|
|
|
Debugger.Launch();
|
2021-12-23 09:24:29 +01:00
|
|
|
|
Electron.ReadAuth();
|
2022-07-14 16:56:50 +02:00
|
|
|
|
builder.UseElectron(args);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
await builder.Build().RunAsync();
|
2017-10-03 04:17:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-14 18:30:41 +03: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(); })
|
2019-10-14 18:30:41 +03:00
|
|
|
|
.UseStartup<Startup>();
|
2017-10-06 00:37:14 +02:00
|
|
|
|
}
|
2017-10-02 20:40:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|