2017-10-06 05:04:56 +02:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
|
using System;
|
2020-05-01 17:29:56 +10:00
|
|
|
|
using System.IO;
|
2020-05-24 02:51:34 +02:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2017-10-06 05:04:56 +02:00
|
|
|
|
|
|
|
|
|
|
namespace ElectronNET.API
|
|
|
|
|
|
{
|
2017-10-24 21:43:27 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
2017-10-06 05:04:56 +02:00
|
|
|
|
public static class WebHostBuilderExtensions
|
|
|
|
|
|
{
|
2017-10-24 21:43:27 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Use a Electron support for this .NET Core Project.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="builder">The builder.</param>
|
|
|
|
|
|
/// <param name="args">The arguments.</param>
|
|
|
|
|
|
/// <returns></returns>
|
2017-10-06 05:04:56 +02:00
|
|
|
|
public static IWebHostBuilder UseElectron(this IWebHostBuilder builder, string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (string argument in args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (argument.ToUpper().Contains("ELECTRONPORT"))
|
|
|
|
|
|
{
|
|
|
|
|
|
BridgeSettings.SocketPort = argument.ToUpper().Replace("/ELECTRONPORT=", "");
|
|
|
|
|
|
Console.WriteLine("Use Electron Port: " + BridgeSettings.SocketPort);
|
2020-05-01 17:29:56 +10:00
|
|
|
|
}
|
|
|
|
|
|
else if (argument.ToUpper().Contains("ELECTRONWEBPORT"))
|
2017-10-06 05:46:01 +02:00
|
|
|
|
{
|
|
|
|
|
|
BridgeSettings.WebPort = argument.ToUpper().Replace("/ELECTRONWEBPORT=", "");
|
2017-10-06 05:04:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-01 17:29:56 +10:00
|
|
|
|
if (HybridSupport.IsElectronActive)
|
2017-10-06 05:04:56 +02:00
|
|
|
|
{
|
2020-05-24 02:51:34 +02:00
|
|
|
|
builder.ConfigureServices(services =>
|
|
|
|
|
|
{
|
|
|
|
|
|
services.AddHostedService<LifetimeServiceHost>();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2020-05-01 17:29:56 +10:00
|
|
|
|
// 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)
|
|
|
|
|
|
.UseUrls("http://localhost:" + BridgeSettings.WebPort);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
builder.UseUrls("http://localhost:" + BridgeSettings.WebPort);
|
|
|
|
|
|
}
|
2017-10-06 05:04:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-05-24 02:51:34 +02:00
|
|
|
|
}
|