mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-13 12:18:08 +00:00
implement auto port support for socket bridge communication
This commit is contained in:
32
ElectronNET.API/WebHostBuilderExtensions.cs
Normal file
32
ElectronNET.API/WebHostBuilderExtensions.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
public static class WebHostBuilderExtensions
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if(IsElectronActive())
|
||||
{
|
||||
builder.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory);
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static bool IsElectronActive()
|
||||
{
|
||||
return !string.IsNullOrEmpty(BridgeSettings.SocketPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user