mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-12 19:57:33 +00:00
Update electron start
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
StartupManager.Initialize();
|
||||
}
|
||||
|
||||
public static string ElectronExtraArguments { get; set; }
|
||||
|
||||
public static int? ElectronSocketPort { get; internal set; }
|
||||
|
||||
public static int? AspNetWebPort { get; internal set; }
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
{
|
||||
var isUnPacked = ElectronNetRuntime.StartupMethod.IsUnpackaged();
|
||||
var electronBinaryName = ElectronNetRuntime.ElectronExecutable;
|
||||
var args = Environment.CommandLine;
|
||||
var args = string.Format("{0} {1}", ElectronNetRuntime.ElectronExtraArguments, Environment.CommandLine).Trim();
|
||||
this.port = ElectronNetRuntime.ElectronSocketPort;
|
||||
|
||||
if (!this.port.HasValue)
|
||||
@@ -49,10 +49,15 @@
|
||||
ElectronNetRuntime.ElectronSocketPort = this.port;
|
||||
}
|
||||
|
||||
Console.Error.WriteLine("[StartCore]: isUnPacked: {0}", isUnPacked);
|
||||
Console.Error.WriteLine("[StartCore]: electronBinaryName: {0}", electronBinaryName);
|
||||
Console.Error.WriteLine("[StartCore]: args: {0}", args);
|
||||
|
||||
this.electronProcess = new ElectronProcessActive(isUnPacked, electronBinaryName, args, this.port.Value);
|
||||
this.electronProcess.Ready += this.ElectronProcess_Ready;
|
||||
this.electronProcess.Stopped += this.ElectronProcess_Stopped;
|
||||
|
||||
Console.Error.WriteLine("[StartCore]: Before Start");
|
||||
return this.electronProcess.Start();
|
||||
}
|
||||
|
||||
@@ -82,11 +87,11 @@
|
||||
|
||||
private void HandleStopped()
|
||||
{
|
||||
if (this.socketBridge.State != LifetimeState.Stopped)
|
||||
if (this.socketBridge != null && this.socketBridge.State != LifetimeState.Stopped)
|
||||
{
|
||||
this.socketBridge.Stop();
|
||||
}
|
||||
else if (this.electronProcess.State != LifetimeState.Stopped)
|
||||
else if (this.electronProcess != null && this.electronProcess.State != LifetimeState.Stopped)
|
||||
{
|
||||
this.electronProcess.Stop();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
@@ -42,6 +43,11 @@
|
||||
var electrondir = Path.Combine(dir.FullName, ".electron");
|
||||
startCmd = Path.Combine(electrondir, "node_modules", "electron", "dist", "electron");
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
startCmd = Path.Combine(electrondir, "node_modules", "electron", "dist", "Electron.app", "Contents", "MacOS", "Electron");
|
||||
}
|
||||
|
||||
args = $"main.js -unpackeddotnet --trace-warnings -electronforcedport={this.socketPort:D} " + this.extraArguments;
|
||||
workingDir = electrondir;
|
||||
}
|
||||
@@ -68,22 +74,40 @@
|
||||
|
||||
private async Task StartInternal(string startCmd, string args, string directoriy)
|
||||
{
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
|
||||
this.process = new ProcessRunner("ElectronRunner");
|
||||
this.process.ProcessExited += this.Process_Exited;
|
||||
this.process.Run(startCmd, args, directoriy);
|
||||
|
||||
await Task.Delay(500).ConfigureAwait(false);
|
||||
|
||||
if (!this.process.IsRunning)
|
||||
try
|
||||
{
|
||||
Task.Run(() => this.TransitionState(LifetimeState.Stopped));
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
|
||||
throw new Exception("Failed to launch the Electron process.");
|
||||
Console.Error.WriteLine("[StartInternal]: startCmd: {0}", startCmd);
|
||||
Console.Error.WriteLine("[StartInternal]: args: {0}", args);
|
||||
|
||||
this.process = new ProcessRunner("ElectronRunner");
|
||||
this.process.ProcessExited += this.Process_Exited;
|
||||
this.process.Run(startCmd, args, directoriy);
|
||||
|
||||
await Task.Delay(500).ConfigureAwait(false);
|
||||
|
||||
Console.Error.WriteLine("[StartInternal]: after run:");
|
||||
|
||||
if (!this.process.IsRunning)
|
||||
{
|
||||
Console.Error.WriteLine("[StartInternal]: Process is not running: " + this.process.StandardError);
|
||||
Console.Error.WriteLine("[StartInternal]: Process is not running: " + this.process.StandardOutput);
|
||||
|
||||
Task.Run(() => this.TransitionState(LifetimeState.Stopped));
|
||||
|
||||
throw new Exception("Failed to launch the Electron process.");
|
||||
}
|
||||
|
||||
this.TransitionState(LifetimeState.Ready);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine("[StartInternal]: Exception: " + this.process?.StandardError);
|
||||
Console.Error.WriteLine("[StartInternal]: Exception: " + this.process?.StandardOutput);
|
||||
Console.Error.WriteLine("[StartInternal]: Exception: " + ex);
|
||||
throw;
|
||||
}
|
||||
|
||||
this.TransitionState(LifetimeState.Ready);
|
||||
}
|
||||
|
||||
private void Process_Exited(object sender, EventArgs e)
|
||||
|
||||
@@ -132,13 +132,19 @@
|
||||
|
||||
if (electronAssembly == null)
|
||||
{
|
||||
Console.WriteLine("GatherBuildInfo: Early exit");
|
||||
return buildInfo;
|
||||
}
|
||||
|
||||
if (electronAssembly.GetName().Name == "testhost" || electronAssembly.GetName().Name == "ReSharperTestRunner")
|
||||
{
|
||||
Console.WriteLine("GatherBuildInfo: Detected testhost");
|
||||
electronAssembly = AppDomain.CurrentDomain.GetData("ElectronTestAssembly") as Assembly ?? electronAssembly;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("GatherBuildInfo: No testhost detected: " + electronAssembly.GetName().Name);
|
||||
}
|
||||
|
||||
var attributes = electronAssembly.GetCustomAttributes<AssemblyMetadataAttribute>().ToList();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user